Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static build with extra options for backend linux #4

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
188 changes: 171 additions & 17 deletions build-ffmpeg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# LICENSE: https://github.com/markus-perl/ffmpeg-build-script/blob/master/LICENSE

PROGNAME=$(basename "$0")
VERSION=1.22
VERSION=1.22.rc1
CWD=$(pwd)
PACKAGES="$CWD/packages"
WORKSPACE="$CWD/workspace"
Expand All @@ -22,19 +22,33 @@ if [[ ("$(uname -m)" == "arm64") && ("$OSTYPE" == "darwin"*) ]]; then
MACOS_M1=true
fi

is_mac () {
if [[ "$OSTYPE" == "darwin"* ]]; then
return 0
fi

return 1
}

# read by gcc and cmake
# https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_DEPLOYMENT_TARGET.html
export MACOSX_DEPLOYMENT_TARGET=10.11

# Speed up the process
# Env Var NUMJOBS overrides automatic detection
if [[ -n "$NUMJOBS" ]]; then
MJOBS="$NUMJOBS"
elif [[ -f /proc/cpuinfo ]]; then
MJOBS=$(grep -c processor /proc/cpuinfo)
elif [[ "$OSTYPE" == "darwin"* ]]; then
elif is_mac; then
MJOBS=$(sysctl -n machdep.cpu.thread_count)
CONFIGURE_OPTIONS=("--enable-videotoolbox")
else
MJOBS=4
fi

CONFIGURE_OPTIONS+=("--extra-version=beamcube")

