Remove Duplicate Frames in FFmpeg with Decimate

This article explains how to use the decimate filter in FFmpeg to identify and remove duplicate frames from video files. You will learn the basic command syntax, how the filter operates on a specific frame-cycle basis, and how to adjust parameters like threshold and cycle size to optimize your video's frame rate and file size.

How the Decimate Filter Works

The decimate filter is designed to drop frames that are nearly identical to their adjacent frames. It operates on a fixed cycle of frames. By default, it looks at blocks of 5 frames and drops the one that is most similar to its predecessor, effectively converting 30 fps video (often telecined) down to 24 fps.

Basic Syntax

To apply the default decimate filter, use the -vf (video filter) flag followed by decimate:

ffmpeg -i input.mp4 -vf decimate output.mp4

This default command uses a cycle of 5 frames (cycle=5) and drops 1 frame per cycle, resulting in a 20% reduction in the total frame count.

Adjusting Filter Parameters

You can fine-tune the filter using specific parameters to match your video's unique characteristics:

  • cycle: The frame interval from which one frame will be dropped. The default is 5. If you want to drop 1 frame out of every 10, set this to 10.
  • dupthresh: The threshold for duplicate detection. This is a percentage of difference. If the difference between two frames is below this threshold, they are considered duplicates. The default is 1.1.
  • scthresh: The scene change threshold. This prevents the filter from dropping frames during sudden scene transitions. The default is 15.0.

Example: Customizing Cycle and Threshold

If you have a video where duplicates occur less frequently, you can increase the cycle size and adjust the sensitivity:

ffmpeg -i input.mp4 -vf "decimate=cycle=10:dupthresh=2.0" output.mp4

In this command, FFmpeg examines groups of 10 frames, detects duplicates with a slightly higher tolerance (2.0), and drops the single most redundant frame from each group.

Decimate vs. Mpdecimate

It is important to choose the right tool for your specific video:

  • decimate: Best for video with a constant, predictable pattern of duplicates (e.g., 3:2 pulldown removal where exactly 1 in 5 frames is a duplicate). It maintains a constant frame rate (CFR).
  • mpdecimate: Best for removing all consecutive duplicate frames, regardless of where they occur (e.g., screencasts or static presentations). This results in a variable frame rate (VFR) video.

If your video has irregular duplicates, use mpdecimate instead:

ffmpeg -i input.mp4 -vf mpdecimate -vsync vfr output.mp4