Ensure even video dimensions and improve recording pipeline robustness #1489
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Greptile Summary
This PR improves video encoding robustness by ensuring all output dimensions are even numbers, consolidates duplicate dimension-rounding logic into a shared module, refactors audio drift correction to use frame timestamps instead of sample counts, and fixes a settings store initialization race condition.
Key Changes:
ensure_evenfunction from two duplicate locations intocrates/media-info/src/lib.rsfor reuse across H264/HEVC encoderscalculate_gpu_compatible_sizeto handle odd dimensions even when under the max limit, preventing encoding failures on hardware that requires even dimensionsAudioDriftTrackerto track frame timestamps relative to first frame instead of cumulative sample counts, improving drift correction accuracyqueries.tsto prevent settings store from overwriting persisted mode on initialization using aninitializedflag andbatch()for atomic updatesConfidence Score: 5/5
Important Files Changed
ensure_evenfrom media-info, enhanced GPU compatibility with comprehensive testsSequence Diagram
sequenceDiagram participant App as Desktop App participant Settings as Settings Store participant IR as InstantRecording participant RL as ResolutionLimits participant H264 as H264Encoder participant HEVC as HEVCEncoder participant Pipeline as OutputPipeline participant Audio as AudioDriftTracker Note over App,Settings: Settings Store Initialization Fix App->>Settings: Initialize (load from store) Settings-->>App: mode data Note over App: Set initialized=true AFTER loading App->>Settings: createEffect watches state changes Note over App: Only persist if initialized=true Settings-->>App: Prevents overwrite on init Note over IR,HEVC: Video Dimension Handling IR->>IR: create_pipeline(screen_info) alt max_output_size defined IR->>IR: clamp_size() else fallback path IR->>RL: ensure_even(width) IR->>RL: ensure_even(height) RL-->>IR: (even_width, even_height) end IR->>H264: build encoder H264->>RL: ensure_even(raw_width) H264->>RL: ensure_even(raw_height) RL-->>H264: (even_width, even_height) Note over H264: Log warning if adjusted H264-->>IR: Encoder ready IR->>HEVC: build encoder HEVC->>RL: ensure_even(raw_width) HEVC->>RL: ensure_even(raw_height) RL-->>HEVC: (even_width, even_height) Note over HEVC: Log warning if adjusted HEVC-->>IR: Encoder ready Note over Pipeline,Audio: Audio Drift Correction Pipeline->>Audio: new() Note over Audio: first_frame_timestamp_secs = None loop Each audio frame Pipeline->>Audio: calculate_timestamp(frame_ts, wall_clock) alt First frame Audio->>Audio: Store first_frame_timestamp_secs end Audio->>Audio: frame_elapsed = frame_ts - first_ts alt Before warmup (< 2s) Audio-->>Pipeline: Duration(frame_elapsed) else After warmup (>= 2s) alt First warmup call Audio->>Audio: baseline = frame_elapsed - wall_clock end Audio->>Audio: adjusted = frame_elapsed - baseline Audio->>Audio: drift_ratio = wall_clock / adjusted Audio->>Audio: corrected = adjusted * drift_ratio Audio-->>Pipeline: Duration(corrected) end Pipeline->>Pipeline: send_audio_frame(timestamp) end