Skip to content

Commit

Permalink
update ffmpeg and other native dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
barsoosayque committed Oct 12, 2022
1 parent 7f5d841 commit 8466702
Show file tree
Hide file tree
Showing 21 changed files with 95 additions and 68 deletions.
155 changes: 91 additions & 64 deletions library/build_ffmpeg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# =============== Build definitions ===============

CORES=4
CORES=12
MAKE="make -j$CORES"

HOST_NAME=$(uname -s | tr '[:upper:]' '[:lower:]')
Expand All @@ -24,17 +24,17 @@ ABI_FILTERS="x86 x86_64 armeabi-v7a arm64-v8a"
# android.defaultConfig.minSdkVersion
MIN_SDK_VERSION="16"

TOOLCHAIN_VERSION="33"

# Flags
FFMPEG_FLAGS="
--enable-cross-compile
--target-os=android
--pkg-config-flags=--static
--pkg-config=pkgconf
--pkg-config=pkg-config
--disable-postproc
--disable-debug
--enable-hardcoded-tables
--enable-version3
--enable-x86asm
--enable-nonfree
--enable-shared
Expand All @@ -50,6 +50,7 @@ FFMPEG_FLAGS="
--disable-pthreads
--disable-programs
--disable-zlib
--disable-autodetect
--enable-swresample
--enable-avformat
--enable-avcodec
Expand Down Expand Up @@ -79,14 +80,17 @@ while [[ $# -gt 0 ]]; do
case "$1" in
--help|-h)
echo "build_ffmpeg.sh -- script to build shared ffmpeg libraries for android with support for mp3, wav and ogg."
echo "usage: build_ffmpeg.sh (--ndk-dir <NDK_DIR>) (-h|--help) (--update) (--clear) (--ffmpeg-only) (--init)"
echo "usage: build_ffmpeg.sh (--ndk-dir <NDK_DIR>) (--toolchain-version <VERSION>) (--abi <$ABI_FILTERS>)"
echo " (-h|--help) (--update) (--clear) (--ffmpeg-only) (--init)"
echo "options:"
echo " -h, --help: print this message and exit."
echo " --ndk-dir <NDK_DIR>: uses toolchain from provided ndk directory (or env var NDK_DIR otherwise)"
echo " --update: copy built libraries to ./libs (this option assume that the library is built)."
echo " --clear: clear build and temporary directories and exit."
echo " --ffmpeg-only: only build ffmpeg (assuming that dependencies already built)"
echo " --init: configure ffmpeg and generate required files (this implies --ffmpeg-only)"
echo " -h, --help: print this message and exit."
echo " --ndk-dir <NDK_DIR>: uses toolchain from provided ndk directory (or env var NDK_DIR otherwise)"
echo " --toolchain-version <VERSION>: uses this exact numeric NDK toolchain version"
echo " --abi <ABI>: build only selected ABI"
echo " --update: copsy built libraries to ./libs (thi option assume that the library is built)."
echo " --clear: clear build and temporary directories and exit."
echo " --ffmpeg-only: only build ffmpeg (assuming that dependencies already built)"
echo " --init: configure ffmpeg and generate required files (this implies --ffmpeg-only)"
exit 0
;;
--update)
Expand All @@ -103,10 +107,11 @@ while [[ $# -gt 0 ]]; do
rm -r "$LIBOGG_ROOT"
rm -r "$LIBWAVPACK_ROOT"
rm -r "$LIBVORBIS_ROOT"
(cd "$FFMPEG_ROOT" && $MAKE clean)
exit 0
;;
--init)
INIT_ONLY=1
MAKE="echo"
FFMPEG_ONLY=1
;;
--ffmpeg-only)
Expand All @@ -116,6 +121,14 @@ while [[ $# -gt 0 ]]; do
NDK_DIR="$2"
shift
;;
--toolchain-version)
TOOLCHAIN_VERSION="$2"
shift
;;
--abi)
ABI_FILTERS="$2"
shift
;;
esac
shift
done
Expand All @@ -130,64 +143,67 @@ TOOLCHAIN="$NDK_DIR/toolchains/llvm/prebuilt/$HOST_TAG"

