If you need a stable identifier for a media file that survives renames and metadata edits, do not hash the file bytes. The header and tags can change without the perceptual content changing. Hash the decoded stream instead, so two encodes of the same source give the same value.

The command

ffmpeg -i input.mp4 -f md5 -

What it does

The md5 muxer hashes the raw decoded packets in stream order, not the container. The hash is written to stderr when the muxer closes. Two files that came from the same encode will produce the same hash; two re-encodes with different settings will not. For bit-exact identity, use the framemd5 muxer which emits one hash per packet.

Requirements

Any container FFmpeg can open. The muxer is built into FFmpeg core, so no extra library is needed. The hash is computed during the encode step, so the command does the same work as a normal conversion — it just discards the output.

Things to avoid

  • Hashing the file on disk with `md5sum input.mp4`. That hash changes the moment you re-mux or strip a tag.
  • Comparing framemd5 output between two files of different duration; the second hash will not match even if the first N frames are identical.
  • Using `-f md5 -` on a file that contains multiple video streams. The muxer concatenates the streams in order, so the result depends on stream order, not on visual content.
  • Forgetting that the hash is written to stderr and the encoded output is written to stdout. Redirect stderr to capture the hash.