11

According to the documentation, mpdecimate will "Drop frames that do not differ greatly from the previous frame in order to reduce frame rate."

I would like to be able to remove only exact duplicate frames from a video. I know the video has a ton of them that are similar, but I only want to get rid of exact duplicates.

Any advice on how to use ffmpeg with mpdecimate to do this (or some other tool)?

2 Answers2

9

Values for hi and lo are for 8x8 pixel blocks and represent actual pixel value differences, so a threshold of 64 corresponds to 1 unit of difference for each pixel, or the same spread out differently over the block.

A frame is a candidate for dropping if no 8x8 blocks differ by more than a threshold of hi, and if no more than frac blocks (1 meaning the whole image) differ by more than a threshold of lo.

Default value for hi is 64 * 12, default value for lo is 64 * 5, and default value for frac is 0.33.

ffmpeg -i input.mkv -vf mpdecimate=hi=1:lo=1:frac=1:max=0 output.mkv

Should only drop an image if the whole image has no more than 1 pixel value difference to the previous.

My test with a static image rendered into a 5sec h264 video show that in reality 3 frames out of 125 get dropped. This is possibly due to compression artifacts.

When adjusting the high and low value to 200

ffmpeg -i input.mkv -vf mpdecimate=hi=200:lo=200:frac=1:max=0 output.mkv

then 21 frames are kept.

You might need to adjust the parameters according to your definition of exact duplicate.

mashuptwice
  • 3,395
2

If you want to actually shorten the video by fully removing the frames rather than just not storing the frames while keeping the video the same length, then use:

ffmpeg -i  input.mkv \
       -vf mpdecimate=hi=200:lo=200:frac=1:max=0,setpts=N/FRAME_RATE/TB \
           output.mkv
bertieb
  • 7,543
Damo
  • 131