Last active
April 29, 2025 23:30
-
-
Save Ghostbird/11b62ae6370a4f42babc7c8164f44d9d to your computer and use it in GitHub Desktop.
Automatically compile and install FFMPEG with NVIDIA hardware acceleration on Debian 10+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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
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
I've checked the script. The only difference was that I had locally added the
notest
option. I've added it here too.Note, this buils and installs all
ffmpeg
dependencies however these include two pairs of mutually exclusive ones,libavcodec58
vslibavcodec58-extra
andlibavfilter7
vslibavfilter-extra7
.I've updated the install line in the script to exclude the non-extra variants. Maybe that'll fix your issue. In my case dpkg automatically made the right choice to not install the normal variants in favour of the -extra variants.
The changed line is 32:
sudo dpkg -i $(ls *.deb | grep -Ev "(libavfilter|libavcodec)[0-9]+_")
Runs a subshell that lists all files ending in
.deb
and feeds that list togrep
using extended regex mode (-E
) and inverse output (-v
outputs only non-matching lines). Finallydpkg -i
installs the resulting list of deb files from the subshell output.