FFmpeg Speed Up Video and Keep Audio Synced
Changing the speed of a video file using FFmpeg requires adjusting both the video frames and the audio track simultaneously to prevent synchronization issues. This article provides the exact commands and filter configurations needed to accelerate your video while keeping the audio perfectly in sync, whether you are doubling the speed or applying a custom speed multiplier.
The Basic Command for 2x Speed
To speed up a video, FFmpeg uses the setpts video filter
to manipulate presentation timestamps and the atempo audio
filter to adjust the audio speed.
To double the speed (2x) of a video and keep the audio synced, use the following command:
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" output.mp4How It Works:
-filter_complex: This flag allows you to apply multiple filters to the video and audio streams at the same time.[0:v]setpts=0.5*PTS[v]: This scales the video presentation timestamps (PTS) by0.5. Reducing the timestamps by half makes the frames display twice as fast.[0:a]atempo=2.0[a]: This speeds up the audio to2.0times its original speed without changing the pitch.-map "[v]" -map "[a]": This tells FFmpeg to combine the processed video stream[v]and audio stream[a]into the final output file.
Customizing the Speed Multiplier
If you want to speed up your video by a factor other than 2, you must calculate the correct values for both the video and audio filters.
The formula for the video filter is
1 / Speed Multiplier. The formula for the audio filter is
simply the Speed Multiplier itself.
Example: 1.5x Speed
- Video PTS modifier:
1 / 1.5 = 0.67 - Audio tempo:
1.5
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.67*PTS[v];[0:a]atempo=1.5[a]" -map "[v]" -map "[a]" output.mp4Speeding Up Beyond 2x Speed
The atempo audio filter in FFmpeg has a limitation: it
only accepts values between 0.5 and 2.0. If
you want to speed up your video by more than double, you must chain
multiple atempo filters together.
Example: 4x Speed
- Video PTS modifier:
1 / 4 = 0.25 - Audio tempo:
2.0 * 2.0 = 4.0
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.25*PTS[v];[0:a]atempo=2.0,atempo=2.0[a]" -map "[v]" -map "[a]" output.mp4Example: 8x Speed
- Video PTS modifier:
1 / 8 = 0.125 - Audio tempo:
2.0 * 2.0 * 2.0 = 8.0
ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.125*PTS[v];[0:a]atempo=2.0,atempo=2.0,atempo=2.0[a]" -map "[v]" -map "[a]" output.mp4Optimizing the Process (Without Re-encoding Audio)
If you do not care about keeping the audio track and want a faster render process, you can discard the audio entirely. This allows FFmpeg to process the video much quicker since it does not have to recalculate audio waveforms:
ffmpeg -i input.mp4 -an -filter:v "setpts=0.5*PTS" output.mp4(The -an flag disables audio entirely).