# =============== Actual build ===============

if [ -z "INIT_ONLY" ]; then
echo "*************** Prepare dependepcies ***************"
if [ -z "$INIT_ONLY" ]; then
echo "========== Prepare dependepcies =========="

mkdir -p "$BUILD_ROOT"

if [ ! -e $LIBMP3LAME_ROOT ]; then
curl -L "https://netcologne.dl.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz" | tar xz
mv lame-3.100 "$LIBMP3LAME_ROOT"
echo "Downloading LIBMP3LAME:"
curl -L "https://altushost-swe.dl.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz" | tar xz
mv lame-3.100 "$LIBMP3LAME_ROOT"
fi

if [ ! -e $LIBOGG_ROOT ]; then
curl -L "http://downloads.xiph.org/releases/ogg/libogg-1.3.4.tar.gz" | tar xz
mv libogg-1.3.4 "$LIBOGG_ROOT"
echo "Downloading LIBOGG:"
curl -L "http://downloads.xiph.org/releases/ogg/libogg-1.3.4.tar.gz" | tar xz
mv libogg-1.3.4 "$LIBOGG_ROOT"
fi

if [ ! -e $LIBVORBIS_ROOT ]; then
curl -L "http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz" | tar xz
mv libvorbis-1.3.5 "$LIBVORBIS_ROOT"
patch $LIBVORBIS_ROOT/configure < dependencies/libvorbis-clang.patch
echo "Downloading LIBVORBIS:"
curl -L "http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz" | tar xz
mv libvorbis-1.3.5 "$LIBVORBIS_ROOT"
patch $LIBVORBIS_ROOT/configure < dependencies/libvorbis-clang.patch
fi

if [ ! -e $LIBWAVPACK_ROOT ]; then
curl -L "http://www.wavpack.com/wavpack-5.2.0.tar.xz" | tar xJ
mv wavpack-5.2.0 "$LIBWAVPACK_ROOT"
echo "Downloading LIBWAVPACK:"
curl -L "http://www.wavpack.com/wavpack-5.2.0.tar.xz" | tar xJ
mv wavpack-5.2.0 "$LIBWAVPACK_ROOT"
fi

echo "Dependencies ready."
fi

echo "*************** FFmpeg cross-compilation ***************"
echo "========== FFmpeg cross-compilation =========="
echo "Compiling list: $ABI_FILTERS."
for ABI in $ABI_FILTERS; do
echo "*************** $ABI ***************"
echo "~~~~~~~~~ Compiling $ABI ~~~~~~~~~"
CFLAGS="-O3"
LDFLAGS="-lm"
ABI_FLAGS=""
case $ABI in
x86)
ARCH=x86
TOOLCHAIN_DIR="$TOOLCHAIN/i686-linux-android"
TOOLCHAIN_PREFIX="i686-linux-android"
ABI_FLAGS="--disable-asm"
CPU="i686"
CFLAGS="$CFLAGS -march=i686"
;;
x86_64)
ARCH=x86_64
TOOLCHAIN_DIR="$TOOLCHAIN/x86_64-linux-android"
TOOLCHAIN_PREFIX="x86_64-linux-android"
CPU="x86_64"
ABI_FLAGS="--disable-x86asm"
;;
armeabi-v7a)
ARCH=arm
TOOLCHAIN_DIR="$TOOLCHAIN/arm-linux-androideabi"
TOOLCHAIN_PREFIX="arm-linux-androideabi"
CPU="armv7a"
;;
arm64-v8a)
ARCH=aarch64
TOOLCHAIN_DIR="$TOOLCHAIN/aarch64-linux-android"
TOOLCHAIN_PREFIX="aarch64-linux-android"
#LDFLAGS="-fuse-ld=gold "
CPU="generic"
Expand All @@ -196,64 +212,72 @@ for ABI in $ABI_FILTERS; do

