HowTo generate single hashcode for A/V content

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
Posts: 373
Joined: Tue Nov 12, 2013 2:05 am

HowTo generate single hashcode for A/V content

Post by peter_b »

UPDATE: This functionality is actually covered by FFmpeg's built-in "-f hash" muxer, and maybe even better its 'streamhash' muxer.

This script does the following all in a single FFmpeg command execution:
  1. Rewrap container
  2. Generate hashcode of raw uncompressed video content
  3. Generate hashcode of raw uncompressed audio content
Same as what "frameMD5" or "frameCRC" are used for: Verify that transcoding/rewrapping was lossless.

Why not frameMD5 then?
It's easier to automate a comparison of a single hashcode per content type than diff-handling in automation.

Code: Select all

# @author: Peter B. (
# @description:
#   Rewraps container of source video, while generating 2 .md5 files with a
#   single MD5 hashcode for the raw audio/video.


# mkfifo $FIFO_A $FIFO_V


CMD_FF="$FFMPEG -y -i $VIDEO_IN -map 0:1 -vn -f s16le audio -map 0:0 -an -f rawvideo video -c copy -map 0 $VIDEO_OUT"

# Audio hash:
CMD_HA="cat $FIFO_A | md5sum > $FIFO_A.md5"
# Video hash:
CMD_HV="cat $FIFO_V | md5sum > $FIFO_V.md5"

echo "$CMD_HA"
echo "$CMD_HV"
echo "$CMD_FF"

eval "$CMD_HA & $CMD_HV & $CMD_FF"

echo ""
echo "Audio MD5"; cat "$FIFO_A.md5"
echo "Video MD5"; cat "$FIFO_V.md5"

Thanks Keenan J. Troll for having the idea to do a "contentMD5"!
Post Reply