Last active
December 22, 2023 02:05
-
-
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 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 |
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
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 ofHEAD
. This solves the issue where you try to use an NVENC codec in ffmpeg and receive: