How to Delay Audio in FFmpeg Using itsoffset
Audio and video synchronization issues frequently occur during
recording, editing, or transcoding. Using FFmpeg, you can fix this
misalignment by delaying the audio stream relative to the video stream
using the -itsoffset option. This guide explains how
-itsoffset works and provides the exact command syntax
needed to adjust stream timing without re-encoding your media.
Understanding
-itsoffset
The -itsoffset parameter adjusts the input timestamps of
the media file that immediately follows it in the command line. Because
timestamps are modified at the input stage, you generally import the
same media file twice: once for the real-time stream and once for the
delayed stream.
Applying -itsoffset directly before the second input
delays that stream relative to the first input. Using stream copying
(-c copy) allows this adjustment to happen instantaneously
without quality loss.
The Basic Command
To delay the audio stream by a specific number of seconds relative to the video, use the following command template:
ffmpeg -i input.mp4 -itsoffset 1.5 -i input.mp4 -map 0:v -map 1:a -c copy output.mp4Command Breakdown
-i input.mp4: The first input. This provides the video stream starting at normal time (0:v).-itsoffset 1.5: The time offset applied to the subsequent input. In this case, it shifts the timestamps forward by 1.5 seconds. You can use standard decimal seconds (e.g.,0.75) or standard time format (hh:mm:ss.ms).-i input.mp4: The second input. Because-itsoffsetprecedes this flag, all streams from this input will be shifted forward by 1.5 seconds.-map 0:v: Maps the video stream from the first input (un-delayed).-map 1:a: Maps the audio stream from the second input (delayed by 1.5 seconds).-c copy: Copies both streams directly into the new container without decoding or re-encoding, preserving original quality and finishing within seconds.output.mp4: The name of the resulting synchronized file.
Advanced Usage and Considerations
- Sub-second Adjustments: For minor desync issues,
specify fractions of a second (e.g.,
-itsoffset 0.2for a 200-millisecond delay). - Multiple Audio Tracks: If your file has multiple
audio tracks and you want to keep all of them delayed, map them
individually (
-map 1:a:0,-map 1:a:1) or map all audio tracks from the second input using-map 1:a. - Subtitle Synchronization: If your file contains
embedded subtitles that must stay synchronized with either stream,
explicitly map the subtitle stream (e.g.,
-map 0:sfor video-aligned or-map 1:sfor audio-aligned).