Delay Video Relative to Audio Using FFmpeg

Audio and video desynchronization is a common issue in media processing, often requiring precise timing adjustments. This article explains how to use the -itsoffset option in FFmpeg to delay a video stream relative to its audio stream, ensuring perfect synchronization. You will learn the exact command-line syntax and how the offset parameter applies to inputs to correct timing discrepancies.

To delay the video stream relative to the audio stream, you must input the source file twice in your FFmpeg command. The -itsoffset option analyzes the input that immediately follows it and delays its start time. By mapping the audio from the original, real-time input and the video from the offset input, you achieve the desired delay.

The FFmpeg Command

Use the following command structure to delay the video by a specific number of seconds (for example, 3.5 seconds):

ffmpeg -i input.mp4 -itsoffset 3.5 -i input.mp4 -map 1:v -map 0:a -c copy output.mp4

Parameter Breakdown

  • -i input.mp4: The first input file (assigned index 0). This serves as the source for the real-time, unaltered audio.
  • -itsoffset 3.5: Specifies a delay of 3.5 seconds. This option must be placed immediately before the input file you want to delay. You can use decimals for millisecond precision (e.g., 0.250 for a 250-millisecond delay).
  • -i input.mp4: The second input file (assigned index 1). Because it follows the -itsoffset option, all streams within this input are delayed by 3.5 seconds.
  • -map 1:v: Maps the video stream (v) from the second input file (index 1), which contains the delayed video.
  • -map 0:a: Maps the audio stream (a) from the first input file (index 0), which contains the non-delayed audio.
  • -c copy: Copies both the audio and video streams directly without re-encoding. This process is extremely fast and preserves the original quality of the file.

By using this method, the audio will play immediately, while the video stream will start exactly 3.5 seconds later, successfully correcting the synchronization issue.