How to Calculate VMAF Score Using FFmpeg

This article provides a quick and practical guide on how to use the libvmaf filter in FFmpeg to calculate the Visual Multi-Method Assessment Fusion (VMAF) score. You will learn the system prerequisites, the exact command-line syntax required to compare a distorted video against a reference video, how to export the results to a log file, and how to interpret the final score.

Prerequisites

To calculate VMAF scores, you need: 1. FFmpeg compiled with VMAF support (the --enable-libvmaf flag must be enabled). You can check this by running ffmpeg -filters | grep vmaf. 2. VMAF Model Files (typically .json format), which are trained models representing different viewing conditions (e.g., 1080p phone/TV screens). You can download these models from the official Netflix VMAF GitHub repository.

Basic FFmpeg Command

To calculate the VMAF score, you must pass both the distorted (processed) video and the original reference video into FFmpeg. The distorted video is typically passed as the first input (-i), and the reference video as the second.

Run the following basic command in your terminal:

ffmpeg -i distorted.mp4 -i reference.mp4 -filter_complex "[0:v][1:v]libvmaf=model=path=vmaf_v0.6.1.json" -f null -

Exporting Scores to a Log File

To save frame-by-frame scores and the final mean score to a file for analysis, use the log_path and log_fmt options. You can export the log as XML, JSON, CSV, or sub (text format).

ffmpeg -i distorted.mp4 -i reference.mp4 -filter_complex "[0:v][1:v]libvmaf=model=path=vmaf_v0.6.1.json:log_path=vmaf_output.json:log_fmt=json" -f null -

Dealing with Different Resolutions or Framerates

VMAF requires both input videos to have the exact same resolution and framerate. If your distorted video has a different resolution than your reference video, you must scale one of them within the filtergraph.

To upscale a distorted 720p video to match a 1080p reference video:

ffmpeg -i distorted_720p.mp4 -i reference_1080p.mp4 -filter_complex "[0:v]scale=1920:1080[distorted_scaled]; [distorted_scaled][1:v]libvmaf=model=path=vmaf_v0.6.1.json" -f null -

Understanding the VMAF Score

Once the process finishes, FFmpeg will print the VMAF score in the terminal output.