I am a newbie at encoding. I have read and tried x264 in lossless mode (-qp 0), however I'd like to make sure that in my new video, every single pixel contains the same information as the source file (which is in YUV 420 so the loss of color conversion is avoidable, as far as I know). I want to be able to check that, because I don't believe in that if someone just says its lossless.
I welcome answers suggesting other codecs for lossless encoding, my only requirements for codecs are having one of the best compression rate and let me to pick different calculation times (such as the range from placebo to veryfast in x264) in order to adjust the compression level and calc time to my needs. But keep in mind that the original question is about how can I calculate the differences frame by frame of two videos and export it to a 3rd file, so I can watch it myself. I think that knowledge (if its possible and doesnt have serious limitations) will be useful for me in the future too.
Reduce the images to something low-res like 16x16 or 64x64, using a nearest neighbor approach. This will blur the image such that two similar images will reduce to the same. Gather a chunk of these images by relative video timestamp and hash them to further reduce the data. Compare said hashes.
You can use the FFmpeg MD5 muxer to show that the decoding results in the exact same output:
Get MD5 hash of the video stream from your original input:
$ ffmpeg -loglevel error -i original.vid -map 0:v -f md5 - MD5=5ee3ae1ee5feaf30618938290225f682
Convert to a lossless output:
$ ffmpeg -i original.vid -c:v libx264 -qp 0 lossless.mkv
Compare MD5 hash of the lossless video:
$ ffmpeg -loglevel error -i lossless.mkv -map 0:v -f md5 - MD5=5ee3ae1ee5feaf30618938290225f682
Notes:
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.
Viewing the difference of a lossy output.
You can use the blend filter to visually compare the difference.
ffplay
ffplay -f lavfi \ "movie=original.mkv[org]; \ movie=encoded.mkv[enc]; \ [org][enc]blend=all_mode=difference"
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.
ffmpeg
ffmpeg -i original.mkv -i encoded.mkv \ -filter_complex "blend=all_mode=difference" \ -c:v libx264 -crf 18 -c:a copy output.mkv
,format=yuv420p
to the end of your filterchain (immediately after difference
) to view the output in non-FFmpeg based players.See Display video difference with ffmpeg’s overlay filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With