Repository navigation
Keep picture and sound together when a render seeks a range join - #435
Merged
Merged
Conversation
A clip rendered from a video's ranges could come out with its picture and sound of different lengths: picture 1.5-2.7 s longer than the sound on a straight clip, or shorter and ahead of the speech on a clip with trimmed pauses. The joined source stores one set of H.264 parameters, the first part's, which is the black filler's Baseline set when a range does not start the video. YouTube's open GOPs make some keyframes recovery points that carry no parameter sets of their own. The render's input seek started the decoder on such a keyframe, decoded it with the filler's parameters, and got garbage until the next IDR a few seconds later. The video began late, `-t` counted from the first good frame so it ran past the clip's end, and in a cut clip every piece after the first lost that time, so the picture ran ahead of the sound. - Every part of a join now carries its own SPS/PPS on each keyframe (h264_mp4toannexb + dump_extra), so any sync frame decodes on its own. - seekVideoArgs (media.ts) seeks 10 s early and moves the clock back with -itsoffset: the decoder meets an IDR first, while ffmpeg's accurate seek still starts the output at the time asked for. The render and the face, speaker and text samplers use it, so joins made before this change render and scan correctly too. Tests build a join with a Baseline filler before an open-GOP High profile piece and check the picture after a seek onto a recovery point, for a new join and with seekVideoArgs on a join made the old way. Signed-off-by: dillonstreator <dillonstreator@gmail.com>
…ther The av-sync suite joins a range the way a ranged project does (buildSparseSource, black filler before it), reads the clip with the render's seek (seekVideoArgs) and cuts it with the render's own graph, now the exported jumpCutGraph (a refactor, no change to the graph). Each case checks that the video and audio streams end within 0.1 s, and that every piece between jump cuts is in step with its sound: a 1 s probe from its middle is found in the source by picture and by sound, and the two offsets must agree within 0.1 s. Cases: a synthetic open-GOP range after a Baseline filler (offline) and four clips whose renders had picture and sound 1.5-2.7 s apart, two with pause trims and two without, by link and range (downloaded into the eval cache). Before the fix all five fail: the synthetic case does not decode, and the reported clips come out 20.20/22.37, 22.07/24.73, 53.80/52.24 and 26.37/24.52 s with pictures up to 2.16 s off their sound. After it all five pass: worst length gap 0.061 s, worst picture-to-sound offset 0.090 s. Signed-off-by: dillonstreator <dillonstreator@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Merged
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
Clips rendered from a video's ranges could come out with video and audio streams of different lengths. On a clip without cuts the picture ran 1.5–2.7 s past the sound. On a clip with pause trims the picture came out shorter than the sound and ran ahead of the speech.
Cause
Pause trimming was not the cause. A ranged project's
source.mp4is a stream-copy join, and itsavcCholds only the first part's H.264 parameters. When a range does not start the video, the first part is the black filler, so the stored parameters are Constrained Baseline. YouTube's High-profile encodes use open GOPs: about one keyframe in three is a recovery point with no SPS/PPS of its own.The render's input
-ssstarts decoding at the nearest sync frame. When that frame is a recovery point, the decoder uses the filler's parameters and gets garbage until the next IDR, up to ~8 s later. Three things follow:-tcounts from the first good frame, so a straight clip's video ends late.The face, speaker and text samplers seek the same way and time their frames by count, so they were offset too.
Repro on such a source:
ffmpeg -ss 4937.85 -t 24.52 -i source.mp4 …gives video 26.37 s and audio 24.52 s, with a burst of h264 decode errors.Fix
pipeline/sparse.ts): each part (piece, re-encoded piece, filler) is remuxed withh264_mp4toannexb,dump_extra=freq=keyframebefore concat. Every keyframe then carries its own parameters, and any sync frame decodes on its own.media.tsseekVideoArgs): seek 10 s early, then use-itsoffsetto move the clock back. The decoder meets an IDR first, while ffmpeg's accurate seek still starts the output at the requested time and-tstill counts from it.jumpCutGraphis extracted from the render's cut branch unchanged, so the eval runs the render's own graph.Tests and evals
Unit tests (
test/sparse-source.test.ts): an open-GOP High-profile piece joined after a Baseline filler.seekVideoArgs, it must also decode correctly in a join made the old way, and the picture and sound of a cut must match in length.New
av-synceval suite: builds the join, the seek and the jump-cut graph through production code. Per case:Cases:
The "before" run used this branch with
sparse.tsandseekVideoArgsreverted tomain's behaviour.About the residual offsets: 0.023 s is the AAC encoder's priming delay in the probe, not drift. The 0.090 s readings are single pieces with a 2-frame picture lead that doesn't build up across cuts. This is below what a viewer notices and outside this fix.
Verification on a running instance
Checks:
tsc,pnpm lint,pnpm guardspass.Existing clips with the old mismatch need a re-render; the source files themselves don't need to be re-downloaded.