FFmpeg with NVIDIA Acceleration

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

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

    For Linux Mint 19.3:

    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
  • Ensure that your PATH includes the bin directory where you installed the Toolkit
    export PATH=/usr/local/cuda-10.2/bin${PATH:+:${PATH}}
  • Install sudo apt install nasm yasm
  • Download the latest FFmpeg or libav source code, by cloning the corresponding GIT repositories
  • Use the following configure command (Use correct CUDA library path in config command below)
    ./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
  • Use the following command to compile:
    make -j $(nproc)
  • Install
    sudo make install