Keeping A/V Sync Tight When Concatenating Multi-Episode Vertical MP4 Clips with FFmpeg
Stitching two AI-generated vertical episodes with -f concat -c copy looks clean on a quick timeline check until playback crosses the splice boundary and dialogue arrives ~100 ms ahead of the mouth. We hit this exact offs
Stitching two AI-generated vertical episodes with -f concat -c copy looks clean on a quick timeline check until playback crosses the splice boundary and dialogue arrives ~100 ms ahead of the mouth. We hit this exact offset while assembling Part 1 (18.04s) and Part 2 (27.08s) of a multi-shot 2000s MiniDV-style vertical series in AlphaDrama (I work on the AlphaDrama engineering team, and the stream numbers below come from our real export pipeline).
Why container-copy concat drifts between clips
H.264 video frames at 24 fps step in 41.67 ms ticks, whereas 48000 Hz AAC audio uses 1024-sample (21.33 ms) frames. Even when each episode appears valid on its own, individual clips routinely end slightly earlier on the audio elementary stream than on the video stream.
When we inspected both source episodes before building our 45-second combined cut, ffprobe reported:
| Clip | Video Stream Duration | Audio Stream Duration | Per-Clip Delta | Pixel / Aspect |
|---|---|---|---|---|
| Part 1 MP4 |
18.041667s (24 fps) |
18.008000s (48000 Hz AAC) |
-33.67 ms |
480x854 (240:427) |
| Part 2 MP4 |
27.083333s (24 fps) |
27.000000s (48000 Hz AAC) |
-83.33 ms |
480x854 (240:427) |
Using the FFmpeg concat demuxer (-f concat -safe 0 -i list.txt -c copy) appends packets linearly without aligning the shorter audio track to Part 1's video duration boundary. Crossing into Part 2 compounds the audio advance immediately at Shot 1.
The fix: re-align both streams inside filter_complex concat
To reset the timeline cleanly at the clip boundary while simultaneously normalising 480x854 (DAR 240:427) drafts up to clean 1080x1920 (DAR 9:16, SAR 1:1) vertical delivery for Shorts, Reels, and X, run both streams through the concat filter rather than -c copy:
ffprobe -v error -show_entries stream=codec_type,duration,r_frame_rate,width,height -of json part1.mp4
ffprobe -v error -show_entries stream=codec_type,duration,r_frame_rate,width,height -of json part2.mp4
ffmpeg -y -i part1.mp4 -i part2.mp4 \
-filter_complex "[0:v]scale=1080:1920:flags=lanczos:force_original_aspect_ratio=increase,crop=1080:1920,setsar=1[v0]; \
[1:v]scale=1080:1920:flags=lanczos:force_original_aspect_ratio=increase,crop=1080:1920,setsar=1[v1]; \
[v0][0:a][v1][1:a]concat=n=2:v=1:a=1[v][a]" \
-map "[v]" -map "[a]" \
-c:v libx264 -preset medium -crf 18 -pix_fmt yuv420p \
-c:a aac -b:a 192k -movflags +faststart \
combined-1080x1920.mp4
What changes in the output
-
Stream padding at the segment boundary: Because
concat=n=2:v=1:a=1pads shorter streams within each segment to match the longer segment boundary before starting Segment 2, Part 2's dialogue stays locked to its first frame (45.125000stotal runtime verified viaffprobe). -
Exact 9:16 sample & display geometry:
scale=...:force_original_aspect_ratio=increase,crop=1080:1920,setsar=1removes the240:427rounding quirk from480x854proxies without adding pillarboxes or stretched pixels. -
Instant first-frame seek (
+faststart): Moving themoovatom to the file header ensures mobile web players start buffering audio and video together immediately.
Where this breaks down
Re-encoding through filter_complex takes roughly 3.5xβ4x real-time on CPU for 1080x1920 H.264, so it belongs in your final assembly step rather than intermediate shot previews. And if both episodes already had completely desynced audio before concatenation, concat preserves the per-clip sync rather than fixing damaged source clips.
If you're assembling multi-episode vertical stories from generated character sheets and shot keyframes, our workflow lives at AlphaDrama Script-to-Video.
Cover graphic generated with an AI image model to illustrate stream duration offsets.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.