How to Use vmaf_cuda in FFmpeg

This article explains how to use the vmaf_cuda filter in FFmpeg to perform hardware-accelerated video quality evaluation using Nvidia GPUs. You will learn the prerequisites, the basic command syntax, and how to configure the filter to utilize your graphics card for faster VMAF score calculations.

Prerequisites

Before using the vmaf_cuda filter, ensure your system meets the following requirements:

Basic Command Syntax

The vmaf_cuda filter requires both the reference video and the distorted video to be loaded into CUDA memory. To achieve the best performance, you should decode both videos on the GPU using hardware acceleration.

Here is the standard command template for running vmaf_cuda:

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i distorted.mp4 \
-hwaccel cuda -hwaccel_output_format cuda -i reference.mp4 \
-filter_complex "[0:v]scale_cuda=format=yuv420p[dist]; [1:v]scale_cuda=format=yuv420p[ref]; [dist][ref]vmaf_cuda=model=vmaf_v0.6.1.json" \
-f null -

Command Breakdown

Saving VMAF Scores to a File

To analyze the frame-by-frame or summary results later, you can instruct the filter to write the scores to an external log file (such as XML, JSON, or CSV).

Use the following command to output the results to a JSON file:

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i distorted.mp4 \
-hwaccel cuda -hwaccel_output_format cuda -i reference.mp4 \
-filter_complex "[0:v]scale_cuda=format=yuv420p[dist]; [1:v]scale_cuda=format=yuv420p[ref]; [dist][ref]vmaf_cuda=model=vmaf_v0.6.1.json:log_path=vmaf_results.json:log_fmt=json" \
-f null -

Key Parameters for Logging

Scaling and Resolution Matching

VMAF requires the distorted and reference videos to have the exact same resolution. If your distorted video has been downscaled, you must scale it back to the reference resolution using scale_cuda before passing it to the vmaf_cuda filter:

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i distorted_720p.mp4 \
-hwaccel cuda -hwaccel_output_format cuda -i reference_1080p.mp4 \
-filter_complex "[0:v]scale_cuda=1920:1080:format=yuv420p[dist]; [1:v]scale_cuda=format=yuv420p[ref]; [dist][ref]vmaf_cuda=model=vmaf_v0.6.1.json" \
-f null -

By keeping the entire pipeline (decoding, scaling, and VMAF calculation) on the GPU, you avoid CPU bottlenecks and PCI-Express bandwidth limitations, resulting in much faster quality assessment.