fix: audio/video sync drift in fixMP4BoxFileDuration#446
Conversation
|
Thanks for the fix. |
|
Thanks for your response!! @hughfenghen To demo a reproduction of the bug, please follow these steps.
So, as you can see, the file concatenated with webav is missing 8 frames, the video duration is shorter overall and audio duration is longer overall than the original video. My fix addresses this by normalizing sample timestamps within each input stream to start from 0 before applying concatenation offsets. The root cause was that input MP4 streams contain internal timestamp offsets that don't start at 0, which were being preserved and accumulated during concatenation, causing progressive A/V drift. The normalization eliminates these internal offsets while maintaining proper synchronization between audio and video tracks. |

Hello! This PR fixes a small issue leading to audio/video sync drift when using
fastConcatMP4to concatenate mp4s.The problem: if input MP4 streams to
fastConcatMP4contain internal timestamp offsets that don't start at 0, cumulative A/V drift occurs during concatenation, making the video not match the audio. This was affecting both audio and video, a video output fromfastConcatMP4is both the wrong duration and showing a/v drift, and also dropping frames due to the incorrectly calculated durations.This fixes it by normalizing sample timestamps within each stream to start from 0 before applying concatenation offsets, ensuring the correct duration is calculated. This also synchronizes audio timing to the video timeline to maintain correct a/v sync.
I don't have a repro case I can share right now but can provide if needed.