Calculate PSNR Between Two Videos with FFmpeg

This article provides a straightforward guide on how to calculate the Peak Signal-to-Noise Ratio (PSNR) between two videos using FFmpeg on Linux. You will find the exact command-line syntax, an explanation of its parameters, and how to interpret the resulting log data to evaluate video quality loss.

To calculate the PSNR between a reference video and a distorted (compressed) video, use the FFmpeg psnr filter via the -filter_complex flag. This ensures both videos are properly synchronized and compared frame by frame.

The FFmpeg PSNR Command

Run the following command in your Linux terminal:

ffmpeg -i distorted_video.mp4 -i reference_video.mp4 -filter_complex "psnr" -f null -

How the Command Works

Saving the Results to a Log File

If you want to analyze the frame-by-frame metrics or save the summary for later, you can instruct FFmpeg to output a log file by modifying the filter parameters:

ffmpeg -i distorted_video.mp4 -i reference_video.mp4 -filter_complex "psnr=stats_file=psnr_report.log" -f null -

Understanding the Output

After the command finishes processing, FFmpeg will print a summary line in the terminal that looks similar to this:

[Parsed_psnr_0 @ 0x5555557a30] PSNR y:42.15 u:48.32 v:48.71 average:43.24 min:38.12 max:inf

Key Considerations

For the calculation to be accurate, both videos must have the exact same frame rate, duration, and resolution. If your distorted video has a different resolution due to downscaling, you must scale it back to match the reference video dimensions within the filter chain before applying the PSNR filter.