Never join shots with their sound copied
ffmpeg -f concat … -c copy (the concat demuxer) places each segment by its container length. A segment's audio is often a few ms longer than its picture, and some segments carry timestamp gaps. The picture slips later and later against the sound: in one cut it was +0.2 s by the end, read as "the lips are behind the audio" on shots that were perfect alone.
Join like this
- Picture: concat filter, every segment's frames re-timed back to back:
[k:v]setpts=N/30/TB[pk]; … [p0][p1]…concat=n=N:v=1:a=0[v], re-encoded,-r 30. - Picture lengths from frame counts, not the container's duration field (it under-reports by a frame or more):
ffprobe -count_frames -show_entries stream=nb_read_frames. - Sound: each segment's audio padded or cut to exactly its picture length in samples (
apad,atrim=end_sample=frames*1600at 48 kHz/30 fps),asetpts=N/SR/TB, concatenated into one continuous track, then muxed under the joined picture. - Write a timeline (segment → start time from frame counts) beside the cut; every later check and fix uses it.
Finish the sound
- Clean the dialogue in one pass over the whole cut, then mix back the segments with no dialogue at their own room sound (cleaning wipes room tone and leaves dead air). Crossfade 50 ms at the switches.
- Add sound effects at timeline positions. Check them by level and say what you measured; you can't hear them.
- Loudness:
loudnorm=I=-16:TP=-1.5:LRA=11. - Last step before delivery, always:
ffmpeg -i mix.mp4 -map 0:v -map 0:a:0 -c:v copy -af aresample=async=1:first_pts=0 -c:a aac -b:a 192k -movflags +faststart final.mp4.
Check before delivering
- Sound and picture lengths equal within a frame (
ffprobestream durations, and summed packet durations). - Every cut lands on its planned frame: decode with ffmpeg, not OpenCV (OpenCV seeking is off by frames).
- A full transcript (whisper large) against the script; explain every difference.
Late changes: "change only this"
When the person asks for one change to a delivered file and no other changes, don't rebuild or re-clean the sound, which would shift everything slightly. Splice the delivered file:
- picture: frames
[0, at)+ new segment + frames[at, end)with the concat filter andsetpts=N/30/TB; - sound: the delivered track with exactly the new segment's length of silence (or its sound) inserted at
at × 1600samples. Put the splice where the delivered sound is silent. - Verify: frame count grew by exactly the inserted frames, and the sound after the splice matches the old file shifted by the inserted length (cross-correlation 1.00, 0 ms).
- Move the superseded file out of the delivery folder; never delete it.


