Skip to content

FFmpeg with NVIDIA Acceleration

Using NVIDIA hardware acceleration in FFmpeg/libav requires the following steps

  1. Download and install the compatible driver from NVIDIA web site
  2. Download and install ffnvcodec:
bash
        git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
        cd nv-codec-headers && sudo make install && cd -
  1. Download and install the CUDA Toolkit CUDA toolkit

For Linux Mint 19.3:

bash
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
sudo apt-get update
sudo apt-get -y install cuda
  1. Ensure that your PATH includes the bin directory where you installed the Toolkit
bash
export PATH=/usr/local/cuda-10.2/bin${PATH:+:${PATH}}
  1. Install sudo apt install nasm yasm
  2. Download the latest FFmpeg or libav source code, by cloning the corresponding GIT repositories
  3. Use the following configure command (Use correct CUDA library path in config command below)
bash
./configure --enable-cuda-nvcc --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
  1. Use the following command to compile:
bash
make -j $(nproc)
  1. Install
bash
sudo make install

Sources: