Speed Up FFmpeg VMAF with Multi-Threading

This article explains how to significantly accelerate video quality assessment by running the VMAF (Video Multi-Method Assessment Fusion) filter in FFmpeg using multi-threading. You will learn the exact command-line parameters required to leverage multiple CPU cores, optimize resource usage, and drastically reduce the time it takes to compute VMAF scores.

Understanding VMAF Bottlenecks

Calculating VMAF scores is a highly CPU-intensive process because it analyzes spatial and temporal features across every single frame of a reference and distorted video. By default, FFmpeg’s libvmaf filter may only run on a single thread or fail to utilize your CPU’s full capacity, leading to slow analysis times. To overcome this, you must explicitly enable multi-threading using the n_threads option within the filter parameters.

The Multi-Threaded FFmpeg Command

To run VMAF with multi-threading, pass the n_threads option inside the -filter_complex flag.

Here is the standard syntax:

ffmpeg -i distorted.mp4 -i reference.mp4 -filter_complex "[0:v][1:v]libvmaf=n_threads=4" -f null -

Parameter Breakdown:

Determining the Optimal Thread Count

Assigning too many threads can lead to diminishing returns due to thread synchronization overhead, while too few will underutilize your system.

Advanced Speed Optimization: Subsampling

If multi-threading alone is not fast enough, you can combine it with frame subsampling. The n_subsample parameter tells FFmpeg to only calculate VMAF for every \(N\text{-th}\) frame.

ffmpeg -i distorted.mp4 -i reference.mp4 -filter_complex "[0:v][1:v]libvmaf=n_threads=8:n_subsample=5" -f null -

In this example, the filter uses 8 threads and processes every 5th frame (n_subsample=5). This speed optimization maintains a high correlation with the actual VMAF score of the entire video while cutting processing time by up to 80%.