FFmpeg Decimate Filter Custom Frame Match Guide
This article explains how to use the decimate filter in
FFmpeg to remove duplicate frames using custom frame match options. You
will learn the core parameters of the decimate filter, how to configure
block matching and difference thresholds, and see practical command-line
examples to optimize your video frame rate reduction.
The decimate filter in FFmpeg is primarily used to drop
duplicate frames from a video stream, a process common in inverse
telecine (IVTC) workflows or when compressing screen recordings. By
default, the filter looks at a cycle of 5 frames and drops the
longest-running duplicate. However, you can customize this behavior
using specific matching parameters to handle complex video sources.
Core Parameters for Custom Matching
To fine-tune how FFmpeg identifies duplicate frames, you can adjust the following key options:
cycle: Sets the frame bin size. FFmpeg looks at this specific number of consecutive frames to decide which ones to drop. The default is5.drop_count: The number of frames to drop from eachcycle. The default is1. For example, settingcycle=10:drop_count=2will drop 2 frames out of every 10.hiandlo: These parameters control the pixel difference thresholds for block matching.hisetting determines the threshold for a block to be considered “different” (default is768).losetting determines the threshold for a block to be considered “similar” (default is320).
frac: The fraction of blocks that must change to consider a frame different from its predecessor. The default is0.15. If the percentage of changed blocks is below this fraction, the frame is marked as a duplicate.
Practical Command Examples
1. Basic Decimation with Custom Cycle
If you have a video where 2 frames are duplicated in every 10-frame sequence, you can set a custom cycle:
ffmpeg -i input.mp4 -vf "decimate=cycle=10:drop_count=2" output.mp42. Strict Duplicate Matching for High-Quality Video
If your video has subtle noise that prevents FFmpeg from detecting
duplicates, you can lower the sensitivity by adjusting the
hi, lo, and frac values. This
forces the filter to tolerate minor differences:
ffmpeg -i input.mp4 -vf "decimate=hi=1024:lo=512:frac=0.10" output.mp4In this command: * hi=1024 and lo=512
increase the pixel difference thresholds, meaning small variations (like
compression artifacts or noise) are ignored. * frac=0.10
means only 10% of the image blocks need to change for FFmpeg to classify
the frame as a new, unique frame.
3. Loose Matching for Static Content
For slideshows, presentations, or software tutorials where frames remain static for long periods, you can make the matching much looser to ensure heavy duplication is aggressively removed:
ffmpeg -i input.mp4 -vf "decimate=cycle=25:drop_count=20:frac=0.05" output.mp4This configuration analyzes larger cycles of 25 frames, dropping up to 20 duplicates per cycle, while requiring only a 5% block change to declare a frame unique.