make_dir() {
remove_dir "$1"
if ! mkdir "$1"; then
Expand Down Expand Up @@ -151,6 +165,13 @@ library_exists() {
return 0
}

set_mac_install_name () {
local name="${2:-$1}"
if is_mac; then
execute install_name_tool -id "${WORKSPACE}/lib/$name" $1
fi
}

build_done() {
touch "$PACKAGES/$1.done"
}
Expand Down Expand Up @@ -206,7 +227,7 @@ while (($# > 0)); do
cleanup
fi
if [[ "$1" == "--full-static" || "$1" =~ 'f' ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
if is_mac; then
echo "Error: A full static binary can only be build on Linux."
exit 1
fi
Expand Down Expand Up @@ -383,6 +404,11 @@ if build "openssl"; then
fi
CONFIGURE_OPTIONS+=("--enable-openssl")

if build "meson"; then
execute pip3 install install meson ninja
build_done "meson"
fi

if build "cmake"; then
download "https://cmake.org/files/v3.18/cmake-3.18.4.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --system-zlib
Expand Down Expand Up @@ -444,7 +470,7 @@ CONFIGURE_OPTIONS+=("--enable-libx265")
if build "libvpx"; then
download "https://github.com/webmproject/libvpx/archive/v1.9.0.tar.gz" "libvpx-1.9.0.tar.gz"

if [[ "$OSTYPE" == "darwin"* ]]; then
if is_mac; then
echo "Applying Darwin patch"
sed "s/,--version-script//g" build/make/Makefile >build/make/Makefile.patched
sed "s/-Wl,--no-undefined -Wl,-soname/-Wl,-undefined,error -Wl,-install_name/g" build/make/Makefile.patched >build/make/Makefile
Expand Down Expand Up @@ -494,6 +520,16 @@ if build "vid_stab"; then
fi
CONFIGURE_OPTIONS+=("--enable-libvidstab")

if build "twolame"; then
download "https://downloads.sourceforge.net/twolame/twolame-0.4.0.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --enable-static --disable-shared
execute make -j $MJOBS
execute make install

build_done "twolame"
fi
CONFIGURE_OPTIONS+=("--enable-libtwolame")

if build "av1"; then
download "https://aomedia.googlesource.com/aom/+archive/b52ee6d44adaef8a08f6984390de050d64df9faa.tar.gz" "av1.tar.gz" "av1"
make_dir "$PACKAGES"/aom_build
Expand All @@ -510,6 +546,29 @@ if build "av1"; then
fi
CONFIGURE_OPTIONS+=("--enable-libaom")

if build "dav1d"; then
download "https://code.videolan.org/videolan/dav1d/-/archive/0.7.1/dav1d-0.7.1.tar.gz"
make_dir "$PACKAGES"/dav1d_build
cd "$PACKAGES"/dav1d_build || exit
execute meson --prefix="${WORKSPACE}" --libdir="${WORKSPACE}/lib" --default-library=static ../dav1d-0.7.1
execute ninja
execute ninja install

build_done "dav1d"
fi
CONFIGURE_OPTIONS+=("--enable-libdav1d")

if build "zimg"; then
download "https://github.com/sekrit-twc/zimg/archive/release-3.0.1.tar.gz"
execute autoreconf -i
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install

build_done "zimg"
fi
CONFIGURE_OPTIONS+=("--enable-libzimg")

##
## audio library
##
Expand Down Expand Up @@ -585,6 +644,39 @@ if build "fdk_aac"; then
fi
CONFIGURE_OPTIONS+=("--enable-libfdk-aac")

if build "shine"; then
download "https://github.com/toots/shine/archive/3.1.1.tar.gz" "shine-3.1.1.tar.gz"
execute autoreconf -i
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install

build_done "shine"
fi
CONFIGURE_OPTIONS+=("--enable-libshine")

if build "soxr"; then
download "http://ftp.debian.org/debian/pool/main/libs/libsoxr/libsoxr_0.1.3.orig.tar.xz" "soxr-0.1.3.tar.xz"
make_dir build
cd build || exit
execute cmake .. -DWITH_OPENMP:BOOL=OFF -Wno-dev -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS:BOOL=OFF
execute make -j $MJOBS
execute make install

build_done "soxr"
fi
CONFIGURE_OPTIONS+=("--enable-libsoxr")

if build "speex"; then
download "http://downloads.us.xiph.org/releases/speex/speex-1.2.0.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install

build_done "speex"
fi
CONFIGURE_OPTIONS+=("--enable-libspeex")

##
## image library
##
Expand All @@ -601,6 +693,18 @@ if build "libwebp"; then
fi
CONFIGURE_OPTIONS+=("--enable-libwebp")

if build "openjpeg"; then
download "https://github.com/uclouvain/openjpeg/archive/v2.3.1.tar.gz" "openjpeg-v2.3.1.tar.gz"
make_dir build
cd build || exit
execute cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DBUILD_SHARED_LIBS:bool=OFF
execute make -j $MJOBS
execute make install

build_done "openjpeg"
fi
CONFIGURE_OPTIONS+=("--enable-libopenjpeg")

##
## other library
##
Expand All @@ -614,21 +718,30 @@ if build "libsdl"; then
build_done "libsdl"
fi

if build "srt"; then
download "https://github.com/Haivision/srt/archive/v1.4.1.tar.gz" "srt-1.4.1.tar.gz"
export OPENSSL_ROOT_DIR="${WORKSPACE}"
export OPENSSL_LIB_DIR="${WORKSPACE}"/lib
export OPENSSL_INCLUDE_DIR="${WORKSPACE}"/include/
execute cmake . -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_BINDIR=bin -DCMAKE_INSTALL_INCLUDEDIR=include -DENABLE_SHARED=OFF -DENABLE_STATIC=ON -DENABLE_APPS=OFF -DUSE_STATIC_LIBSTDCXX=ON
execute make install
if build "snappy"; then
download "https://github.com/google/snappy/archive/1.1.8.tar.gz"
make_dir build
cd build || exit
execute cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="${WORKSPACE}" -DBUILD_SHARED_LIBS:bool=OFF
execute make -j $MJOBS

if [ -n "$LDEXEFLAGS" ]; then
sed -i.backup 's/-lgcc_s/-lgcc_eh/g' "${WORKSPACE}"/lib/pkgconfig/srt.pc # The -i.backup is intended and required on MacOS: https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux
fi
set_mac_install_name "libsnappy.1.1.8.dylib" "libsnappy.1.dylib"

execute make install

build_done "srt"
build_done "snappy"
fi
CONFIGURE_OPTIONS+=("--enable-libsnappy")

if build "xz"; then
download "https://tukaani.org/xz/xz-5.2.5.tar.gz"
execute ./configure --prefix="${WORKSPACE}" --disable-shared --enable-static
execute make -j $MJOBS
execute make install

build_done "xz"
fi
CONFIGURE_OPTIONS+=("--enable-libsrt")

##
## HWaccel library
Expand Down Expand Up @@ -681,7 +794,6 @@ download "https://git.ffmpeg.org/gitweb/ffmpeg.git/snapshot/553eb0773763798a6b96
--enable-nonfree \
--enable-pthreads \
--enable-static \
--enable-small \
--enable-version3 \
--extra-cflags="${CFLAGS}" \
--extra-ldexeflags="${LDEXEFLAGS}" \
Expand All @@ -691,11 +803,46 @@ download "https://git.ffmpeg.org/gitweb/ffmpeg.git/snapshot/553eb0773763798a6b96
--pkg-config-flags="--static" \
--prefix="${WORKSPACE}"

if is_mac; then
execute dsymutil libavcodec/libavcodec.dylib -o libavcodec.dSYM
execute dsymutil libavdevice/libavdevice.dylib -o libavdevice.dSYM
execute dsymutil libavfilter/libavfilter.dylib -o libavfilter.dSYM
execute dsymutil libavformat/libavformat.dylib -o libavformat.dSYM
# we're not building this one (libswresample replaces this)
# execute dsymutil libavresample/libavresample.dylib -o libavresample.dSYM
execute dsymutil libavutil/libavutil.dylib -o libavutil.dSYM
execute dsymutil libpostproc/libpostproc.dylib -o libpostproc.dSYM
execute dsymutil libswresample/libswresample.dylib -o libswresample.dSYM
execute dsymutil libswscale/libswscale.dylib -o libswscale.dSYM
fi

if [[ -n "$SENTRY_AUTH_TOKEN" ]] && [[ -n "$SENTRY_ORG" ]] && [[ -n "$SENTRY_PROJECT" ]]; then
# TODO: install sentry-cli when running on CI
# reads SENTRY_AUTH_TOKEN, SENTRY_ORG and SENTRY_PROJECT from env
# https://docs.sentry.io/product/cli/configuration/#configuration-values
sentry-cli upload-dif .
fi

# strip symbols from binaries (i.e., make them smaller)
if is_mac; then
execute strip -x libavcodec/libavcodec.dylib
execute strip -x libavdevice/libavdevice.dylib
execute strip -x libavfilter/libavfilter.dylib
execute strip -x libavformat/libavformat.dylib
execute strip -x libavutil/libavutil.dylib
execute strip -x libpostproc/libpostproc.dylib
execute strip -x libswresample/libswresample.dylib
execute strip -x libswscale/libswscale.dylib
execute strip -x ffmpeg
execute strip -x ffprobe
execute strip -x ffplay
fi

execute make -j $MJOBS
execute make install

INSTALL_FOLDER="/usr/bin"
if [[ "$OSTYPE" == "darwin"* ]]; then
if is_mac; then
INSTALL_FOLDER="/usr/local/bin"
fi

Expand Down Expand Up @@ -739,4 +886,11 @@ elif [[ ! "$SKIPINSTALL" == "yes" ]]; then
esac
fi

cd $CWD
if is_mac; then
node copy_mac_libs.js
cd "$WORKSPACE/mac"
execute zip --symlinks -r "ffmpeg-ffprobe-shared-darwin-x86_64.${VERSION}.zip" *
fi

exit 0
4 changes: 2 additions & 2 deletions full-static.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility,video

RUN apt-get update \
&& apt-get -y --no-install-recommends install build-essential curl ca-certificates python \
&& apt-get -y --no-install-recommends install build-essential curl ca-certificates python python3 python3-pip autoconf autotools-dev automake libtool meson \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* \
&& update-ca-certificates

Expand All @@ -30,4 +30,4 @@ COPY --from=build /app/workspace/bin/ffprobe /ffprobe
COPY --from=build /app/workspace/bin/ffplay /ffplay

CMD ["--help"]
ENTRYPOINT ["/ffmpeg"]
ENTRYPOINT ["/ffmpeg"]
17 changes: 17 additions & 0 deletions publish-to-s3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

if [ $# -ne 3 ]; then
echo "Required arguments: BUCKET PLATFORM ARCH"
exit 1
fi

BUCKET=$1
PLATFORM=$2
ARCH=$3

# rename the ffmpeg/ffprobe files
cp build/ffmpeg "build/ffmpeg-$PLATFORM-$ARCH"
cp build/ffprobe "build/ffprobe-$PLATFORM-$ARCH"

# upload to s3
s3cmd put "build/ffmpeg-$PLATFORM-$ARCH" "build/ffprobe-$PLATFORM-$ARCH" "s3://$BUCKET/"