How to compare/show the difference between 2 videos in ffmpeg?

Comparison of decoded data with MD5 hash

You can use the FFmpeg MD5 muxer to show that the decoding results in the exact same output:

  1. Get MD5 hash of the video stream from your original input:

    $ ffmpeg -loglevel error -i original.vid -map 0:v -f md5 -
  2. Convert to a lossless output:

    $ ffmpeg -i original.vid -c:v libx264 -qp 0 lossless.mkv
  3. Compare MD5 hash of the lossless video:

    $ ffmpeg -loglevel error -i lossless.mkv -map 0:v -f md5 -


  • You may not get the same hash even with a lossless encoder. Changes to various attributes can occur that can alter the MD5 hash such as the colorspace or chroma subsampling.

  • You can see that the MD5 hash can change if you output to a lossy format.

  • Other losslessly compressed video encoders supported by FFmpeg include: ffv1, ffvhuff, huffyuv, and utvideo.

  • See the framemd5 muxer to view the hash for each frame.

Visual comparison

With the blend filter

Viewing the difference of a lossy output
Viewing the difference of a lossy output.

You can use the blend filter to visually compare the difference.

Using ffplay

ffplay -f lavfi \
"movie=original.mkv[org]; \
 movie=encoded.mkv[enc]; \
  • blend is slow, and this command may not play in real time depending on your CPU and the inputs. Alternatively you could output a video with ffmpeg then watch it as shown below.

  • There are modes other than difference that may fit your needs. See the documentation.

Using ffmpeg

ffmpeg -i original.mkv -i encoded.mkv \
-filter_complex "blend=all_mode=difference" \
-c:v libx264 -crf 18 -c:a copy output.mkv
  • You may need to add ,format=yuv420p to the end of your filterchain (immediately after difference) to view the output in non-FFmpeg based players.

With the overlay filter

See Display video difference with ffmpeg’s overlay filter.

Leave a Comment