Last active
November 19, 2024 21:34
-
-
Save masterflitzer/b176bc9b3729554fe12d1bcc97c8d3cf to your computer and use it in GitHub Desktop.
Compile ffmpeg on Debian
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
#!/usr/bin/env bash | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
shopt -s inherit_errexit | |
if test -z "${FFMPEG_VERSION:-}" | |
then | |
echo "You need to set the FFMPEG_VERSION environment variable (see https://git.ffmpeg.org/gitweb/ffmpeg.git/tags)" | |
exit 1 | |
fi | |
FFMPEG_VERSION="${FFMPEG_VERSION#n}" | |
FFMPEG_VERSION="${FFMPEG_VERSION#v}" | |
THREADS="$(nproc)" | |
sudo apt update | |
sudo apt install \ | |
autoconf \ | |
automake \ | |
build-essential \ | |
cargo-c \ | |
cmake \ | |
curl \ | |
git-core \ | |
gnutls-dev \ | |
jq \ | |
libaom-dev \ | |
libass-dev \ | |
libdav1d-dev \ | |
libfdk-aac-dev \ | |
libfreetype-dev \ | |
libjxl-dev \ | |
libmp3lame-dev \ | |
libnuma-dev \ | |
libopus-dev \ | |
libsdl2-dev \ | |
libtool \ | |
libunistring-dev \ | |
libvorbis-dev \ | |
libvpx-dev \ | |
libwebp-dev \ | |
libx264-dev \ | |
libx265-dev \ | |
libxcb-shm0-dev \ | |
libxcb-xfixes0-dev \ | |
libxcb1-dev \ | |
meson \ | |
nasm \ | |
ninja-build \ | |
pkg-config \ | |
texinfo \ | |
yasm \ | |
zlib1g-dev | |
BIN_DIR="${HOME}/bin" | |
FFMPEG_BUILD_DIR="${HOME}/ffmpeg-build" | |
FFMPEG_SOURCES_DIR="${HOME}/ffmpeg-sources" | |
mkdir -p "${BIN_DIR}" "${FFMPEG_BUILD_DIR}" "${FFMPEG_SOURCES_DIR}" | |
# aom | |
printf "\n\n### AOM ###\n\n" | |
AOM_BUILD_DIR="${FFMPEG_SOURCES_DIR}/aom-build" | |
cd "${FFMPEG_SOURCES_DIR}" && \ | |
{ git -C aom switch main; git -C aom pull --prune; } > /dev/null 2>&1 || git clone "https://aomedia.googlesource.com/aom" aom && \ | |
git -C aom switch --detach "$(git -C aom tag --sort=-version:refname | grep -Fiv -- "-rc" | head -n 1)" && \ | |
mkdir -p "${AOM_BUILD_DIR}" && \ | |
cd "${AOM_BUILD_DIR}" && \ | |
PATH="${HOME}/bin:${PATH}" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="${FFMPEG_BUILD_DIR}" -DENABLE_TESTS="OFF" -DENABLE_NASM="on" "../aom" && \ | |
PATH="${HOME}/bin:${PATH}" make -j"${THREADS}" && \ | |
make -j"${THREADS}" install && \ | |
rm -r "${AOM_BUILD_DIR}" | |
# svt-av1 | |
printf "\n\n### SVT-AV1 ###\n\n" | |
SVTAV1_BUILD_DIR="${FFMPEG_SOURCES_DIR}/svt-av1-build" | |
SVTAV1_DEFAULT_BRANCH="$(curl -fsSL "https://gitlab.com/api/v4/projects/aomediacodec%2fsvt-av1" | jq -r ".default_branch")" | |
SVTAV1_TAG="$(curl -fsSL "https://gitlab.com/api/v4/projects/aomediacodec%2fsvt-av1/releases/permalink/latest" | jq -r ".tag_name")" | |
cd "${FFMPEG_SOURCES_DIR}" && \ | |
{ git -C svt-av1 switch "${SVTAV1_DEFAULT_BRANCH}"; git -C svt-av1 pull --prune; } > /dev/null 2>&1 || git clone "https://gitlab.com/aomediacodec/svt-av1.git" svt-av1 && \ | |
git -C svt-av1 switch --detach "${SVTAV1_TAG}" && \ | |
mkdir -p "${SVTAV1_BUILD_DIR}" && \ | |
cd "${SVTAV1_BUILD_DIR}" && \ | |
PATH="${HOME}/bin:${PATH}" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="${FFMPEG_BUILD_DIR}" -DCMAKE_BUILD_TYPE="Release" -DBUILD_DEC="OFF" -DBUILD_SHARED_LIBS="OFF" "../svt-av1" && \ | |
PATH="${HOME}/bin:${PATH}" make -j"${THREADS}" && \ | |
make -j"${THREADS}" install && \ | |
rm -r "${SVTAV1_BUILD_DIR}" | |
# rav1e | |
printf "\n\n### RAV1E ###\n\n" | |
RAV1E_DEFAULT_BRANCH="$(curl -fsSL "https://api.github.com/repos/xiph/rav1e" | jq -r ".default_branch")" | |
RAV1E_TAG="$(curl -fsSL "https://api.github.com/repos/xiph/rav1e/releases/latest" | jq -r ".tag_name")" | |
cd "${FFMPEG_SOURCES_DIR}" && \ | |
{ git -C rav1e switch "${RAV1E_DEFAULT_BRANCH}"; git -C rav1e pull --prune; } > /dev/null 2>&1 || git clone "https://github.com/xiph/rav1e.git" rav1e && \ | |
git -C rav1e switch --detach "${RAV1E_TAG}" && \ | |
cd rav1e && \ | |
RUSTFLAGS="-C target-cpu=native" cargo cinstall --release --prefix "${FFMPEG_BUILD_DIR}" --libdir lib --library-type staticlib | |
# vmaf | |
printf "\n\n### VMAF ###\n\n" | |
VMAF_BUILD_DIR="${FFMPEG_SOURCES_DIR}/vmaf-build" | |
VMAF_DEFAULT_BRANCH="$(curl -fsSL "https://api.github.com/repos/netflix/vmaf" | jq -r ".default_branch")" | |
VMAF_TAG="$(curl -fsSL "https://api.github.com/repos/netflix/vmaf/releases/latest" | jq -r ".tag_name")" | |
cd "${FFMPEG_SOURCES_DIR}" && \ | |
{ git -C vmaf switch "${VMAF_DEFAULT_BRANCH}"; git -C vmaf pull --prune; } > /dev/null 2>&1 || git clone "https://github.com/netflix/vmaf.git" vmaf && \ | |
git -C vmaf switch --detach "${VMAF_TAG}" && \ | |
mkdir -p "${VMAF_BUILD_DIR}" && \ | |
cd "${VMAF_BUILD_DIR}" && \ | |
meson setup -Denable_tests="false" -Denable_docs="false" --buildtype="release" --default-library="static" "../vmaf/libvmaf" --prefix "${FFMPEG_BUILD_DIR}" --bindir="bin" --libdir="lib" && \ | |
ninja -j"${THREADS}" && \ | |
ninja -j"${THREADS}" install && \ | |
rm -r "${VMAF_BUILD_DIR}" | |
# ffmpeg | |
printf "\n\n### FFMPEG ###\n\n" | |
FFMPEG_VERSION_STRING="ffmpeg-${FFMPEG_VERSION}" | |
cd "${FFMPEG_SOURCES_DIR}" && \ | |
curl -fsSLO "https://ffmpeg.org/releases/${FFMPEG_VERSION_STRING}.tar.xz" && \ | |
tar -xf "${FFMPEG_VERSION_STRING}.tar.xz" && \ | |
rm "${FFMPEG_VERSION_STRING}.tar.xz" && \ | |
cd "${FFMPEG_VERSION_STRING}" && \ | |
PATH="${HOME}/bin:${PATH}" PKG_CONFIG_PATH="${FFMPEG_BUILD_DIR}/lib/pkgconfig" ./configure \ | |
--prefix="${FFMPEG_BUILD_DIR}" \ | |
--pkg-config-flags="--static" \ | |
--extra-cflags="-I${FFMPEG_BUILD_DIR}/include" \ | |
--extra-ldflags="-L${FFMPEG_BUILD_DIR}/lib" \ | |
--extra-libs="-lpthread -lm" \ | |
--ld="g++" \ | |
--bindir="${HOME}/bin" \ | |
--enable-gpl \ | |
--enable-gnutls \ | |
--enable-libaom \ | |
--enable-libass \ | |
--enable-libdav1d \ | |
--enable-libfdk-aac \ | |
--enable-libfreetype \ | |
--enable-libjxl \ | |
--enable-libmp3lame \ | |
--enable-libopus \ | |
--enable-librav1e \ | |
--enable-libsvtav1 \ | |
--enable-libvmaf \ | |
--enable-libvorbis \ | |
--enable-libvpx \ | |
--enable-libwebp \ | |
--enable-libx264 \ | |
--enable-libx265 \ | |
--enable-nonfree && \ | |
PATH="${HOME}/bin:${PATH}" make -j"${THREADS}" && \ | |
make -j"${THREADS}" install && \ | |
cd .. && \ | |
rm -r "${FFMPEG_SOURCES_DIR:?}/${FFMPEG_VERSION_STRING:?}" && \ | |
hash -r | |
. ~/.profile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment