Accelerating VMAF with CUDA
This post is about how to compile VMAF with CUDA support and run the filter from FFMPEG. The entire compilation process has been tested on Ubuntu 25.15, without using Docker and with a minimum of pre-built libraries.
Install compilation tools and required libraries:
sudo apt install autoconf automake build-essential yasm cmake git-core unzip libtool wget meson ninja-build pkg-config libunistring-dev libnuma-dev libc6-dev libsdl2-dev zlib1g-dev
Install CUDA 13.1:
wget https://developer.download.nvidia.com/compute/cuda/13.1.1/local_installers/cuda_13.1.1_590.48.01_linux.run
chmod +x cuda_13.1.1_590.48.01_linux.run
sudo ./cuda_13.1.1_590.48.01_linux.run --toolkit
# add path to nvcc compiler
export PATH+=':/usr/local/cuda/bin/'
Install Nvidia Video SDK headers:
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
sudo make install
Download sources and configure VMAF:
wget https://github.com/Netflix/vmaf/archive/v2.3.1.tar.gz
tar xvf v2.3.1.tar.gz
mkdir -p vmaf-2.3.1/libvmaf/build
cd vmaf-2.3.1/libvmaf/build
meson setup ../libvmaf/ -Denable_tests=false -Denable_docs=false --buildtype=release --default-library=static
ninja -vC .
sudo ninja install
Download FFMPEG sources:
git clone https://git.ffmpeg.org/ffmpeg.git
cd ffmpeg
#894da5ca7d742e4429ffb2af534fcda0103ef593 - v8.0.1
git checkout 894da5ca7d742e4429ffb2af534fcda0103ef593
Configure and compile FFMPEG:
cd ffmpeg
./configure \
--extra-libs='-lpthread -lm' \
--ld=g++ \
--enable-gpl \
--enable-gnutls \
--enable-nvenc \
--enable-cuvid \
--enable-nvdec \
--enable-cuda-nvcc \
--enable-cuda \
--enable-zlib \
--enable-libvmaf \
--enable-nonfree \
--enable-ffplay \
--enable-filter=libvmaf_cuda \
--enable-filter=scale_cuda \
--disable-filter=scale_npp \
--pkg-config-flags=--static \
--enable-static \
--disable-shared \
--extra-cflags=-fPIC \
--extra-cflags=-I/usr/local/cuda/include/ \
--extra-ldflags=-L/usr/local/cuda/lib64/ \
--extra-ldflags=-L/usr/local/lib
make -j
sudo make install
Run VMAF calculation with scaling the original to 1920×1080:
ffmpeg -y -hwaccel cuda -hwaccel_output_format cuda -r 30 -i reference.mp4 -hwaccel cuda -hwaccel_output_format cuda -r 30 -i transcoded.mp4 -filter_complex "[0:v]scale_cuda=w=1920:h=1080:format=yuv420p[ref],[1:v]scale_npp=format=yuv420p[enc];[ref][enc]libvmaf_cuda=log_path=vmaf.log" -f null /dev/null
Or run calculation with the VMAF NEG model and using uncompressed original video:
ffmpeg -y -hwaccel cuda -hwaccel_output_format cuda -r 30 -i reference.y4m -hwaccel cuda -hwaccel_output_format cuda -r 30 -i transcoded.mp4 -filter_complex "[0:v]split=2[ref1][ref2];[1:v]split=2[enc1][enc2];[ref1]hwupload_cuda[ref_hw1];[ref2]hwupload_cuda[ref_hw2];[ref_hw1]scale_cuda=w=1920:h=1080:format=yuv420p[ref_sc1];[ref_hw2]scale_cuda=w=1920:h=1080:format=yuv420p[ref_sc2];[ref_sc1][enc1]libvmaf_cuda=log_path=vmaf.log[out1];[ref_sc2][enc2]libvmaf_cuda=log_path=vmafneg.log:model=path=/model/vmaf_v0.6.1neg.json[out2]" -map "[out1]" -map "[out2]" -f null /dev/null
Please let me know if you have any issue using these steps.
Leave a Reply