rsv-ben: fix fps detection for CFR reference clips#286
Open
kevinthelobster wants to merge 1 commit into
Open
Conversation
repairRsvBen() read the video frame duration only from Track::times_, but getSampleTimes() collapses a constant-rate stts into constant_duration_ and leaves times_ empty. Every Sony camera records CFR, so times_ was empty and video_duration_per_sample kept its 1000 default. fps was therefore computed as 24 instead of 23.976 (24000/1001), making the per-GOP audio chunk 96000 bytes instead of 96096. That ~96-byte/GOP error appended PCM to each GOP's last video frame (one corrupt frame per GOP -> ~0.5s judder) and truncated audio by the same amount (~4.5s short over 75 min) for NTSC-fractional footage (23.976/29.97/59.94). Fix: use constant_duration_ when times_ is empty. Also compute audio_samples_per_chunk with exact integer rounding so float truncation can't drop a sample at other rates. Verified on a 58GB Sony FX30 XAVC S .RSV: audio/video durations now match exactly and the file decodes with zero per-GOP errors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
-rsv-benrecovery of Sony recording-in-progress (.RSV) files produces, for NTSC-fractional footage (23.976 / 29.97 / 59.94 fps):This looks like an inherent limitation of recovering an unfinalized file, so it's easy to misattribute as unavoidable data loss. It is not — the frame data is intact in the
.RSV; it is mis-spliced.Root cause
repairRsvBen()derives the video frame duration only fromTrack::times_:But
Track::getSampleTimes()collapses a single-entry (constant-rate)sttsintoconstant_duration_and leavestimes_empty:Every Sony camera records CFR, so the reference clip's
times_is empty andvideo_duration_per_samplekeeps its1000default.fpsis then computed as24000 / 1000 = 24instead of the true24000 / 1001 = 23.976.That feeds the per-GOP audio chunk size:
giving
12 / 24 * 48000 = 24000samples (96000 bytes) instead of the correct12 * 48000 * 1001 / 24000 = 24024samples (96096 bytes) — off by ~96 bytes per GOP.audio_boundary = next_rtmd_start - total_audio_chunk_sizeis then ~96 bytes too late, so the last video frame of every GOP swallows ~96 bytes of PCM (corrupt frame), and the audio chunk is ~96 bytes short every GOP (cumulative drift).Empirically confirmed on a 58 GB FX30 XAVC S
.RSV: at the 96096-byte boundary the bytes before are high-entropy H.264 and after are low-amplitude 16-bit PCM; at 96000 both sides are PCM.Fix
constant_duration_whentimes_is empty (the actual fix).audio_samples_per_chunkwith exact integer rounding so float truncation cannot drop a sample at other rates.Verification
Patched build, same 58 GB FX30
.RSV+ a same-codec CFR reference:derived parameters: fps=23.976, GOP duration=0.5005s, audio chunk=96096 bytes(wasfps=24 … 96000)Duration of avc1andDuration of twosnow identical (were 4.5 s apart)