How to Use the FFmpeg PSNR Filter
This article provides a quick guide on how to use the Peak Signal-to-Noise Ratio (PSNR) filter in FFmpeg to measure video quality. You will learn the basic command-line syntax required to compare a compressed or processed video against its original reference, how to log the results to a text file, and how to interpret the final decibel (dB) scores output by the tool.
Basic command syntax
The psnr filter in FFmpeg requires two video inputs: the
modified (distorted) video and the original (reference) video. Because
it compares two distinct video streams, you must use FFmpeg’s
-filter_complex option to map both inputs into the
filter.
Here is the standard command to calculate the PSNR:
ffmpeg -i distorted.mp4 -i original.mp4 -filter_complex "[0:v][1:v]psnr" -f null -Command breakdown:
-i distorted.mp4: The first input (0:v), which is the compressed or processed video you want to evaluate.-i original.mp4: The second input (1:v), which serves as the high-quality reference video.-filter_complex "[0:v][1:v]psnr": Takes the video streams from both inputs and passes them into thepsnrfilter.-f null -: Instructs FFmpeg to process the video and calculate the metrics without exporting a new video file.
Saving PSNR results to a log file
If you need to analyze the quality of the video frame-by-frame, you
can export the PSNR statistics to a log file using the
stats_file parameter.
ffmpeg -i distorted.mp4 -i original.mp4 -filter_complex "[0:v][1:v]psnr=stats_file=psnr_results.log" -f null -This command generates a file named psnr_results.log in
your working directory, containing the frame number, loss metric, and
individual PSNR values for the Y, U, and V color channels of every
single frame.
Understanding the output
Once the process finishes, FFmpeg will display a summary line in the terminal that looks similar to this:
[Parsed_psnr_0 @ 0x55bfca609bc0] PSNR y:38.45 u:42.15 v:41.80 average:39.12 min:32.40 max:inf
To interpret these results: * y, u, v: Represents
the PSNR values for the luminance (Y) and chrominance (U, V) channels.
The Y (luminance) channel is the most critical for human visual
perception. * average: The overall average PSNR value
across the entire video. * min / max: The lowest and
highest PSNR values recorded. A value of
inf (infinite) means the compared frames
are identical.
Evaluating the scores
PSNR is measured on a logarithmic decibel (dB) scale: * Above 40 dB: Excellent quality; the compressed video is virtually indistinguishable from the original. * 30 dB to 40 dB: Good quality; distortions are minimal and generally hard to notice. * Below 30 dB: Poor quality; visible compression artifacts, pixelation, or blurriness are present.