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

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