Skip to content

How to Fix FFmpeg Audio Sync Issues

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about How to Fix FFmpeg Audio Sync Issues. We cover key concepts, practical examples, and best practices.

The Problem

After running FFmpeg, the audio is out of sync with the video — the sound comes before or after the picture. This can start immediately or drift progressively over time. Audio desync makes the video unwatchable.

Quick Fix

Fix 1: Check Source for Sync Issues

ffmpeg -i input.mp4 -f null -
# Look for "non-monotonous DTS" or "pts has no value" warnings

WRONG — assuming the source is synchronized:

# (the source may have variable frame rate or timestamp issues)

RIGHT — use -fflags +genpts to regenerate timestamps:

ffmpeg -fflags +genpts -i input.mp4 -c copy output.mp4
# (regenerates PTS values from the stream data)

Fix 2: Variable Frame Rate to Constant

ffprobe -v error -select_streams v -show_entries stream=r_frame_rate input.mp4
# r_frame_rate=30000/1001  (29.97 fps)
# But the actual frame rate may vary

RIGHT — use -vsync cfr for constant frame rate:

ffmpeg -i input.mp4 -vsync cfr -c:v libx264 -c:a aac output.mp4

Fix 3: Delay Audio with -itsoffset

If the audio is consistently ahead or behind by a known amount:

# Audio is 2 seconds ahead — delay audio by 2 seconds:
ffmpeg -i input.mp4 -itsoffset 2.0 -i input.mp4 \
    -map 0:v -map 1:a -c copy output.mp4

Or use the adelay audio filter:

# Delay audio by 2000ms:
ffmpeg -i input.mp4 -c:v copy -af "adelay=2000" output.mp4

Fix 4: Resync with the aresample Filter

ffmpeg -i input.mp4 -c:v copy -af "aresample=48000:async=1" output.mp4
# (resamples audio to 48kHz and adjusts sync)

async=1 stretches or compresses audio to maintain sync.

Fix 5: Copy Without Re-Encoding (Common Fix)

WRONG — re-encoding introduces sync issues:

ffmpeg -i input.mp4 -c:v libx264 -c:a aac output.mp4
# (re-encoding may change durations if GOP size mismatches)

RIGHT — try stream copy first:

ffmpeg -i input.mp4 -c copy output.mp4
# (preserves original timestamps exactly)

Fix 6: Extract and Remux

# Extract video and audio separately, then remux:
ffmpeg -i input.mp4 -c:v copy -an video_only.ts
ffmpeg -i input.mp4 -c:a copy -vn audio_only.aac

# Remux with corrected timestamps:
ffmpeg -i video_only.ts -i audio_only.aac -c copy output.mp4

Fix 7: Check for Drop Frames

ffmpeg -i input.mp4 -v debug 2>&1 | grep "duplicate frame|drop frame"
# (if frames are dropped, the sync will drift)

Use -muxdelay 0 and -muxpreload 0 to minimize sync issues:

ffmpeg -i input.mp4 -c:v libx264 -c:a aac -muxdelay 0 -muxpreload 0 output.mp4

Use DodaTech's Media Sync Analyzer to detect audio drift, measure offset amounts, and generate correction commands automatically.

Prevention

  • Always test a short segment before processing the full video.
  • Use -c copy when you do not need to re-encode.
  • Fix source issues with -fflags +genpts first.
  • Use constant frame rate (-vsync cfr) for streaming.
  • Check sync at multiple points (beginning, middle, end).

Common Mistakes with audio sync

  1. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  2. Misunderstanding that String is [Char] with poor performance for large text operations
  3. Using foldl instead of foldl' causing stack overflow on large lists

These mistakes appear frequently in real-world FFMPEG code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does audio drift further out of sync over time?

Variable frame rate (VFR) sources cause progressive desync. Fix with -vsync cfr. Also check if the audio sample rate differs from the original — mismatched sample rates cause cumulative drift.

How do I measure the exact audio offset?

Play the video in a player that shows frame-by-frame timing. Note the offset at a specific point. Alternatively, use a waveform editor to align a known audio spike with the corresponding video frame.

Can I fix sync without re-encoding?

Yes, use -itsoffset to shift audio timestamps without re-encoding: ffmpeg -i input.mp4 -itsoffset -0.5 -i input.mp4 -map 0:v -map 1:a -c copy output.mp4. This shifts audio by 0.5 seconds earlier.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro