Match Audio Speed to Fast Motion Video with FFmpeg
When creating fast-motion video effects in FFmpeg, speeding up the
video stream without adjusting the audio results in desynchronization.
To keep the audio track perfectly aligned with the accelerated video,
you must use the asetpts (audio set presentation timestamp)
filter in combination with audio tempo or sample rate adjustments. This
article provides a straightforward guide on how to use
asetpts to match your audio to fast-motion video, covering
both pitch-preserved and pitch-altered methods.
Understanding the Math
To speed up a video, you reduce its presentation timestamps (PTS)
using the setpts filter. For example, to make a video play
at double speed (2x), you multiply the PTS by
0.5:
setpts=0.5*PTS
To match this fast-motion effect, the audio stream must be modified
to fit the exact same timeline. This requires adjusting the audio speed
and using asetpts=0.5*PTS to scale the audio presentation
timestamps.
Here are the two ways to apply this filter depending on how you want the audio to sound.
Method 1: Speeding Up Audio with Pitch Preservation (Normal Voice)
If you want the audio to play faster to match the video but want to
keep the voice pitch sounding natural (avoiding the “chipmunk” effect),
combine the atempo filter with asetpts.
Use the following command to speed up both video and audio by 2x:
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0,asetpts=0.5*PTS[a]" -map "[v]" -map "[a]" output.mp4How it works: * setpts=0.5*PTS speeds
up the video by 2x. * atempo=2.0 speeds up the audio data
by 2x without changing the pitch. * asetpts=0.5*PTS
rescales the audio timestamps to ensure they match the accelerated video
timeline perfectly.
Method 2: Speeding Up Audio with Pitch Change (Chipmunk Effect)
If you want the classic “high-pitched fast-forward” sound to
accompany your fast-motion video, you should use the
asetrate filter alongside asetpts.
For a 2x speed increase, you must double the input sample rate (e.g., from 44,100 Hz to 88,200 Hz) and then reset the timestamps:
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]asetrate=44100*2,asetpts=0.5*PTS[a]" -map "[v]" -map "[a]" output.mp4How it works: * asetrate=44100*2
changes the sample rate configuration, which increases the playback
speed and raises the pitch. Note: Replace 44100 with
your input file’s actual sample rate if different (e.g.,
48000). * asetpts=0.5*PTS rebuilds the
audio timestamps so that the player renders the high-sample-rate audio
at the accelerated speed, syncing it with the video.
Formula Cheat Sheet for Different Speeds
To apply different fast-motion speeds, use this guide to calculate your filter values:
| Target Speed | Video Filter (setpts) |
Audio Filter (asetpts) |
Audio Tempo (atempo) |
|---|---|---|---|
| 1.5x Speed | 0.67*PTS |
0.67*PTS |
1.5 |
| 2x Speed | 0.5*PTS |
0.5*PTS |
2.0 |
| 3x Speed | 0.33*PTS |
0.33*PTS |
3.0 |
| 4x Speed | 0.25*PTS |
0.25*PTS |
4.0 |
Note: The atempo filter in FFmpeg only supports
values between 0.5 and 100.0.