root/software/misc/build_ffmpeg_shared.sh @ c5ccc7aa
| 6b9cdf0b | David Sorber | #!/bin/bash
|
|
#
|
|||
###############################################################################
|
|||
# FFmpeg Build Script #
|
|||
# #
|
|||
# This script is based on instructions here: #
|
|||
# https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu #
|
|||
# #
|
|||
# NOTE: The script is designed to build shared libraries instead of static #
|
|||
# ones as the original instructions did. #
|
|||
# #
|
|||
###############################################################################
|
|||
# Helper function to pause between each step
|
|||
function pause {
|
|||
echo "Press any key to continue"
|
|||
read -n 1
|
|||
echo
|
|||
echo
|
|||
}
|
|||
# Setup directories - modify as needed
|
|||
#~ SOURCES_DIR="/home/dsorber/Downloads/ffmpeg/sources"
|
|||
#~ BUILD_DIR="/home/dsorber/Downloads/ffmpeg/build"
|
|||
#~ BIN_DIR="/home/dsorber/Downloads/ffmpeg/bin"
|
|||
DATESTAMP=$(date +%Y%m%d-%H%M%S)
|
|||
SOURCES_DIR="/tmp/ffmpeg-${DATESTAMP}/"
|
|||
INSTALL_DIR="/opt/local"
|
|||
BIN_DIR="$INSTALL_DIR/bin"
|
|||
LIB_DIR="$INSTALL_DIR/lib"
|
|||
# Set to a string containing the version you wish to install
|
|||
FFMPEG_VERSION="5.0" # <--- set this to latest version
|
|||
NUM_CORES=$(cat /proc/cpuinfo | awk '/^processor/{print $3}' | wc -l)
|
|||
if [[ $EUID -ne 0 ]]; then
|
|||
echo -e "ERROR: This script must be run as root\n"
|
|||
exit 1
|
|||
fi
|
|||
echo -e "Sources directory: ${SOURCES_DIR}"
|
|||
echo -e "Install directory: ${INSTALL_DIR}\n\n"
|
|||
# Determine which OS we are running on
|
|||
DISTRIB_ID="$(lsb_release -is)"
|
|||
# CLEAN: rm -rf bin/ build sources/
|
|||
echo "Installing prereqs..."
|
|||
sudo apt -y install \
|
|||
autoconf \
|
|||
automake \
|
|||
build-essential \
|
|||
cmake \
|
|||
git-core \
|
|||
libass-dev \
|
|||
libfreetype6-dev \
|
|||
libgnutls28-dev \
|
|||
libnuma-dev \
|
|||
libsdl2-dev \
|
|||
libtool \
|
|||
libunistring-dev \
|
|||
libva-dev \
|
|||
libvdpau-dev \
|
|||
libvorbis-dev \
|
|||
libxcb1-dev \
|
|||
libxcb-shm0-dev \
|
|||
libxcb-xfixes0-dev \
|
|||
meson \
|
|||
ninja-build \
|
|||
pkg-config \
|
|||
texinfo \
|
|||
wget \
|
|||
yasm \
|
|||
zlib1g-dev
|
|||
# Make the necessary directories
|
|||
mkdir -p $SOURCES_DIR $INSTALL_DIR $BIN_DIR
|
|||
echo
|
|||
echo
|
|||
echo "Building NASM"
|
|||
cd $SOURCES_DIR && \
|
|||
wget https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.bz2 && \
|
|||
tar xjvf nasm-2.15.05.tar.bz2 && \
|
|||
cd nasm-2.15.05 && \
|
|||
./autogen.sh && \
|
|||
PATH="$BIN_DIR:$PATH" ./configure --prefix="$INSTALL_DIR" --bindir="$BIN_DIR" --libdir="$LIB_DIR" && \
|
|||
make -j$NUM_CORES && sudo make install
|
|||
echo
|
|||
echo
|
|||
pause
|
|||
#~ echo "Building Yasm"
|
|||
#~ cd $SOURCES_DIR && \
|
|||
#~ wget -O yasm-1.3.0.tar.gz https://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz && \
|
|||
#~ tar xzvf yasm-1.3.0.tar.gz && \
|
|||
#~ cd yasm-1.3.0 && \
|
|||
#~ ./configure --prefix="$INSTALL_DIR" --bindir="$BIN_DIR" && \
|
|||
#~ make -j$NUM_CORES && \
|
|||
#~ make install
|
|||
#~ echo
|
|||
#~ echo
|
|||
#~ read -n 1
|
|||
echo "Building libx264"
|
|||
cd $SOURCES_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-shared --enable-pic \
|
|||
--extra-ldflags="-Wl,-rpath=$LIB_DIR,--enable-new-dtags" && \
|
|||
PATH="$BIN_DIR:$PATH" make -j$NUM_CORES && sudo make install
|
|||
echo
|
|||
echo
|
|||
pause
|
|||
echo "Buildxing libx265"
|
|||
cd $SOURCES_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" -DLIB_INSTALL_DIR="$LIB_DIR_NAME" \
|
|||
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-rpath=$LIB_DIR,--enable-new-dtags" ../../source && \
|
|||
PATH="$BIN_DIR:$PATH" make -j$NUM_CORES && sudo make install
|
|||
# NOTE: There does not appear to be a way to disable building of static lib;
|
|||
# instead we remove it after the fact
|
|||
rm $LIB_DIR/libx265.a
|
|||
echo
|
|||
echo
|
|||
pause
|
|||
echo "Building libvpx"
|
|||
cd $SOURCES_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" --libdir="$LIB_DIR" --disable-examples \
|
|||
--disable-unit-tests --enable-vp9-highbitdepth --as=yasm --enable-shared --disable-static && \
|
|||
PATH="$BIN_DIR:$PATH" make -j$NUM_CORES && sudo make install
|
|||
echo
|
|||
echo
|
|||
pause
|
|||
echo "Building libfdk-aac"
|
|||
cd $SOURCES_DIR && \
|
|||
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" --libdir="$LIB_DIR" --disable-static && \
|
|||
make -j$NUM_CORES && sudo make install
|
|||
echo
|
|||
echo
|
|||
pause
|
|||
echo "Building libmp3lame"
|
|||
cd $SOURCES_DIR && \
|
|||
wget -O lame-3.100.tar.gz https://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz && \
|
|||
tar xzvf lame-3.100.tar.gz && \
|
|||
cd lame-3.100 && \
|
|||
PATH="$BIN_DIR:$PATH" ./configure --prefix="$INSTALL_DIR" --libdir="$LIB_DIR" --bindir="$BIN_DIR" --disable-static --enable-nasm && \
|
|||
PATH="$BIN_DIR:$PATH" make -j$NUM_CORES && sudo make install
|
|||
echo
|
|||
echo
|
|||
pause
|
|||
echo "Building libopus"
|
|||
cd $SOURCES_DIR && \
|
|||
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" --libdir="$LIB_DIR" --disable-static && \
|
|||
make -j$NUM_CORES && sudo make install
|
|||
echo
|
|||
echo
|
|||
pause
|
|||
echo "Building libaom"
|
|||
cd $SOURCES_DIR && \
|
|||
git -C aom pull 2> /dev/null || git clone --depth 1 https://aomedia.googlesource.com/aom && \
|
|||
mkdir aom_build && \
|
|||
cd aom_build && \
|
|||
PATH="$BIN_DIR:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
|
|||
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-rpath=$LIB_DIR,--enable-new-dtags" \
|
|||
-DBUILD_SHARED_LIBS=1 -DENABLE_NASM=on ../aom && \
|
|||
PATH="$BIN_DIR:$PATH" make -j$NUM_CORES && sudo make install
|
|||
echo
|
|||
echo
|
|||
pause
|
|||
echo "Building libsvtav1"
|
|||
cd $SOURCES_DIR && \
|
|||
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="$BIN_DIR:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" -DCMAKE_BUILD_TYPE=Release \
|
|||
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-rpath=$LIB_DIR,--enable-new-dtags" \
|
|||
-DBUILD_DEC=OFF -DBUILD_SHARED_LIBS=1 .. && \
|
|||
PATH="$BIN_DIR:$PATH" make -j$NUM_CORES && sudo make install
|
|||
echo
|
|||
echo
|
|||
pause
|
|||
echo "Building libdav1d"
|
|||
cd $SOURCES_DIR && \
|
|||
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=shared --prefix="$INSTALL_DIR" \
|
|||
--libdir="$LIB_DIR" --bindir="$BIN_DIR" .. && \
|
|||
ninja && sudo ninja install
|
|||
echo
|
|||
echo
|
|||
pause
|
|||
echo "Building libvmaf"
|
|||
cd $SOURCES_DIR && \
|
|||
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=shared \
|
|||
--prefix="$INSTALL_DIR" --libdir="$LIB_DIR" --bindir="$BIN_DIR" .. && \
|
|||
ninja && sudo ninja install
|
|||
echo
|
|||
echo
|
|||
pause
|
|||
echo "Building ffmpeg"
|
|||
cd $SOURCES_DIR && \
|
|||
wget -O ffmpeg-$FFMPEG_VERSION.tar.bz2 https://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.bz2 && \
|
|||
tar xjvf ffmpeg-$FFMPEG_VERSION.tar.bz2 && \
|
|||
cd ffmpeg-$FFMPEG_VERSION && \
|
|||
PATH="$BIN_DIR:$PATH" PKG_CONFIG_PATH="$INSTALL_DIR/lib/pkgconfig:$INSTALL_DIR/lib64/pkgconfig" ./configure \
|
|||
--enable-shared \
|
|||
--disable-static \
|
|||
--prefix="$INSTALL_DIR" \
|
|||
--libdir="$LIB_DIR" \
|
|||
--extra-cflags="-I$INSTALL_DIR/include" \
|
|||
--extra-ldflags="-L$LIB_DIR -Wl,-rpath=$LIB_DIR,--enable-new-dtags" \
|
|||
--extra-libs="-lpthread -lm" \
|
|||
--ld="g++" \
|
|||
--enable-gpl \
|
|||
--enable-gnutls \
|
|||
--enable-libaom \
|
|||
--enable-libass \
|
|||
--enable-libfdk-aac \
|
|||
--enable-libfreetype \
|
|||
--enable-libmp3lame \
|
|||
--enable-libopus \
|
|||
--enable-libsvtav1 \
|
|||
--enable-libdav1d \
|
|||
--enable-libvorbis \
|
|||
--enable-libvpx \
|
|||
--enable-libx264 \
|
|||
--enable-libx265 \
|
|||
--enable-nonfree && \
|
|||
PATH="$BIN_DIR:$PATH" make -j$NUM_CORES && sudo make install && \
|
|||
hash -r
|