Skip to content

Commit

Permalink
improvement: link deps of ffmpeg also statically
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart-Steensma committed Jan 30, 2024
1 parent 5efd03e commit 8bf01d5
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches:
- main
# - develop
- develop
pull_request:
branches:
- main
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,6 @@ more information.

- [ ] Cross compile for raspberry pi

- [ ] For ffmpeg, build the other dependencies from source as well such that
these can be linked statically as well. Do this only for the dependencies
that are included in the ffmpeg docs.

- [ ] Use ffmpeg 6.0, that is tested by Qt. If not possible, fix the version
instead of using the latest version.

Expand Down
99 changes: 90 additions & 9 deletions scripts/build-ffmpeg
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ set -euo pipefail

this_dir=$(dirname "$(realpath "${BASH_SOURCE:-$0}")")
root="$(dirname "$this_dir")"
usage="$(basename "$0") [-h] [-s, --source-dir] [-b, --install-dir] -- Compiles ffmpeg from source
static=true
shared=false
source_dir="$root/ffmpeg_sources"
install_dir="$this_dir/../3rdparty/ffmpeg"

usage="$(basename "$0") [-h] [-s, --source-dir] [-b, --install-dir] --
Compiles ffmpeg from source.
The packages managers \`apt\` and \`pacman\` are supported.
where:
-h, --help show this help text
--static build static libraries (default: true)
--shared build shared libraries (default: false)
-s, --source-dir ffmpeg source directory (default: $root/ffmpeg_sources)
-i, --install-dir ffmpeg build directory (default: $this_dir/../3rdparty/ffmpeg)"

static=true
shared=false
source_dir="$root/ffmpeg_sources"
install_dir="$this_dir/../3rdparty/ffmpeg"
-s, --source-dir ffmpeg source directory (default: $source_dir)
-i, --install-dir ffmpeg build directory (default: $install_dir)"

while [[ $# -gt 0 ]]; do
key="$1"
Expand Down Expand Up @@ -61,6 +62,78 @@ install_dependencies() {
"${this_dir}/helpers/${manager}/install-ffmpeg-deps"
}

compile_nasm() {
cd "$source_dir" &&
wget https://www.nasm.us/pub/nasm/releasebuilds/2.16.01/nasm-2.16.01.tar.bz2 &&
tar xjvf nasm-2.16.01.tar.bz2 &&
cd nasm-2.16.01 &&
./autogen.sh &&
PATH="$bin_dir:$PATH" ./configure --prefix="$install_dir" --bindir="$bin_dir" &&
make &&
make install
}

compile_x264() {
cd "$source_dir" &&
git -C x264 pull 2>/dev/null || git clone --depth 1 https://code.videolan.org/videolan/x264.git &&
cd x264 &&
PATH="$bin_dir:$PATH" PKG_CONFIG_PATH="$install_dir/lib/pkgconfig" ./configure --prefix="$install_dir" --bindir="$bin_dir" --enable-static --enable-pic &&
PATH="$bin_dir:$PATH" make &&
make install
}

compile_x265() {
cd "$source_dir" &&
wget -O x265.tar.bz2 https://bitbucket.org/multicoreware/x265_git/get/master.tar.bz2 &&
tar xjvf x265.tar.bz2 &&
cd multicoreware*/build/linux &&
PATH="$bin_dir:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$install_dir" -DENABLE_SHARED=off ../../source &&
PATH="$bin_dir:$PATH" make &&
make install
}

compile_libvpx() {
cd "$source_dir" &&
git -C libvpx pull 2>/dev/null || git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git &&
cd libvpx &&
PATH="$bin_dir:$PATH" ./configure --prefix="$install_dir" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm &&
PATH="$bin_dir:$PATH" make &&
make install
}

compile_fdk-aac() {
cd "$source_dir" &&
PATH="$bin_dir:$PATH" &&
git -C fdk-aac pull 2>/dev/null || git clone --depth 1 https://github.com/mstorsjo/fdk-aac &&
cd fdk-aac &&
autoreconf -fiv &&
./configure --prefix="$install_dir" --disable-shared &&
make &&
make install
}

compile_libopus() {
cd "$source_dir" &&
PATH="$bin_dir:$PATH" &&
git -C opus pull 2>/dev/null || git clone --depth 1 https://github.com/xiph/opus.git &&
cd opus &&
./autogen.sh &&
./configure --prefix="$install_dir" --disable-shared &&
make &&
make install
}

compile_libdav1d() {
cd "$source_dir" &&
PATH="$bin_dir:$PATH" &&
git -C dav1d pull 2>/dev/null || git clone --depth 1 https://code.videolan.org/videolan/dav1d.git &&
mkdir -p dav1d/build &&
cd dav1d/build &&
meson setup -Denable_tools=false -Denable_tests=false --default-library=static .. --prefix "$install_dir" --libdir="$install_dir/lib" &&
ninja &&
ninja install
}

compile_libaom() {
echo "Compiling libaom"
cd "$source_dir" &&
Expand All @@ -86,6 +159,7 @@ compile_libsvtav1() {
compile_libvmaf() {
echo "Compiling libvmaf"
cd "$source_dir" &&
PATH="$bin_dir:$PATH" &&
wget https://github.com/Netflix/vmaf/archive/v2.3.1.tar.gz && tar xvf v2.3.1.tar.gz &&
mkdir -p vmaf-2.3.1/libvmaf/build &&
cd vmaf-2.3.1/libvmaf/build &&
Expand All @@ -100,7 +174,7 @@ compile_ffmpeg() {
unpack_dir="ffmpeg"
cd "$source_dir" &&
wget -O "$file" https://ffmpeg.org/releases/"$file" &&
tar xjvf "$file" &&
tar xjvf "$file" &&
cd "$unpack_dir" &&
PATH="$bin_dir:$PATH" PKG_CONFIG_PATH="$install_dir/lib/pkgconfig" ./configure \
$@ \
Expand Down Expand Up @@ -136,6 +210,13 @@ rm -rf "$source_dir" || true
rm -rf "$install_dir" || true
mkdir -p "$source_dir" "$bin_dir"
install_dependencies
compile_nasm
compile_x264
compile_x265
compile_libvpx
compile_fdk-aac
compile_libopus
compile_libdav1d
compile_libaom
compile_libsvtav1
compile_libvmaf
Expand Down
4 changes: 2 additions & 2 deletions scripts/helpers/apt/install-ffmpeg-deps
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail
echo "Updating apt-get"
sudo apt-get update -qq
echo "Installing build tools and dependencies"
sudo apt-get -y install autoconf automake build-essential cmake git-core libass-dev libfreetype6-dev libgnutls28-dev libmp3lame-dev libsdl2-dev libtool libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev meson ninja-build pkg-config texinfo wget yasm zlib1g-dev gnutls-bin libunistring-dev libaom-dev libdav1d-dev tar || true
sudo apt-get -y install python3 autoconf automake build-essential cmake git-core libass-dev libfreetype6-dev libgnutls28-dev libmp3lame-dev libsdl2-dev libtool libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev meson ninja-build pkg-config texinfo wget yasm zlib1g-dev gnutls-bin libunistring-dev libaom-dev libdav1d-dev tar

echo "Installing ffmpeg dependencies"
sudo apt-get -y install nasm libx264-dev libx265-dev libvpx-dev libfdk-aac-dev libopus-dev libdav1d-dev libnuma-dev libva-dev libdrm-dev || true
sudo apt-get -y install libnuma-dev libva-dev libdrm-dev
7 changes: 3 additions & 4 deletions scripts/helpers/pacman/install-ffmpeg-deps
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
set -euo pipefail

echo "Installing build tools and dependencies"
sudo pacman -S --noconfirm autoconf automake cmake git libass freetype2 sdl2 libtool libvdpau libvorbis libxcb meson ninja pkgconf texinfo wget yasm gnutls libunistring aom dav1d tar || true
sudo pacman -S --noconfirm zlib || true
sudo pacman -S --noconfirm autoconf automake cmake git libass freetype2 sdl2 libtool libvdpau libvorbis libxcb meson ninja pkgconf texinfo wget yasm gnutls libunistring tar
sudo pacman -S --noconfirm zlib

echo "Installing ffmpeg dependencies"
sudo pacman -S --noconfirm nasm x264 x265 fdkaac opus numactl libdrm libva || true
sudo pacman -S --noconfirm libvpx || true
sudo pacman -S --noconfirm numactl libdrm libva numactl

0 comments on commit 8bf01d5

Please sign in to comment.