case $ARCH in
arm)
CC="armv7a-linux-androideabi$MIN_SDK_VERSION-clang"
CC="armv7a-linux-androideabi$TOOLCHAIN_VERSION-clang"
;;
*64)
CC="${TOOLCHAIN_PREFIX}21-clang"
CC="$TOOLCHAIN_PREFIX$TOOLCHAIN_VERSION-clang"
;;
*)
CC="$TOOLCHAIN_PREFIX$MIN_SDK_VERSION-clang"
CC="$TOOLCHAIN_PREFIX$TOOLCHAIN_VERSION-clang"
;;
esac

export AR=$TOOLCHAIN/bin/$TOOLCHAIN_PREFIX-ar
export AS=$TOOLCHAIN/bin/$TOOLCHAIN_PREFIX-as
export AR=$TOOLCHAIN/bin/llvm-ar
export AS=$TOOLCHAIN/bin/llvm-as
export CC=$TOOLCHAIN/bin/$CC
export CXX=$CC++
export LD=$CC
export RANLIB=$TOOLCHAIN/bin/$TOOLCHAIN_PREFIX-ranlib
export STRIP=$TOOLCHAIN/bin/$TOOLCHAIN_PREFIX-strip
export NM=$TOOLCHAIN/bin/$TOOLCHAIN_PREFIX-nm
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip
export NM=$TOOLCHAIN/bin/llvm-nm

export PKG_CONFIG_PATH=$BUILD_ROOT/$ABI/lib/pkgconfig

export TOOLCHAIN=$TOOLCHAIN
export TARGET=$TOOLCHAIN_PREFIX
export API=$MIN_SDK_VERSION

AUTOCONF_CROSS_FLAGS="
--quiet
--host=$TARGET
--disable-shared
--enable-static
--disable-frontend
--disable-docs
--disable-examples
--disable-encoder
--prefix=$BUILD_ROOT/$ABI
"
# --with-sysroot=$TOOLCHAIN/sysroot

if [ -z "$INIT_ONLY" ]; then
BUILD_CMD="$MAKE clean && $MAKE && $MAKE install"
else
BUILD_CMD=":"
fi


if [ -z "$FFMPEG_ONLY" ]; then
echo "Cross-compile autoconf env:"
echo "AR=$AR"
echo "AS=$AS"
echo "CC=$CC"
echo "CXX=$CXX"
echo "LD=$LD"
echo "RANLIB=$RANLIB"
echo "STRIP=$STRIP"
echo "NM=$NM"
echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH"
echo "TOOLCHAIN=$TOOLCHAIN"
echo "TARGET=$TARGET"
echo "API=$API"
echo "============================"

AUTOCONF_CROSS_FLAGS="
--quiet
--host=$TARGET
--disable-shared
--enable-static
--disable-frontend
--disable-docs
--disable-examples
--disable-encoder
--prefix=$BUILD_ROOT/$ABI
"

echo "[1/5] Build $ABI libmp3lame..."
(cd $LIBMP3LAME_ROOT && ./configure $AUTOCONF_CROSS_FLAGS && $BUILD_CMD)
(cd $LIBMP3LAME_ROOT && ./configure $AUTOCONF_CROSS_FLAGS && $MAKE clean && $MAKE install)

echo "[2/5] Build $ABI libogg..."
(cd $LIBOGG_ROOT && ./configure $AUTOCONF_CROSS_FLAGS && $BUILD_CMD)
(cd $LIBOGG_ROOT && ./configure $AUTOCONF_CROSS_FLAGS && $MAKE clean && $MAKE install)

echo "[3/5] Build $ABI libvorbis..."
LIBVORBIS_FLAGS="
--disable-oggtest
CFLAGS=-I$BUILD_ROOT/$ABI/include
LDFLAGS=-L$BUILD_ROOT/$ABI/lib
"
(cd $LIBVORBIS_ROOT && ./configure $AUTOCONF_CROSS_FLAGS $LIBVORBIS_FLAGS && $BUILD_CMD)
(cd $LIBVORBIS_ROOT && ./configure $AUTOCONF_CROSS_FLAGS $LIBVORBIS_FLAGS && $MAKE clean && $MAKE install)

