Measure Visual Information Fidelity with FFmpeg

Visual Information Fidelity (VIF) is a full-reference image and video quality metric that measures how much information is lost during distortion, such as compression or transmission. This article provides a step-by-step guide on how to use FFmpeg to calculate VIF scores. It covers the required prerequisites, the exact command-line syntax, and how to export and interpret the resulting quality scores.

Prerequisites

To measure VIF, you must use FFmpeg's libvmaf filter. VIF is implemented as a feature within Netflix's VMAF (Video Multi-Method Assessment Fusion) library.

Before starting, ensure that your version of FFmpeg is compiled with VMAF support. You can verify this by running the following command in your terminal:

ffmpeg -filters | grep libvmaf

If libvmaf appears in the output, your FFmpeg installation is ready.

The Command Syntax

To calculate VIF, you need two video files: the distorted (compressed) video and the reference (original) video. Both videos must have the same resolution and frame rate.

Use the following command to run the VIF assessment:

ffmpeg -i distorted.mp4 -i reference.mp4 -filter_complex "[0:v][1:v]libvmaf=feature='name=vif':log_path=vif_results.json:log_fmt=json" -f null -

Command Breakdown

  • -i distorted.mp4: Specifies the distorted/compressed video as the first input (0:v).
  • -i reference.mp4: Specifies the original reference video as the second input (1:v).
  • -filter_complex "[0:v][1:v]libvmaf=...": Maps both video streams into the libvmaf filter.
  • feature='name=vif': Instructs the VMAF library to specifically calculate and output VIF metrics.
  • log_path=vif_results.json: Saves the frame-by-frame and pooled VIF metrics to a JSON file named vif_results.json.
  • log_fmt=json: Sets the output format of the log to JSON for easy parsing.
  • -f null -: Prevents FFmpeg from writing a new video file, as we only need the text-based log output.

Understanding the VIF Output

Once the command finishes running, open the generated vif_results.json file. The file will contain VIF scores calculated at different scales, typically labeled as:

  • vif_scale0
  • vif_scale1
  • vif_scale2
  • vif_scale3

These scales represent the visual fidelity at different spatial resolutions (multi-scale analysis).

A VIF score generally ranges from 0 to 1, where:

  • 1.0 indicates that the distorted video is identical to the reference video.
  • 0.0 indicates complete loss of visual information.
  • In some cases where artificial sharpening or contrast enhancement has been applied, a VIF score may exceed 1.0.