EN ·
🌏 中文

Compiling FFmpeg with CUDA Support on CentOS 8

Prerequisites

Before starting, ensure that the CUDA toolkit is installed. You will also need to install the following dependencies:

dnf -y install automake autoconf libtool make gcc gcc-c++
dnf --enablerepo=powertools -y install giflib-devel
dnf --enablerepo=powertools -y install libexif-devel
dnf -y install bison pkgconfig glib2-devel gettext make libpng-devel libjpeg-devel libtiff-devel libexif-devel giflib-devel libX11-devel freetype-devel fontconfig-devel cairo-devel fribidi-devel
dnf -y install openssl openssl-devel

Note: Depending on your configuration, powertools might be named PowerTools. To enable the powertools channel, run the following commands:

yum install dnf-plugins-core
yum config-manager --set-enabled powertools

yasm

cd /tmp
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure 
make 
make install

nasm

cd /tmp
wget https://www.nasm.us/pub/nasm/releasebuilds/2.15/nasm-2.15.tar.gz
tar xvf nasm-2.15.tar.gz
cd nasm-2.15
./configure 
make 
make install

libx264

cd /tmp
yum install git
git clone https://code.videolan.org/videolan/x264.git
cd x264
./configure --enable-shared
make 
make install

libmp3lame

cd /tmp
wget https://sourceforge.net/projects/lame/files/lame/3.100/lame-3.100.tar.gz
tar zxvf lame-3.100.tar.gz
cd lame-3.100
./configure --enable-shared
make 
make install

libgdiplus

cd /tmp
wget http://download.mono-project.com/sources/libgdiplus/libgdiplus0-6.0.5.tar.gz
tar zxvf libgdiplus0-6.0.5.tar.gz
cd libgdiplus-6.0.5
./configure
make 
make install

ffnvcodec

cd /tmp
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers && sudo make install && cd -

Alternatively:

sudo dnf -y install nv-codec-headers

Refresh Library Path

echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig

Compile FFmpeg with CUDA

git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/
cd ffmpeg
./configure --enable-cuda-nvcc --enable-cuda --enable-cuvid --enable-nvdec --enable-nvenc --enable-nonfree --enable-libnpp --disable-static --enable-shared --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
make -j8
sudo make install

Testing

ffmpeg -version