echo "[4/5] Build $ABI libwavpack..."
LIBWAVPACK_FLAGS="
Expand All @@ -262,7 +286,7 @@ for ABI in $ABI_FILTERS; do
--disable-dsd
--enable-legacy
"
(cd $LIBWAVPACK_ROOT && ./configure $AUTOCONF_CROSS_FLAGS $LIBWAVPACK_FLAGS && $BUILD_CMD)
(cd $LIBWAVPACK_ROOT && ./configure $AUTOCONF_CROSS_FLAGS $LIBWAVPACK_FLAGS && $MAKE clean && $MAKE install)

echo "[5/5] Build $ABI ffmpeg..."
else
Expand All @@ -273,7 +297,7 @@ for ABI in $ABI_FILTERS; do
$ABI_FLAGS
--cpu=$CPU
--cc=$CC
--cxx=$XX
--cxx=$CXX
--ld=$LD
--ar=$AR
--as=$CC
Expand All @@ -284,8 +308,11 @@ for ABI in $ABI_FILTERS; do
--sysroot=$TOOLCHAIN/sysroot
--prefix=$BUILD_ROOT/$ABI
--cross-prefix=$TOOLCHAIN/bin/$TOOLCHAIN_PREFIX-
--env=PKG_CONFIG_PATH=$BUILD_ROOT/$ABI/lib/pkgconfig
--env=PKG_CONFIG_PATH=\"$BUILD_ROOT/$ABI/lib/pkgconfig\"
"
echo "ABI flags:$ABI_FLAGS"
echo "FFMPEG flags:$FFMPEG_FLAGS"

CFLAGS="$CFLAGS -I$BUILD_ROOT/$ABI/include"
LDFLAGS="$LDFLAGS -L$BUILD_ROOT/$ABI/lib"
(cd "$FFMPEG_ROOT" && \
Expand All @@ -294,5 +321,5 @@ for ABI in $ABI_FILTERS; do
--extra-ldflags="$LDFLAGS" \
$FFMPEG_FLAGS \
$ABI_FLAGS \
&& $BUILD_CMD)
&& $MAKE clean && $MAKE install)
done
2 changes: 1 addition & 1 deletion library/dependencies/ffmpeg
Submodule ffmpeg updated from 287620 to ba3074
2 changes: 1 addition & 1 deletion library/dependencies/fmt
Submodule fmt updated 141 files
2 changes: 1 addition & 1 deletion library/dependencies/libsamplerate
2 changes: 1 addition & 1 deletion library/dependencies/oboe
Submodule oboe updated 523 files
Binary file modified library/libs/arm64-v8a/libavcodec.so
Binary file not shown.
Binary file modified library/libs/arm64-v8a/libavformat.so
Binary file not shown.
Binary file modified library/libs/arm64-v8a/libavutil.so
Binary file not shown.
Binary file modified library/libs/arm64-v8a/libswresample.so
Binary file not shown.
Binary file modified library/libs/armeabi-v7a/libavcodec.so
Binary file not shown.
Binary file modified library/libs/armeabi-v7a/libavformat.so
Binary file not shown.
Binary file modified library/libs/armeabi-v7a/libavutil.so
Binary file not shown.
Binary file modified library/libs/armeabi-v7a/libswresample.so
Binary file not shown.
Binary file modified library/libs/x86/libavcodec.so
Binary file not shown.
Binary file modified library/libs/x86/libavformat.so
Binary file not shown.
Binary file modified library/libs/x86/libavutil.so
Binary file not shown.
Binary file modified library/libs/x86/libswresample.so
Binary file not shown.
Binary file modified library/libs/x86_64/libavcodec.so
Binary file not shown.
Binary file modified library/libs/x86_64/libavformat.so
Binary file not shown.
Binary file modified library/libs/x86_64/libavutil.so
Binary file not shown.
Binary file modified library/libs/x86_64/libswresample.so
Binary file not shown.

0 comments on commit 8466702

Please sign in to comment.