Verify Unchanged Video with FFmpeg Identity Filter
This article explains how to verify that a video remains completely
unchanged during processing or transfer using FFmpeg. We will explore
how to use FFmpeg’s conceptual identity filter—the null
video filter (-vf null)—combined with the
framemd5 muxer to generate cryptographic hashes of video
frames. By comparing these hashes before and after a transfer or
processing pipeline, you can mathematically prove that your video pixel
data is 100% identical and unchanged.
Understanding the Identity Filter in FFmpeg
In mathematics and signal processing, an “identity” function or
filter is one that returns its input exactly as it was received, without
any modifications. In FFmpeg, this role is performed by the
null video filter.
When you pass a video through -vf null, FFmpeg decodes
the video frames and passes them through the filtergraph completely
unaltered. By combining this identity filter with a hash-generating
muxer, you can create a unique fingerprint of the video’s raw pixel
data.
Step-by-Step Verification Process
To verify that a video is unchanged, you must generate a frame-by-frame hash of the original video and compare it against a hash of the destination or processed video.
Step 1: Generate Hashes for the Original Video
Run the following command on your source video to decode the frames through the identity filter and output their MD5 hashes:
ffmpeg -i original.mp4 -vf null -f framemd5 original_frames.md5Command Breakdown: * -i original.mp4:
Defines the input video file. * -vf null: Invokes the
identity filter, ensuring the decoded video frames are passed through
unchanged. * -f framemd5: Specifies the format muxer that
calculates an MD5 hash for the pixel data of every single decoded frame.
* original_frames.md5: The output text file containing the
list of frame hashes.
Step 2: Generate Hashes for the Target Video
Run the identical command on the video you want to verify (e.g., after copying, uploading, or processing):
ffmpeg -i target.mp4 -vf null -f framemd5 target_frames.md5Step 3: Compare the Hash Files
To confirm the videos are identical, compare the two generated
.md5 text files. You can use standard command-line tools to
do this.
On Linux or macOS:
diff original_frames.md5 target_frames.md5On Windows (PowerShell):
Compare-Object (Get-Content original_frames.md5) (Get-Content target_frames.md5)If the command returns no output (or indicates no differences), the pixel content of the two videos is absolutely identical, confirming that the video is completely unchanged.
Bitstream Identity Verification (Faster Method)
If you only want to verify that the compressed video packets (the bitstream) are unchanged without decoding the actual pixels, you can bypass the decoder entirely and run a stream-copy identity check.
Use the following command to generate an MD5 hash of the raw stream packets:
ffmpeg -i input.mp4 -c:v copy -f md5 stream_hash.md5Because this method avoids decoding the video frames, it runs
significantly faster than the frame-by-frame pixel verification method.
However, it requires the container format and packet structures to be
completely identical. For verifying visual losslessness across different
containers (e.g., MP4 to MKV), the decoded framemd5 method
with the null filter is preferred.