Compiling ffmpeg with cuda and shared library
Remeber to build shared library for all libs.
Ex: for libsvtav1 use -DBUILD_SHARED_LIBS=ON in the command.
cd ~/ffmpeg_sources && \
git -C SVT-AV1 pull 2> /dev/null || git clone https://gitlab.com/AOMediaCodec/SVT-AV1.git && \
mkdir -p SVT-AV1/build && \
cd SVT-AV1/build && \
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DCMAKE_BUILD_TYPE=Release -DBUILD_DEC=OFF -DBUILD_SHARED_LIBS=ON .. && \
PATH="$HOME/bin:$PATH" make && \
make install
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig" CC=gcc CXX=g++ CFLAGS="-D__linux__ -U__WIN32__ -U_WIN32 -U_WIN64" CXXFLAGS="-D__linux__ -U__WIN32__ -U_WIN32 -U_WIN64" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include -I/usr/local/cuda/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib -L/usr/local/cuda/lib64" --extra-libs="-lpthread -lm" --ld="g++" --bindir="$HOME/bin" --enable-gpl --enable-gnutls --enable-libaom --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libsvtav1 --enable-libdav1d --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree --enable-cuda-nvcc --enable-libnpp --disable-static --enable-shared --disable-doc --disable-debug --disable-lzma
make
make install
Don’t forget to dump the cache so that shell can find binaries from $PATH freshly.
hash -r
Add to path
sudo ln -s /home/{username}/bin/ffmpeg /usr/local/bin/
Redo the compiling process
make distclean || rm -rf config.*
Common Errors
Encountering the error ERROR: dav1d >= 0.2.1 not found using pkg-config while pkg-config --modversion dav1d shows the module do existing.
$ pkg-config --modversion dav1d
1.3.0
The reason this error occurs, despite pkg-config seemingly finding the library, is often related to how the build system (like Meson or Autotools) is executing pkg-config. Make sure you have the correct PKG_CONFIG_PATH
export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH"