Using ffmpeg + MPDecimate to get rid of exact duplicate frames (i.e. losslessly)
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)?
11 Answer
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.mkvShould 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.mkvthen 21 frames are kept.
You might need to adjust the parameters according to your definition of exact duplicate.
1