Skip to content

Instantly share code, notes, and snippets.

@Ghostbird
Last active December 22, 2023 02:05
Show Gist options
  • Save Ghostbird/11b62ae6370a4f42babc7c8164f44d9d to your computer and use it in GitHub Desktop.
Save Ghostbird/11b62ae6370a4f42babc7c8164f44d9d to your computer and use it in GitHub Desktop.
Automatically compile and install FFMPEG with NVIDIA hardware acceleration on Debian 10+
#!/bin/bash
# Automatically compile and install FFMPEG with NVIDIA hardware acceleration on Debian
# Based on https://www.tal.org/tutorials/ffmpeg_nvidia_encode
# Verified working on Debian 10 and 11
# Abort on error
set -e
suite=stable
sudo apt-get build-dep ffmpeg -t $suite
sudo apt-get install nvidia-cuda-toolkit -t $suite
mkdir -p ffmpeg-deb/src
cd ffmpeg-deb
if [[ -d nv-codec-headers ]]
then
cd nv-codec-headers
git fetch --tags
else
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
fi
# Checkout latest release, intead of HEAD. The Debian driver in stable may not yet support the pre-release API.
git checkout $(git describe --tags $(git rev-list --tags --max-count=1))
make
sudo make install
cd ../src
rm -rf ./*
apt-get source ffmpeg -t $suite
cd ffmpeg-*
sed -i 's/--enable-sdl2/--enable-sdl2 --enable-cuda --enable-nvenc/' debian/rules
DEB_BUILD_OPTIONS="nocheck nodoc notest" dpkg-buildpackage -r -nc -j4 --no-sign
cd ..
# Install all built packages, except the non-extra variants of libavfilter and libavcodec
sudo dpkg -i $(ls *.deb | grep -Ev "(libavfilter|libavcodec)[0-9]+_")
echo "Verification:"
ffmpeg -codecs 2> /dev/null | grep nvenc
@Ghostbird
Copy link
Author

Ghostbird commented Dec 3, 2022

Found an interesting issue just now. nv-codec-headers HEAD is already at API 12 but the Debian stable driver only supports up to API 11. That makes sense, API 12 is not officially released yet AFAIK.
I've changed the script to checkout and build the latest tag from nv-codec-headers , instead of HEAD. This solves the issue where you try to use an NVENC codec in ffmpeg and receive:

[h264_nvenc @ 0x55639ee42180] Driver does not support the required nvenc API version. Required: 12.0 Found: 11.1
[h264_nvenc @ 0x55639ee42180] The minimum required Nvidia driver for nvenc is (unknown) or newer

@Ghostbird
Copy link
Author

This script is now superseded by build-ffmpeg-nvidia.sh.

It compiles FFMPEG with cuvid, cuvid, nvdec, nvenc, and non-free libnpp.

I've decided to make that a separate script, instead of an upgrade to this one, because it includes the --enable-nonfree flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment