How to Sync Audio and Video with FFmpeg
Practical FFmpeg commands to fix audio drift, delay audio or video, and check the result before re-encoding. Covers common capture and recording sync problems.
Before you start
FFmpeg runs locally on your computer, so the source file stays on your machine unless you choose to upload it elsewhere. You need a copy of FFmpeg available from a command-line terminal and a media file with a visible marker where the picture and sound should line up, such as a clap, tap, or blinking light. If the recording has no clear reference point, create one by recording a short clap while the camera and microphone are both active.
Before changing anything, make a copy of the original recording. Some sync corrections can be tested without full re-encoding, but the process is easier to reverse when the source file is unchanged. If you are working with a capture source such as a webcam or separate microphone, confirm which stream carries the audio and which carries the video so the adjustment is applied to the correct stream.
Step-by-step instructions
Start with a quick preview correction before committing to a long re-encoding pass. This lets you adjust the offset without altering the original file.
Measure the offset
Play the recording and watch for the sync marker. Estimate how far the audio sits from the picture. If the sound happens after the visible action, the audio is late and needs to start earlier. If the sound happens before the picture, the audio is early and needs to be delayed.
Delay the audio
Use the adelay filter when the audio is too early. The delay value is given in milliseconds, so a half-second correction is 500. The all=1 option applies the delay to every audio channel.
ffmpeg -i input.mp4 -af "adelay=500|500" -c:v copy output.mp4
For stereo audio, separate values can be supplied for the left and right channels. If the command above does not suit your FFmpeg version or channel layout, use all=1 so the filter does not stop when it reaches an unlisted channel:
ffmpeg -i input.mp4 -af "adelay=500:all=1" -c:v copy output.mp4
Make late audio start earlier
When the audio is late, use a negative delay value. Some builds of FFmpeg also accept the expression 500S for a five-hundred-millisecond cut from the start.
ffmpeg -i input.mp4 -af "adelay=-500|500" -c:v copy output.mp4
The negative form trims audio from the beginning. If the timing problem grows during the recording rather than staying constant, the cause may be a mismatch between the audio sample rate and the video frame rate, which usually requires re-encoding or adjusting the stream timestamps instead of a single fixed delay.
Shift the video instead
In some recordings it is more practical to move the picture relative to the sound. The setpts filter can shift all video timestamps forward, keeping the audio untouched. The value must match the input frame rate. For a 30 frame per second file, a one-second delay uses setpts=PTS+1/TB.
ffmpeg -i input.mp4 -vf "setpts=PTS+1/TB" -af "asetpts=PTS+1/TB" -c:v libx264 -c:a aac output.mp4
Correct constant drift with stream options
If the whole audio track has a fixed offset, the input option can be a quicker alternative during a full output pass. The value is in seconds and accepts a decimal point.
ffmpeg -itsoffset 0.5 -i input.mp4 -i input.mp4 -map 0:v:0 -map 1:a:0 -c:v copy -c:a aac output.mp4
A negative value moves the audio earlier. If this route is used, check the mapping carefully after the command completes.
Produce a final re-encoded file
When the preview offset is correct, create the final recording. The first pass can copy the video stream to save time, but if the video must be re-encoded, choose a video codec and audio codec suitable for your recording format. A common MP4 example uses H.264 video and AAC audio, with a bitrate set only if you need to control file size.
ffmpeg -i input.mp4 -af "adelay=-300:all=1" -c:v libx264 -preset medium -crf 20 -c:a aac -b:a 128k output.mp4
Check the output
Open the output file and watch the sync marker several times. Focus on the instant the visible action happens relative to the sound. If the original recording contained background noise, compare a quiet section as well to make sure the correction did not expose a level change or clipping.
Inspect the result in the terminal with ffprobe to confirm the streams were mapped as expected. Look for one video stream and one audio stream, and verify the duration and declared frame rate and sample rate match the values from the source unless you intentionally re-encoded them.
ffprobe -v error -show_entries stream=index,codec_name,codec_type,duration,avg_frame_rate,sample_rate -of default=noprint_wrappers=1 output.mp4
A stream-copy operation may preserve the original encoding but can also retain an existing timestamp problem. If the first output is still out of sync, repeat the measurement with a finer offset, such as 50 or 100 milliseconds, and test again. Large random jumps usually point to a source stream problem rather than a constant delay.
Common problems and next steps
If the movement starts in time but drifts further apart over minutes, do not keep increasing one delay value. This pattern often comes from a recording where the input device produced audio and video at slightly different clocks. Try re-encoding the audio to a single constant sample rate, or use aresample to force the expected rate before applying any time adjustment.
ffmpeg -i input.mp4 -af "aresample=48000,adelay=-200:all=1" -c:v copy -c:a aac -ar 48000 output.mp4
If the sound is absent or attached to the wrong output device stream, check the mapping with -map and a targeted ffprobe command before changing the offset. A dropped or repeated picture during the recording usually requires cutting and realigning at the edit point rather than applying one delay to the whole file.
For future recordings, use a single capture source with the camera and microphone connected in the same hardware path when possible, or start each session with a clap marker and note the expected frame rate and sample rate. That makes the next sync correction faster and avoids guessing whether the original capture or the conversion introduced the drift.