FFmpeg with Nvidia GPU on Ubuntu 20.04

Page content

Prep - Install Nvidia driver and cuda-toolkit

I installed on Ubuntu 20.04.

Install

https://developer.nvidia.com/ffmpeg

git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers && sudo make install && cd –
git clone https://git.ffmpeg.org/ffmpeg.git
cd ffmpeg
#export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
sudo apt install -y pkg-config
./configure --enable-cuda-sdk --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
make -j 10

Error 1

/usr/local/cuda-10.2/bin/../targets/x86_64-linux/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
  138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
      |  ^~~~~
ERROR: failed checking for nvcc.

This is because I installed CUDA with GCC 9 (Ubuntu 20.04 default version) with option --override.

sudo sh cuda_10.2.89_440.33.01_linux.run --overwride

Re-install cuda with right version

sudo apt -y install gcc-7 g++-7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 7
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 7
sudo sh cuda_10.2.89_440.33.01_linux.run #install cuda agaim

After CUDA installation, back again.

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 9

Error2

Got error like below.

ERROR: cuvid requested, but not all dependencies are satisfied: ffnvcodec

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help

This is because pkg-config is not installed in your environment. Install it.

sudo apt install -y pkg-config