How to Use FFmpeg setpts for Fast Motion Video
This article provides a quick and practical guide on how to use the
FFmpeg setpts filter to create a fast-motion effect in your
videos. You will learn the exact command-line syntax required to speed
up video streams, understand how the presentation timestamp (PTS) math
works, and discover how to properly adjust and sync the accompanying
audio track so it matches the accelerated video.
To create a fast-motion effect in FFmpeg, you must modify the
Presentation Timestamp (PTS) of each video frame using the
setpts video filter. Speeding up a video requires dragging
the frames closer together in time, which is achieved by multiplying the
PTS by a fraction less than 1.0.
The Basic Command for Video Only
To double the speed of a video stream (and discard the audio), use the following command:
ffmpeg -i input.mp4 -vf "setpts=0.5*PTS" -an output.mp4In this command: * -vf "setpts=0.5*PTS" multiplies the
timestamp of each frame by 0.5, making the video play at 2x
speed. * -an disables the audio stream to prevent sync
issues, as changing video speed does not automatically speed up the
audio.
To achieve other common speed increases, adjust the multiplier
accordingly: * 2x Speed: setpts=0.5*PTS *
4x Speed: setpts=0.25*PTS * 10x
Speed: setpts=0.1*PTS
Speeding Up Both Video and Audio
If you want to keep the audio and have it speed up alongside the
video, you must use the atempo audio filter in combination
with setpts. Because you are modifying both streams, you
should use the -filter_complex flag.
To speed up both video and audio to 2x speed, use this 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.mp4Handling Speeds Greater Than 2x
The FFmpeg atempo filter only supports speed adjustments
between 0.5 and 2.0. If you want to speed up
your video by a larger factor, such as 4x, you must chain multiple
atempo filters together.
For a 4x fast-motion effect with synchronized audio, use this command:
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.mp4By chaining atempo=2.0,atempo=2.0, the audio is
multiplied by 2 and then multiplied by 2 again, resulting in the
required 4x speed increase to match the 0.25*PTS video
adjustment.