How to Use the SSIM Filter in FFmpeg
This article provides a straightforward guide on how to use the Structural Similarity Index Measure (SSIM) filter in FFmpeg to compare the quality of two videos. You will learn the basic command structure to calculate SSIM scores, how to output the results to a log file, and how to interpret the final scores to measure video compression loss.
What is SSIM?
SSIM is a metric used to measure the similarity between two digital images or videos. Unlike Peak Signal-to-Noise Ratio (PSNR), which focuses on absolute pixel error, SSIM is designed to align with human visual perception by analyzing luminance, contrast, and structure. The SSIM score ranges from 0 to 1, where 1 represents a perfect match (identical quality).
Basic SSIM Command
To compare a compressed or processed video against the original
reference video, use the filter_complex flag to pair the
two inputs.
Run the following command in your terminal:
ffmpeg -i distorted.mp4 -i reference.mp4 -filter_complex ssim -f null -Command breakdown: * -i distorted.mp4:
The first input is the modified or compressed video you want to test. *
-i reference.mp4: The second input is the original,
high-quality reference video. * -filter_complex ssim: This
tells FFmpeg to compare the two inputs using the SSIM filter. *
-f null -: This prevents FFmpeg from writing a new video
file, as you only need the text output generated in the console.
Exporting SSIM Results to a Log File
If you want to analyze the SSIM score frame-by-frame, you can export
the results to a text file using the stats_file option.
ffmpeg -i distorted.mp4 -i reference.mp4 -filter_complex "ssim=stats_file=ssim_log.txt" -f null -This command will create a file named ssim_log.txt in
your current directory containing the SSIM values for every individual
frame of the video.
How to Interpret the Output
Once the process finishes, FFmpeg will output a summary line in the terminal that looks similar to this:
[Parsed_ssim_0 @ 0x7fa8bb40c300] SSIM Y:0.985210 U:0.991120 V:0.991540 All:0.987310 (18.965012)
- Y, U, V: These represent the SSIM scores for the luminance (Y) and chrominance (U and V) channels.
- All: This is the global SSIM score across all
channels. In the example above,
0.987310indicates that the compressed video is extremely close in quality to the original reference. - The dB value (e.g., 18.96): The value in parentheses is the SSIM score converted to a logarithmic decibel scale. A higher decibel value indicates better quality.