FFmpeg Drop Frames to Match High Speed setpts
When you speed up a video in FFmpeg using the setpts
filter, the software compresses the presentation timestamps, which crams
more frames into a shorter duration and dramatically increases the
effective frame rate. To prevent playback stutter, massive file sizes,
and processing overhead, you must drop the excess frames to maintain
your original target frame rate. This article explains how to pair the
setpts filter with the fps filter in a single
command to discard unwanted frames and create a smooth, high-speed
time-lapse effect.
The Problem with setpts Alone
When you apply a filter like -vf "setpts=0.25*PTS", you
speed up the visual action by 4x. However, FFmpeg does not automatically
delete frames. If your source video is 30 frames per second (fps),
speeding it up 4x without dropping frames forces FFmpeg to pack 120
frames into every second of output. Most media players and hardware
decoders cannot handle this sudden spike in frame rate, resulting in
choppy playback.
The Solution: Chaining setpts and fps
To solve this, you must chain the fps filter
after the setpts filter. This tells FFmpeg to
first speed up the video timestamps, and then resample the resulting
high-frame-rate stream back down to your desired target frame rate by
dropping the duplicate or excess frames.
Here is the standard command template:
ffmpeg -i input.mp4 -vf "setpts=0.25*PTS,fps=30" output.mp4How the Command Works
-i input.mp4: Defines your input video file.-vf: Initiates the video filtergraph.setpts=0.25*PTS: Multiplies the presentation timestamps by 0.25, speeding up the video to 4x its original speed. (For 2x speed, use0.5*PTS; for 10x speed, use0.1*PTS).,(Comma): Chains the filters together in sequence. The output of thesetptsfilter is sent directly into thefpsfilter.fps=30: Forces the final output to be exactly 30 frames per second. Because the previous filter compressed the timeline, thefpsfilter drops the excess frames to maintain this constant 30 fps limit.output.mp4: The exported high-speed video file.
Why Filter Order Matters
You must place the setpts filter before the
fps filter.
If you place the fps filter first (e.g.,
fps=30,setpts=0.25*PTS), FFmpeg will first discard frames
from the normal-speed video to match 30 fps, and then speed up the
remaining frames. This results in an incredibly choppy, low-frame-rate
output (effectively 7.5 fps). By running setpts first, you
ensure the motion remains smooth before dropping the excess frames down
to your target playback rate.