I have created a script to compile FFmpeg on Solus. A few issues with pkg-config not recognizing libsvtav1, libass, and libfreetype on my machine, so I commented those lines out for now.
Let me know any improvements/fixes!
#!/bin/bash
### Description ###
# Compiles and installs FFmpeg for SolusOS.
# May be run with "-y" or "--yes" flag to confirm prompts. Password input will still be required for "sudo" commands.
# This script performs the following:
# 1) Creates 3 directories in the working directory: "ffmpeg", "ffmpeg_build", "ffmpeg_sources". Binaries will be installed in the "ffmpeg" directory.
# 2) Install base development tools "eopkg install -c system.devel" https://getsol.us/articles/package-management/basics/en/#base-development-tools
# 3) Install dependencies for FFmpeg and third-party libraries
# 4) Clone the FFmpeg git repository
# 5) Compile FFmpeg
### Configuration ###
libs=( \
libx264 \
libx265 \
libvpx \
libfdk-aac \
libmp3lame \
libopus \
libaom \
# libsvtav1 \ gives an error
libdav1d \
libvmaf \
librav1e \
)
# release version or "master" for nightly build
release=master
# release=4.4
### Set-up ###
if [[ $1 != "-y" && $1 != "--yes" ]]; then
echo "This script will install base development tools, FFmpeg dependencies, and third-party libraries according to the \"Configuration\" section. Continue? [Y/n]"
read cont
if [[ $cont != "Y" ]]; then
exit 1
fi
fi
if [[ -d "ffmpeg" || -d "ffmpeg_build" || -d "ffmpeg_sources" ]]; then
if [[ $1 != "-y" && $1 != "--yes" ]]; then
echo "Remove directories \"ffmpeg\", \"ffmpeg_build\", \"ffmpeg_sources\" to continue? [Y/n]"
read delete
if [[ $delete != "Y" ]]; then
exit 1
fi
fi
rm -rf ffmpeg
rm -rf ffmpeg_build
rm -rf ffmpeg_sources
fi
mkdir -p ffmpeg
mkdir -p ffmpeg_build
mkdir -p ffmpeg_sources
wd=$(pwd)
PATH="$wd/ffmpeg:$PATH"
### Install Dependencies ###
echo "Installing base development tools..."
sudo eopkg install -c system.devel
installed=$(eopkg li | awk '{ print $1 }')
to_install=""
if ! [[ $installed =~ "autoconf" ]]; then
to_install="$to_install autoconf"
fi
if ! [[ $installed =~ "automake" ]]; then
to_install="$to_install automake"
fi
if ! [[ $installed =~ "cmake" ]]; then
to_install="$to_install cmake"
fi
if ! [[ $installed =~ "git" ]]; then
to_install="$to_install git"
fi
if ! [[ $installed =~ "libass-devel" ]]; then
to_install="$to_install libass-devel"
fi
if ! [[ $installed =~ "freetype2-devel" ]]; then
to_install="$to_install freetype2-devel"
fi
if ! [[ $installed =~ "libgnutls-devel" ]]; then
to_install="$to_install libgnutls-devel"
fi
if ! [[ $installed =~ "sdl2-devel" ]]; then
to_install="$to_install sdl2-devel"
fi
if ! [[ $installed =~ "libtool" ]]; then
to_install="$to_install libtool"
fi
if ! [[ $installed =~ "libva-devel" ]]; then
to_install="$to_install libva-devel"
fi
if ! [[ $installed =~ "libvdpau-devel" ]]; then
to_install="$to_install libvdpau-devel"
fi
if ! [[ $installed =~ "libvorbis-devel" ]]; then
to_install="$to_install libvorbis-devel"
fi
if ! [[ $installed =~ "libxcb-devel" ]]; then
to_install="$to_install libxcb-devel"
fi
if ! [[ $installed =~ "meson" ]]; then
to_install="$to_install meson"
fi
if ! [[ $installed =~ "ninja" ]]; then
to_install="$to_install ninja"
fi
if ! [[ $installed =~ "pkg-config" ]]; then
to_install="$to_install pkg-config"
fi
if ! [[ $installed =~ "texinfo" ]]; then
to_install="$to_install texinfo"
fi
if ! [[ $installed =~ "wget" ]]; then
to_install="$to_install wget"
fi
if ! [[ $installed =~ "yasm" ]]; then
to_install="$to_install yasm"
fi
if ! [[ $installed =~ "zlib-devel" ]]; then
to_install="$to_install zlib-devel"
fi
if ! [[ $installed =~ "nasm" ]]; then
to_install="$to_install nasm"
fi
if ! [[ $installed =~ "libunistring-devel" ]]; then
to_install="$to_install libunistring-devel"
fi
sudo eopkg upgrade -y
if [[ $to_install != "" ]]; then
echo "Installing FFmpeg dependencies..."
sudo eopkg install -y $to_install
fi
### Install third-party libraries ###
containsElement() {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
to_install=""
enable_lib_str=""
containsElement "libx264" "${libs[@]}"
match=$(echo $?)
if [[ $match == 0 ]]; then
if ! [[ $installed =~ "x264-devel" ]]; then
to_install="$to_install x264-devel"
fi
enable_lib_str="$enable_lib_str --enable-libx264"
fi
containsElement "libx265" "${libs[@]}"
match=$(echo $?)
if [[ $match == 0 ]]; then
if ! [[ $installed =~ "x265-devel" ]]; then
to_install="$to_install x265-devel"
fi
enable_lib_str="$enable_lib_str --enable-libx265"
fi
containsElement "libvpx" "${libs[@]}"
match=$(echo $?)
if [[ $match == 0 ]]; then
if ! [[ $installed =~ "libvpx-devel" ]]; then
to_install="$to_install libvpx-devel"
fi
enable_lib_str="$enable_lib_str --enable-libvpx"
fi
containsElement "libfdk-aac" "${libs[@]}"
match=$(echo $?)
if [[ $match == 0 ]]; then
if ! [[ $installed =~ "fdk-aac-devel" ]]; then
to_install="$to_install fdk-aac-devel"
fi
enable_lib_str="$enable_lib_str --enable-libfdk-aac"
fi
containsElement "libmp3lame" "${libs[@]}"
match=$(echo $?)
if [[ $match == 0 ]]; then
if ! [[ $installed =~ "lame-devel" ]]; then
to_install="$to_install lame-devel"
fi
enable_lib_str="$enable_lib_str --enable-libmp3lame"
fi
containsElement "libopus" "${libs[@]}"
match=$(echo $?)
if [[ $match == 0 ]]; then
if ! [[ $installed =~ "opus-devel" ]]; then
to_install="$to_install opus-devel"
fi
enable_lib_str="$enable_lib_str --enable-libopus"
fi
containsElement "libaom" "${libs[@]}"
match=$(echo $?)
if [[ $match == 0 ]]; then
if ! [[ $installed =~ "aom-devel" ]]; then
to_install="$to_install aom-devel"
fi
enable_lib_str="$enable_lib_str --enable-libaom"
fi
containsElement "libsvtav1" "${libs[@]}"
match=$(echo $?)
if [[ $match == 0 ]]; then
cd ffmpeg_sources
git -C SVT-AV1 pull 2> /dev/null || git clone https://gitlab.com/AOMediaCodec/SVT-AV1.git
mkdir -p SVT-AV1/build
cd SVT-AV1/build
PATH="$wd/ffmpeg:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$wd/ffmpeg_build" -DCMAKE_BUILD_TYPE=Release -DBUILD_DEC=OFF -DBUILD_SHARED_LIBS=OFF .. && \
PATH="$wd/ffmpeg:$PATH" make && \
make install
cd $wd
enable_lib_str="$enable_lib_str --enable-libsvtav1"
fi
containsElement "libdav1d" "${libs[@]}"
match=$(echo $?)
if [[ $match == 0 ]]; then
if ! [[ $installed =~ "dav1d-devel" ]]; then
to_install="$to_install dav1d-devel"
fi
enable_lib_str="$enable_lib_str --enable-libdav1d"
fi
containsElement "libvmaf" "${libs[@]}"
match=$(echo $?)
if [[ $match == 0 ]]; then
cd ffmpeg_sources
wget https://github.com/Netflix/vmaf/archive/v2.1.1.tar.gz
tar xvf v2.1.1.tar.gz
mkdir -p vmaf-2.1.1/libvmaf/build
cd vmaf-2.1.1/libvmaf/build
meson setup -Denable_tests=false -Denable_docs=false --buildtype=release --default-library=static .. --prefix "$wd/ffmpeg_build" --bindir="$wd/ffmpeg_build/bin" --libdir="$wd/ffmpeg_build/lib" && \
ninja && \
ninja install
cd $wd
enable_lib_str="$enable_lib_str --enable-libvmaf"
fi
containsElement "librav1e" "${libs[@]}"
match=$(echo $?)
if [[ $match == 0 ]]; then
if ! [[ $installed =~ "rav1e-devel" ]]; then
to_install="$to_install rav1e-devel"
fi
enable_lib_str="$enable_lib_str --enable-librav1e"
fi
if [[ "$enable_lib_str" != "" ]]; then
enable_lib_str="${enable_lib_str##*( )}"
fi
if [[ $to_install != "" ]]; then
echo "Installing third-party libraries..."
sudo eopkg install -y $to_install
fi
### Git FFmpeg ###
cd $wd/ffmpeg_sources
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
if [[ $release != "master" ]]; then
cd ffmpeg
git checkout -b "release/$release" "origin/release/$release"
git pull
fi
### Compile FFmpeg###
cd $wd/ffmpeg_sources/ffmpeg
PATH="$wd/ffmpeg:$PATH" PKG_CONFIG_PATH="$wd/ffmpeg_build/lib/pkgconfig" ./configure \
--prefix="$wd/ffmpeg_build" \
--pkg-config-flags="--static" \
--extra-cflags="-I$wd/ffmpeg_build/include" \
--extra-ldflags="-L$wd/ffmpeg_build/lib" \
--extra-libs="-lpthread -lm" \
--ld="g++" \
--bindir="$wd/ffmpeg" \
--enable-gpl \
--enable-gnutls \
--enable-libvorbis \
$enable_lib_str \
--enable-nonfree && \
PATH="$wd/ffmpeg:$PATH" make && \
make install && \
hash -r
# Currently these libraries are not found by pkg-config. Add them back once error is solved:
# --enable-libass \
# --enable-libfreetype \
echo "Script complete. Add \"${wd}/ffmpeg\" to your \$PATH. You may optionally remove directories \"ffmpeg_build\" and \"ffmpeg_sources\"."