How to Adjust Video and Audio Speed in FFmpeg

This article provides a straightforward guide on how to adjust video playback speed in FFmpeg by simultaneously modifying the presentation timestamps (PTS) for video and the tempo for audio. You will learn the exact filter commands required to speed up or slow down your media files while keeping the audio and video tracks perfectly synchronized.

To change the speed of a video file in FFmpeg, you must modify both the video stream and the audio stream. If you only modify one, the streams will become desynchronized. Video speed is controlled by the setpts filter, which changes the presentation timestamps of the video frames. Audio speed is controlled by the atempo filter.

The Math Behind Speed Adjustment


Command to Speed Up Video and Audio (2x Speed)

To double the speed of your video and audio, use the -filter_complex option to apply both filters simultaneously:

ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=0.5*PTS[v];[0:a]atempo=2.0[a]" -map "[v]" -map "[a]" output.mp4

How it works: * [0:v]setpts=0.5*PTS[v] takes the video stream of the first input (0:v), halves the timestamps to double the playback speed, and labels the output stream as [v]. * [0:a]atempo=2.0[a] takes the audio stream of the first input (0:a), doubles the tempo, and labels the output stream as [a]. * -map "[v]" -map "[a]" maps these processed streams to the final output file.


Command to Slow Down Video and Audio (0.5x Speed)

To slow down your video and audio to half-speed, use the following command:

ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=2.0*PTS[v];[0:a]atempo=0.5[a]" -map "[v]" -map "[a]" output.mp4

How it works: * setpts=2.0*PTS doubles the display duration of each video frame, resulting in half-speed video. * atempo=0.5 slows down the audio to half-speed.


Handling Extreme Speed Changes

The atempo filter in older versions of FFmpeg only supports values between 0.5 and 2.0. If you need to go faster or slower than these limits, you must chain multiple atempo filters together.

For example, to speed up your video to 4x speed:

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.mp4

In this command, 0.25*PTS handles the 4x video speed, while the chained atempo=2.0,atempo=2.0 multiplies the audio speed twice (\(2.0 \times 2.0 = 4.0\)) to match.