Tool

Fix Audio/Video Sync: Measure with a Clap and Build itsoffset and adelay Commands

When the audio runs later or earlier than the lip movement, this tool measures how far off it is and builds an ffmpeg command to fix it. Pick a clap video and it calculates the difference between the clap frame in the video and the time the clap starts in the audio; if you already know the value, you can enter it directly in ms or frames. All calculation happens only inside this browser.

① Measure the offset with a clap video (optional)

Pick a video in which you clapped once in front of the camera. The tool finds the frame where the palms meet in the video and the moment the clap starts in the audio, and calculates the difference. If you already know the value, skip to ②.


② Enter the offset

Direction check preview

If you pick the wrong direction, the offset doubles. Press the buttons to check that the symptom you picked feels like what you were seeing, and that it lines up after the fix. The screen flash is tied to the browser's display refresh (usually around 16 ms), so it is not a precise measurement at the tens-of-ms level.


③ Build the command

ffmpeg command (output: input_sync.mp4)

ffmpeg -itsoffset 0.2 -i "input.mp4" -i "input.mp4" -map 0:v:0 -map 1:a:0 -c copy "input_sync.mp4"

The audio is 200 ms late, so the same file is opened as input a second time and -itsoffset 0.2 is applied to the first input (the video), which delays the video by that amount. Relatively, that is the same as pulling the audio 200 ms earlier.

-itsoffset applies only to the single -i that comes right after it. Because there are two inputs, -map 0:v:0 means the video of the first input and -map 1:a means the audio of the second. Subtitles and other audio tracks are left out of this command, so add more -map options if you need them.

In MP4, a start delay is stored as an edit list, and there are reports that some players and editors ignore it, so it has no effect. Open the result and check it yourself; if it doesn't work, use the ‘re-encode audio only’ method.

Because this method delays the video, the start of the output file may have a stretch with no video, and depending on the player the first few hundred ms may show as a black or frozen frame.

The original input is not touched; the result is saved as a new file. Open the result and check the clap scene again.

Why audio and video drift out of sync

Inside a video file, the video and the audio are compressed and stored separately, and each has its own timetable (timestamps) saying ‘play this at this many seconds.’ The player lines the two timetables up. So an offset usually appears when one timetable is shifted to one side: for example, the recording or capture device received the video and the audio with different delays, only one of them was trimmed during editing, or the playback device, like Bluetooth earbuds, outputs the sound late. The last case is a problem of the playback setup, not of the file, so first check whether the offset also shows up on other speakers or a wired connection. There is a reason to fix the file only if it is still off over a wired connection.

First, tell them apart: a constant offset, or one that keeps growing

  • The offset is about the same from start to finish → you only need to shift once. This is the tool’s default behavior.
  • In sync at first, then it keeps growing over time → it may be a drift, a slight difference between the audio and video speeds. Measure at the start and at the end of the video, turn on ‘I also measured at the end of the video,’ and the tool judges it from the difference between the two values and calculates an audio speed ratio (atempo).

How to do the clap test

  1. Record a short clip with the same device and the same settings that produce the offset. Clap your hands once in front of the camera. The moment the palms meet is clearly visible in one frame and the sound is instantaneous, which makes it a good reference.
  2. If you suspect drift, clap once more near the end of the video.
  3. Choose that file on this page, step through the video frame by frame, and press ‘Mark’ on the first frame where the palms touch. Then press ‘Find the clap in the audio’ and the time the sound starts is picked up.
  4. If audio time − video time is positive, the audio is late; if it is negative, the audio is early. ‘Use this value in ②’ moves the value over.

A loud scene other than a clap (a door slamming, a slate) works too. If several sounds are mixed in the range, narrow the analysis range to around the clap. You can also line things up by eye using a flash of light in the scene or the lip movement, but the eye can hardly tell differences of tens of ms, so the error gets larger.

The difference between the two methods

Without re-encoding: -itsoffset + -c copy

The same file is opened twice as input, only the timetable of the input that has -itsoffset is pushed back, and then the video is taken from the first input and the audio from the second. Both the video and the audio are copied as compressed data, so picture and sound quality do not change and it finishes almost instantly. This tool always builds the command with positive values only: if the audio is late it delays the video (which, as a result, is the same as pulling the audio earlier), and if the audio is early it delays the audio. This avoids negative offsets, whose sign is easy to mix up.

The downside is that results can differ depending on the container and the player. There are user reports on the FFmpeg issue tracker and forums that it had no effect in MP4 or that-itsoffset on the second input did not take, so be sure to open the file you made and check the clap scene again.

Re-encode audio only: adelay and atrim

The audio is processed directly with a filter and compressed anew. If the audio is early, adelay adds silence at the front to delay it; if the audio is late,atrim=start= cuts off the front of the audio to pull it earlier. The video stays as is with -c:v copy, so picture quality is kept, but the audio goes through lossy compression once more. Because it relies less on how the container handles timestamps, it is the alternative when the copy method does not behave. The speed correction (atempo) for an offset that keeps growing is also possible only with this method.

What the preview is for

People easily use ‘the audio is late/early’ in opposite ways. This tool’s convention is: if, for the same event, the sound comes after the picture, it is ‘late.’If you pick the wrong direction, the fix doubles the offset, so press the play-before-fix button to confirm the symptom matches what you have been seeing, then use the command.

Limitations worth knowing

  • There is no guarantee that the time the browser reads and the time ffmpeg reads are the same. If a file records different start times for video and audio, the browser may interpret them differently. The measured value is only a starting point; playing the fixed file yourself is the final check.
  • Codecs the browser cannot play (for example, some HEVC or 10-bit files) may not work for the preview or audio analysis. In that case, enter the value yourself.
  • The audio analysis looks only at the first audio channel and skips files larger than 300 MB. A short file with just the clap cut out works best. How to cut one is covered in the lossless-cut keyframe planner.
  • A value picked frame by frame carries an error of one frame (about 33 ms at 30 fps). The sound of a clap also takes time to spread, so it cannot be pinned down to exactly one point.
  • This site has not measured the results of audio/video sync fixes. The explanations of how the commands behave are based on the meaning of the options in the ffmpeg documentation and on the reports above, and we have not listed figures such as the threshold at which people notice an offset.
  • For VFR (variable frame rate) video, frame numbers and times do not map to each other at a constant rate. Use ms instead of frame input, and check whether a file is VFR with the VFR detector.

Tools that go well with this one

To see which tracks are inside a file, use the video file info inspector; if a command throws an error, use the FFmpeg error log explainer. For subtitles that are out of sync, there is a separate subtitle sync fixer.