How to Calculate PSNR Using FFmpeg

This article provides a quick and practical guide on how to use the FFmpeg psnr filter to calculate the Peak Signal-to-Noise Ratio (PSNR) between two videos. You will learn the exact command-line syntax required to compare a compressed or processed video against its original reference, how to save the frame-by-frame results to a log file, and how to interpret the final output metrics.

The Basic Command Syntax

To calculate the PSNR, you must provide two input videos to FFmpeg: the processed (distorted) video and the original (reference) video. For the filter to work correctly, both videos must have the same resolution, frame rate, and pixel format.

Run the following command in your terminal:

ffmpeg -i distorted_video.mp4 -i original_video.mp4 -filter_complex psnr -f null -

Command Breakdown

Saving PSNR Results to a Log File

If you want to analyze the PSNR values on a frame-by-frame basis, you can export the data to a text file using the stats_file option:

ffmpeg -i distorted_video.mp4 -i original_video.mp4 -filter_complex "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 PSNR values for the Y, U, and V color channels of every frame.

Understanding the Output

Once the analysis is complete, FFmpeg will display a summary line in the console that looks like this:

[Parsed_psnr_0 @ 0x55ccb67a9e00] PSNR y:41.25 u:45.67 v:46.12 average:42.34 min:35.10 max:54.89

PSNR is measured in decibels (dB). Higher values indicate a higher-quality video that is closer to the original. In lossy video compression, a PSNR value between 30 dB and 50 dB is generally considered good to excellent.