Files
mobile-ffmpeg/android.sh
T
Taner Şener 4f6e484d5b merge v4.4 to master (#503)
* cleanup openh264 build

* apply 'use build host and target host in build scripts' efe1c59a

* remove custom common_includes

The includes are handled by llvm via --sysroot parameter.

* remove unnecessary parameters for make command

using the names of compiler tools same way as they are used (without full path) for ffmpeg build

* let AndroidStudio manage project root

* import cpufeatures from NDK

* Enable stale action

* Use JSON parsing in getMediaInformation, fixes #417

* Remove internal log line limit on Android, fixes #418

* add support for vo-amrwbenc, fixes #381

* Enable all gpl libraries when both --full and --enable-gpl flags are present, fixes #394

* let the project be opened and managed in Android Studio

* bring in cpu_features as a submodule

* add cpu_features script

and some helper fuctions to android-common

* fix lint errors

* use cpu_features script

it's a regular library, only it's enabled by default

* import cpu_features into Android.mk

also clean up the Android.mk files a bit
also, import libc++_shared correctly, so that it is packed in AAR

* fix Android.lts.mk

* with NDK r20 and higher, openh264.a does not depend on libc++

* Revert "with NDK r20 and higher, openh264.a does not depend on libc++"

This reverts commit dc751016

* Revert a (small) portion of commit e77f8971

On lower API, openh264 depends on libc++_shared. Here, for simplicity, we force this dependency for all API levels.

* LTS: fix the static constructor blocks to handle the changed name of the cpu features library

Also, add ffmpeg dependencies for lower APIs (how did it work before?)
Also, just try to load c++_shared if it is present, not trying to guess whether the external libraries require it (android.sh will still make the decision to add c++_shared to dependencies list based on the list of external libraries).

* switch the submodule to fork

* rename the submodule library

* scripts changed for renamed libary and move cpu-features to slot 47

create_cpufeatures_package_config moved back to android-common.sh
android_ndk_cmake to handle generic Android-NDK toolchain invocation of cmake

* update the Android.mk files to reflect cpu-features rename

also, remove unnecessary dependencies

* fix for LTS

* not needed anymore

* revert the commit 740fd2e9

load of c++_shared determined by the list of enabled external libraries

* Using static lib for Google cpu-features

* let openh264 work with external cpu-features

compatible with NDK deperecated implementation and with ndk_compat from https://github.com/google/cpu_features

* set packages path

* make android-cpu-features.sh executable

* automatically update submodules from android.sh

* disable publishing to bintray

* bump version

* list cpu-features after builtin libraries

* fix javadoc warnings

* disable stripping of debug symbols for ffmpeg, fixes #447

* do not detach main thread on error cases, fixes #446

* release unreleased utf strings in setNativeEnvironmentVariable(), fixes #443

* implement toString() method for Statistics and LogMessage classes, fixes #438

* do not install lldb for android in travis builds

* fix travis builds

* remove unused test resources

* switch src/cpu-features remote to google/cpu_features

* switch expat source code with expat submodule

* update submodules in top level build scripts

* switch openh264 source code with openh264 submodule

* implement bash functions to download external libraries

* implement ignoreSignal api method, fixes #258, #214

* use the latest android ndk

* disable avfoundation device for ios lts releases, fixes #462

* update ios test-app versions

* implement an api method to set environment variables, fixes #466

* update release scripts to use the latest ndk version

* update stale.yml

* implement ffmpeg async api

* add executionId to log and statistic callbacks

* fix ndk version in travis

* fix test commands in android test app

* fix android env variables  in travis

* switch to personal fork for cpu-features, use in-repo sources for expat and openh264

* introduce an api method to list ongoing executions

* use a thread safe implementation to list ongoing executions

* add startTime to FFmpegExecution class

* test openh264 in ios/tvos test applications

* use new x265 version v3.4

* use new x264 version v20200630-stable

* use new chromaprint version v1.5.0

* use new wavpack version v5.3.0

* use new kvazaar version v2.0.0

* use new libvorbis version v1.3.7

* use new nettle version v3.6

* use new libjpeg-turbo version v2.0.5

* use new ffmpeg version v4.4-dev-416-g1998d1d6af

* remove coreimage references on ios/tvos, fixes #480

* use new freetype version 2.10.2

* enable redownloading of ffmpeg source code

* freeze v4.4

* disable building of audiotoolbox output device on ios/tvos

* do not process log lines with zero length on ios/tvos

* update libsamplerate build workarounds

* do not print parsing exceptions for not found keys on android

* synchronize updating lastCommandOutput on ios/tvos, fixes #494

* introduce execution specific log levels, fixes #495

* fix x265 compilation errors on ios/tvos

* fix android lts neon packaging

* fix processing of ios/tvos flags

* fix mobile-ffmpeg videotoolbox flags for tvos

* release v4.4.LTS

* use v4.4.LTS in test applications

* fix ios/tvos system library indexes in ffmpeg build scripts

* update ios test-app settings

* fix android release packaging script

* Update README

Co-authored-by: alexcohn <sasha.cohn@gmail.com>
2020-07-29 21:28:04 +01:00

901 lines
24 KiB
Bash
Executable File

#!/bin/bash
# ARCH INDEXES
ARCH_ARM_V7A=0
ARCH_ARM_V7A_NEON=1
ARCH_ARM64_V8A=2
ARCH_X86=3
ARCH_X86_64=4
# LIBRARY INDEXES
LIBRARY_FONTCONFIG=0
LIBRARY_FREETYPE=1
LIBRARY_FRIBIDI=2
LIBRARY_GMP=3
LIBRARY_GNUTLS=4
LIBRARY_LAME=5
LIBRARY_LIBASS=6
LIBRARY_LIBICONV=7
LIBRARY_LIBTHEORA=8
LIBRARY_LIBVORBIS=9
LIBRARY_LIBVPX=10
LIBRARY_LIBWEBP=11
LIBRARY_LIBXML2=12
LIBRARY_OPENCOREAMR=13
LIBRARY_SHINE=14
LIBRARY_SPEEX=15
LIBRARY_WAVPACK=16
LIBRARY_KVAZAAR=17
LIBRARY_X264=18
LIBRARY_XVIDCORE=19
LIBRARY_X265=20
LIBRARY_LIBVIDSTAB=21
LIBRARY_RUBBERBAND=22
LIBRARY_LIBILBC=23
LIBRARY_OPUS=24
LIBRARY_SNAPPY=25
LIBRARY_SOXR=26
LIBRARY_LIBAOM=27
LIBRARY_CHROMAPRINT=28
LIBRARY_TWOLAME=29
LIBRARY_SDL=30
LIBRARY_TESSERACT=31
LIBRARY_OPENH264=32
LIBRARY_VO_AMRWBENC=33
LIBRARY_GIFLIB=34
LIBRARY_JPEG=35
LIBRARY_LIBOGG=36
LIBRARY_LIBPNG=37
LIBRARY_LIBUUID=38
LIBRARY_NETTLE=39
LIBRARY_TIFF=40
LIBRARY_EXPAT=41
LIBRARY_SNDFILE=42
LIBRARY_LEPTONICA=43
LIBRARY_LIBSAMPLERATE=44
LIBRARY_ZLIB=45
LIBRARY_MEDIA_CODEC=46
LIBRARY_CPU_FEATURES=47
# ENABLE ARCH
ENABLED_ARCHITECTURES=(1 1 1 1 1)
# ENABLE LIBRARIES
ENABLED_LIBRARIES=(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1)
export BASEDIR=$(pwd)
# USING API LEVEL 24 / Android 7.0 (NOUGAT)
export API=24
RECONF_LIBRARIES=()
REBUILD_LIBRARIES=()
REDOWNLOAD_LIBRARIES=()
get_mobile_ffmpeg_version() {
local MOBILE_FFMPEG_VERSION=$(grep '#define MOBILE_FFMPEG_VERSION' ${BASEDIR}/android/app/src/main/cpp/mobileffmpeg.h | grep -Eo '\".*\"' | sed -e 's/\"//g')
echo ${MOBILE_FFMPEG_VERSION}
}
display_help() {
COMMAND=$(echo $0 | sed -e 's/\.\///g')
echo -e "\n'"$COMMAND"' builds FFmpeg and MobileFFmpeg for Android platform. By default five Android ABIs (armeabi-v7a, armeabi-v7a-neon, arm64-v8a, x86 and x86_64) are built \
without any external libraries enabled. Options can be used to disable ABIs and/or enable external libraries. \
Please note that GPL libraries (external libraries with GPL license) need --enable-gpl flag to be set explicitly. \
When compilation ends an Android Archive (AAR) file is created under the prebuilt folder.\n"
echo -e "Usage: ./"$COMMAND" [OPTION]...\n"
echo -e "Specify environment variables as VARIABLE=VALUE to override default build options.\n"
echo -e "Options:"
echo -e " -h, --help\t\t\tdisplay this help and exit"
echo -e " -v, --version\t\t\tdisplay version information and exit"
echo -e " -d, --debug\t\t\tbuild with debug information"
echo -e " -s, --speed\t\t\toptimize for speed instead of size"
echo -e " -l, --lts\t\t\tbuild lts packages to support API 16+ devices"
echo -e " -f, --force\t\t\tignore warnings\n"
echo -e "Licensing options:"
echo -e " --enable-gpl\t\t\tallow use of GPL libraries, created libs will be licensed under GPLv3.0 [no]\n"
echo -e "Platforms:"
echo -e " --disable-arm-v7a\t\tdo not build arm-v7a platform [yes]"
echo -e " --disable-arm-v7a-neon\tdo not build arm-v7a-neon platform [yes]"
echo -e " --disable-arm64-v8a\t\tdo not build arm64-v8a platform [yes]"
echo -e " --disable-x86\t\t\tdo not build x86 platform [yes]"
echo -e " --disable-x86-64\t\tdo not build x86-64 platform [yes]\n"
echo -e "Libraries:"
echo -e " --full\t\t\tenables all external libraries"
echo -e " --enable-android-media-codec\tbuild with built-in Android MediaCodec support[no]"
echo -e " --enable-android-zlib\t\tbuild with built-in zlib support[no]"
echo -e " --enable-chromaprint\t\tbuild with chromaprint [no]"
echo -e " --enable-fontconfig\t\tbuild with fontconfig [no]"
echo -e " --enable-freetype\t\tbuild with freetype [no]"
echo -e " --enable-fribidi\t\tbuild with fribidi [no]"
echo -e " --enable-gmp\t\t\tbuild with gmp [no]"
echo -e " --enable-gnutls\t\tbuild with gnutls [no]"
echo -e " --enable-kvazaar\t\tbuild with kvazaar [no]"
echo -e " --enable-lame\t\t\tbuild with lame [no]"
echo -e " --enable-libaom\t\tbuild with libaom [no]"
echo -e " --enable-libass\t\tbuild with libass [no]"
echo -e " --enable-libiconv\t\tbuild with libiconv [no]"
echo -e " --enable-libilbc\t\tbuild with libilbc [no]"
echo -e " --enable-libtheora\t\tbuild with libtheora [no]"
echo -e " --enable-libvorbis\t\tbuild with libvorbis [no]"
echo -e " --enable-libvpx\t\tbuild with libvpx [no]"
echo -e " --enable-libwebp\t\tbuild with libwebp [no]"
echo -e " --enable-libxml2\t\tbuild with libxml2 [no]"
echo -e " --enable-opencore-amr\t\tbuild with opencore-amr [no]"
echo -e " --enable-openh264\t\tbuild with openh264 [no]"
echo -e " --enable-opus\t\t\tbuild with opus [no]"
echo -e " --enable-sdl\t\t\tbuild with sdl [no]"
echo -e " --enable-shine\t\tbuild with shine [no]"
echo -e " --enable-snappy\t\tbuild with snappy [no]"
echo -e " --enable-soxr\t\t\tbuild with soxr [no]"
echo -e " --enable-speex\t\tbuild with speex [no]"
echo -e " --enable-tesseract\t\tbuild with tesseract [no]"
echo -e " --enable-twolame\t\tbuild with twolame [no]"
echo -e " --enable-vo-amrwbenc\t\tbuild with vo-amrwbenc [no]"
echo -e " --enable-wavpack\t\tbuild with wavpack [no]\n"
echo -e "GPL libraries:"
echo -e " --enable-libvidstab\t\tbuild with libvidstab [no]"
echo -e " --enable-rubberband\t\tbuild with rubber band [no]"
echo -e " --enable-x264\t\t\tbuild with x264 [no]"
echo -e " --enable-x265\t\t\tbuild with x265 [no]"
echo -e " --enable-xvidcore\t\tbuild with xvidcore [no]\n"
echo -e "Advanced options:"
echo -e " --reconf-LIBRARY\t\trun autoreconf before building LIBRARY [no]"
echo -e " --redownload-LIBRARY\t\tdownload LIBRARY even it is detected as already downloaded [no]"
echo -e " --rebuild-LIBRARY\t\tbuild LIBRARY even it is detected as already built [no]\n"
}
display_version() {
COMMAND=$(echo $0 | sed -e 's/\.\///g')
echo -e "\
$COMMAND v$(get_mobile_ffmpeg_version)\n\
Copyright (c) 2018 Taner Sener\n\
License LGPLv3.0: GNU LGPL version 3 or later\n\
<https://www.gnu.org/licenses/lgpl-3.0.en.html>\n\
This is free software: you can redistribute it and/or modify it under the terms of the \
GNU Lesser General Public License as published by the Free Software Foundation, \
either version 3 of the License, or (at your option) any later version."
}
skip_library() {
SKIP_VARIABLE=$(echo "SKIP_$1" | sed "s/\-/\_/g")
export ${SKIP_VARIABLE}=1
}
no_output_redirection() {
export NO_OUTPUT_REDIRECTION=1
}
no_workspace_cleanup_library() {
NO_WORKSPACE_CLEANUP_VARIABLE=$(echo "NO_WORKSPACE_CLEANUP_$1" | sed "s/\-/\_/g")
export ${NO_WORKSPACE_CLEANUP_VARIABLE}=1
}
no_link_time_optimization() {
export NO_LINK_TIME_OPTIMIZATION=1
}
enable_debug() {
export MOBILE_FFMPEG_DEBUG="-g"
BUILD_TYPE_ID+="debug "
}
optimize_for_speed() {
export MOBILE_FFMPEG_OPTIMIZED_FOR_SPEED="1"
}
enable_lts_build() {
export MOBILE_FFMPEG_LTS_BUILD="1"
# USING API LEVEL 16 / Android 4.1 (JELLY BEAN)
export API=16
}
reconf_library() {
local RECONF_VARIABLE=$(echo "RECONF_$1" | sed "s/\-/\_/g")
local library_supported=0
for library in {1..45}; do
library_name=$(get_library_name $((library - 1)))
if [[ $1 != "ffmpeg" ]] && [[ ${library_name} == $1 ]]; then
export ${RECONF_VARIABLE}=1
RECONF_LIBRARIES+=($1)
library_supported=1
fi
done
if [[ ${library_supported} -eq 0 ]]; then
echo -e "INFO: --reconf flag detected for library $1 is not supported.\n" 1>>${BASEDIR}/build.log 2>&1
fi
}
rebuild_library() {
local REBUILD_VARIABLE=$(echo "REBUILD_$1" | sed "s/\-/\_/g")
local library_supported=0
for library in {0..47}; do
library_name=$(get_library_name ${library})
if [[ $1 != "ffmpeg" ]] && [[ ${library_name} == $1 ]]; then
export ${REBUILD_VARIABLE}=1
REBUILD_LIBRARIES+=($1)
library_supported=1
fi
done
if [[ ${library_supported} -eq 0 ]]; then
echo -e "INFO: --rebuild flag detected for library $1 is not supported.\n" 1>>${BASEDIR}/build.log 2>&1
fi
}
redownload_library() {
local REDOWNLOAD_VARIABLE=$(echo "REDOWNLOAD_$1" | sed "s/\-/\_/g")
local library_supported=0
for library in {0..47}; do
library_name=$(get_library_name ${library})
if [[ ${library_name} == $1 ]]; then
export ${REDOWNLOAD_VARIABLE}=1
REDOWNLOAD_LIBRARIES+=($1)
library_supported=1
fi
done
if [[ "ffmpeg" == $1 ]]; then
export ${REDOWNLOAD_VARIABLE}=1
REDOWNLOAD_LIBRARIES+=($1)
library_supported=1
fi
if [[ ${library_supported} -eq 0 ]]; then
echo -e "INFO: --redownload flag detected for library $1 is not supported.\n" 1>>${BASEDIR}/build.log 2>&1
fi
}
enable_library() {
set_library $1 1
}
set_library() {
case $1 in
android-media-codec)
ENABLED_LIBRARIES[LIBRARY_MEDIA_CODEC]=$2
;;
android-zlib)
ENABLED_LIBRARIES[LIBRARY_ZLIB]=$2
;;
chromaprint)
ENABLED_LIBRARIES[LIBRARY_CHROMAPRINT]=$2
;;
fontconfig)
ENABLED_LIBRARIES[LIBRARY_FONTCONFIG]=$2
ENABLED_LIBRARIES[LIBRARY_LIBUUID]=$2
ENABLED_LIBRARIES[LIBRARY_EXPAT]=$2
ENABLED_LIBRARIES[LIBRARY_LIBICONV]=$2
set_library "freetype" $2
;;
freetype)
ENABLED_LIBRARIES[LIBRARY_FREETYPE]=$2
ENABLED_LIBRARIES[LIBRARY_ZLIB]=$2
set_library "libpng" $2
;;
fribidi)
ENABLED_LIBRARIES[LIBRARY_FRIBIDI]=$2
;;
gmp)
ENABLED_LIBRARIES[LIBRARY_GMP]=$2
;;
gnutls)
ENABLED_LIBRARIES[LIBRARY_GNUTLS]=$2
ENABLED_LIBRARIES[LIBRARY_ZLIB]=$2
set_library "nettle" $2
set_library "gmp" $2
set_library "libiconv" $2
;;
kvazaar)
ENABLED_LIBRARIES[LIBRARY_KVAZAAR]=$2
;;
lame)
ENABLED_LIBRARIES[LIBRARY_LAME]=$2
set_library "libiconv" $2
;;
libaom)
ENABLED_LIBRARIES[LIBRARY_LIBAOM]=$2
;;
libass)
ENABLED_LIBRARIES[LIBRARY_LIBASS]=$2
ENABLED_LIBRARIES[LIBRARY_LIBUUID]=$2
ENABLED_LIBRARIES[LIBRARY_EXPAT]=$2
set_library "freetype" $2
set_library "fribidi" $2
set_library "fontconfig" $2
set_library "libiconv" $2
;;
libiconv)
ENABLED_LIBRARIES[LIBRARY_LIBICONV]=$2
;;
libilbc)
ENABLED_LIBRARIES[LIBRARY_LIBILBC]=$2
;;
libpng)
ENABLED_LIBRARIES[LIBRARY_LIBPNG]=$2
ENABLED_LIBRARIES[LIBRARY_ZLIB]=$2
;;
libtheora)
ENABLED_LIBRARIES[LIBRARY_LIBTHEORA]=$2
ENABLED_LIBRARIES[LIBRARY_LIBOGG]=$2
set_library "libvorbis" $2
;;
libvidstab)
ENABLED_LIBRARIES[LIBRARY_LIBVIDSTAB]=$2
;;
libvorbis)
ENABLED_LIBRARIES[LIBRARY_LIBVORBIS]=$2
ENABLED_LIBRARIES[LIBRARY_LIBOGG]=$2
;;
libvpx)
ENABLED_LIBRARIES[LIBRARY_LIBVPX]=$2
;;
libwebp)
ENABLED_LIBRARIES[LIBRARY_LIBWEBP]=$2
ENABLED_LIBRARIES[LIBRARY_GIFLIB]=$2
ENABLED_LIBRARIES[LIBRARY_JPEG]=$2
set_library "tiff" $2
set_library "libpng" $2
;;
libxml2)
ENABLED_LIBRARIES[LIBRARY_LIBXML2]=$2
set_library "libiconv" $2
;;
opencore-amr)
ENABLED_LIBRARIES[LIBRARY_OPENCOREAMR]=$2
;;
openh264)
ENABLED_LIBRARIES[LIBRARY_OPENH264]=$2
;;
opus)
ENABLED_LIBRARIES[LIBRARY_OPUS]=$2
;;
rubberband)
ENABLED_LIBRARIES[LIBRARY_RUBBERBAND]=$2
ENABLED_LIBRARIES[LIBRARY_SNDFILE]=$2
ENABLED_LIBRARIES[LIBRARY_LIBSAMPLERATE]=$2
;;
sdl)
ENABLED_LIBRARIES[LIBRARY_SDL]=$2
;;
shine)
ENABLED_LIBRARIES[LIBRARY_SHINE]=$2
;;
snappy)
ENABLED_LIBRARIES[LIBRARY_SNAPPY]=$2
ENABLED_LIBRARIES[LIBRARY_ZLIB]=$2
;;
soxr)
ENABLED_LIBRARIES[LIBRARY_SOXR]=$2
;;
speex)
ENABLED_LIBRARIES[LIBRARY_SPEEX]=$2
;;
tesseract)
ENABLED_LIBRARIES[LIBRARY_TESSERACT]=$2
ENABLED_LIBRARIES[LIBRARY_LEPTONICA]=$2
ENABLED_LIBRARIES[LIBRARY_LIBWEBP]=$2
ENABLED_LIBRARIES[LIBRARY_GIFLIB]=$2
ENABLED_LIBRARIES[LIBRARY_JPEG]=$2
ENABLED_LIBRARIES[LIBRARY_ZLIB]=$2
set_library "tiff" $2
set_library "libpng" $2
;;
twolame)
ENABLED_LIBRARIES[LIBRARY_TWOLAME]=$2
ENABLED_LIBRARIES[LIBRARY_SNDFILE]=$2
;;
vo-amrwbenc)
ENABLED_LIBRARIES[LIBRARY_VO_AMRWBENC]=$2
;;
wavpack)
ENABLED_LIBRARIES[LIBRARY_WAVPACK]=$2
;;
x264)
ENABLED_LIBRARIES[LIBRARY_X264]=$2
;;
x265)
ENABLED_LIBRARIES[LIBRARY_X265]=$2
;;
xvidcore)
ENABLED_LIBRARIES[LIBRARY_XVIDCORE]=$2
;;
expat | giflib | jpeg | leptonica | libogg | libsamplerate | libsndfile | libuuid)
# THESE LIBRARIES ARE NOT ENABLED DIRECTLY
;;
nettle)
ENABLED_LIBRARIES[LIBRARY_NETTLE]=$2
set_library "gmp" $2
;;
tiff)
ENABLED_LIBRARIES[LIBRARY_TIFF]=$2
ENABLED_LIBRARIES[LIBRARY_JPEG]=$2
;;
*)
print_unknown_library $1
;;
esac
}
disable_arch() {
set_arch $1 0
}
set_arch() {
case $1 in
arm-v7a)
ENABLED_ARCHITECTURES[ARCH_ARM_V7A]=$2
;;
arm-v7a-neon)
ENABLED_ARCHITECTURES[ARCH_ARM_V7A_NEON]=$2
;;
arm64-v8a)
ENABLED_ARCHITECTURES[ARCH_ARM64_V8A]=$2
;;
x86)
ENABLED_ARCHITECTURES[ARCH_X86]=$2
;;
x86-64)
ENABLED_ARCHITECTURES[ARCH_X86_64]=$2
;;
*)
print_unknown_platform $1
;;
esac
}
print_unknown_option() {
echo -e "Unknown option \"$1\".\nSee $0 --help for available options."
exit 1
}
print_unknown_library() {
echo -e "Unknown library \"$1\".\nSee $0 --help for available libraries."
exit 1
}
print_unknown_platform() {
echo -e "Unknown platform \"$1\".\nSee $0 --help for available platforms."
exit 1
}
print_enabled_architectures() {
echo -n "Architectures: "
let enabled=0
for print_arch in {0..4}; do
if [[ ${ENABLED_ARCHITECTURES[$print_arch]} -eq 1 ]]; then
if [[ ${enabled} -ge 1 ]]; then
echo -n ", "
fi
echo -n $(get_arch_name $print_arch)
enabled=$((${enabled} + 1))
fi
done
if [ ${enabled} -gt 0 ]; then
echo ""
else
echo "none"
fi
}
print_enabled_libraries() {
echo -n "Libraries: "
let enabled=0
for library in {45..47} {0..33}; do
if [[ ${ENABLED_LIBRARIES[$library]} -eq 1 ]]; then
if [[ ${enabled} -ge 1 ]]; then
echo -n ", "
fi
echo -n $(get_library_name $library)
enabled=$((${enabled} + 1))
fi
done
if [ ${enabled} -gt 0 ]; then
echo ""
else
echo "none"
fi
}
print_reconfigure_requested_libraries() {
local counter=0
for RECONF_LIBRARY in "${RECONF_LIBRARIES[@]}"; do
if [[ ${counter} -eq 0 ]]; then
echo -n "Reconfigure: "
else
echo -n ", "
fi
echo -n ${RECONF_LIBRARY}
counter=$((${counter} + 1))
done
if [[ ${counter} -gt 0 ]]; then
echo ""
fi
}
print_rebuild_requested_libraries() {
local counter=0
for REBUILD_LIBRARY in "${REBUILD_LIBRARIES[@]}"; do
if [[ ${counter} -eq 0 ]]; then
echo -n "Rebuild: "
else
echo -n ", "
fi
echo -n ${REBUILD_LIBRARY}
counter=$((${counter} + 1))
done
if [[ ${counter} -gt 0 ]]; then
echo ""
fi
}
print_redownload_requested_libraries() {
local counter=0
for REDOWNLOAD_LIBRARY in "${REDOWNLOAD_LIBRARIES[@]}"; do
if [[ ${counter} -eq 0 ]]; then
echo -n "Redownload: "
else
echo -n ", "
fi
echo -n ${REDOWNLOAD_LIBRARY}
counter=$((${counter} + 1))
done
if [[ ${counter} -gt 0 ]]; then
echo ""
fi
}
build_application_mk() {
if [[ ! -z ${MOBILE_FFMPEG_LTS_BUILD} ]]; then
local LTS_BUILD_FLAG="-DMOBILE_FFMPEG_LTS "
fi
if [[ ${ENABLED_LIBRARIES[$LIBRARY_X265]} -eq 1 ]] || [[ ${ENABLED_LIBRARIES[$LIBRARY_TESSERACT]} -eq 1 ]] || [[ ${ENABLED_LIBRARIES[$LIBRARY_OPENH264]} -eq 1 ]] || [[ ${ENABLED_LIBRARIES[$LIBRARY_SNAPPY]} -eq 1 ]] || [[ ${ENABLED_LIBRARIES[$LIBRARY_RUBBERBAND]} -eq 1 ]]; then
local APP_STL="c++_shared"
else
local APP_STL="none"
fi
local BUILD_DATE="-DMOBILE_FFMPEG_BUILD_DATE=$(date +%Y%m%d 2>>${BASEDIR}/build.log)"
rm -f ${BASEDIR}/android/jni/Application.mk
cat >"${BASEDIR}/android/jni/Application.mk" <<EOF
APP_OPTIM := release
APP_ABI := ${ANDROID_ARCHITECTURES}
APP_STL := ${APP_STL}
APP_PLATFORM := android-${API}
APP_CFLAGS := -O3 -DANDROID ${LTS_BUILD_FLAG}${BUILD_DATE} -Wall -Wno-deprecated-declarations -Wno-pointer-sign -Wno-switch -Wno-unused-result -Wno-unused-variable
APP_LDFLAGS := -Wl,--hash-style=both
EOF
}
if [[ -z ${ANDROID_NDK_ROOT} ]]; then
echo "ANDROID_NDK_ROOT not defined"
exit 1
fi
if [[ -z ${ANDROID_HOME} ]]; then
echo "ANDROID_HOME not defined"
exit 1
fi
# ENABLE COMMON FUNCTIONS
. ${BASEDIR}/build/android-common.sh
DETECTED_NDK_VERSION=$(grep -Eo Revision.* ${ANDROID_NDK_ROOT}/source.properties | sed 's/Revision//g;s/=//g;s/ //g')
echo -e "\nINFO: Using Android NDK v${DETECTED_NDK_VERSION} provided at ${ANDROID_NDK_ROOT}\n" 1>>${BASEDIR}/build.log 2>&1
echo -e "INFO: Build options: $*\n" 1>>${BASEDIR}/build.log 2>&1
# CLEAR OLD NATIVE LIBS
rm -rf ${BASEDIR}/android/libs 1>>${BASEDIR}/build.log 2>&1
rm -rf ${BASEDIR}/android/obj 1>>${BASEDIR}/build.log 2>&1
GPL_ENABLED="no"
DISPLAY_HELP=""
BUILD_LTS=""
BUILD_FULL=""
BUILD_TYPE_ID=""
BUILD_VERSION=$(git describe --tags 2>>${BASEDIR}/build.log)
while [ ! $# -eq 0 ]; do
case $1 in
-h | --help)
DISPLAY_HELP="1"
;;
-v | --version)
display_version
exit 0
;;
--skip-*)
SKIP_LIBRARY=$(echo $1 | sed -e 's/^--[A-Za-z]*-//g')
skip_library ${SKIP_LIBRARY}
;;
--no-output-redirection)
no_output_redirection
;;
--no-workspace-cleanup-*)
NO_WORKSPACE_CLEANUP_LIBRARY=$(echo $1 | sed -e 's/^--[A-Za-z]*-[A-Za-z]*-[A-Za-z]*-//g')
no_workspace_cleanup_library ${NO_WORKSPACE_CLEANUP_LIBRARY}
;;
--no-link-time-optimization)
no_link_time_optimization
;;
-d | --debug)
enable_debug
;;
-s | --speed)
optimize_for_speed
;;
-l | --lts)
BUILD_LTS="1"
;;
-f | --force)
BUILD_FORCE="1"
;;
--reconf-*)
CONF_LIBRARY=$(echo $1 | sed -e 's/^--[A-Za-z]*-//g')
reconf_library ${CONF_LIBRARY}
;;
--rebuild-*)
BUILD_LIBRARY=$(echo $1 | sed -e 's/^--[A-Za-z]*-//g')
rebuild_library ${BUILD_LIBRARY}
;;
--redownload-*)
DOWNLOAD_LIBRARY=$(echo $1 | sed -e 's/^--[A-Za-z]*-//g')
redownload_library ${DOWNLOAD_LIBRARY}
;;
--full)
BUILD_FULL="1"
;;
--enable-gpl)
GPL_ENABLED="yes"
;;
--enable-*)
ENABLED_LIBRARY=$(echo $1 | sed -e 's/^--[A-Za-z]*-//g')
enable_library ${ENABLED_LIBRARY}
;;
--disable-*)
DISABLED_ARCH=$(echo $1 | sed -e 's/^--[A-Za-z]*-//g')
disable_arch ${DISABLED_ARCH}
;;
*)
print_unknown_option $1
;;
esac
shift
done
# DETECT BUILD TYPE
rm -f ${BASEDIR}/android/jni/Android.mk 1>>${BASEDIR}/build.log 2>&1
rm -f ${BASEDIR}/android/app/build.gradle 1>>${BASEDIR}/build.log 2>&1
if [[ ! -z ${BUILD_LTS} ]]; then
enable_lts_build
BUILD_TYPE_ID+="LTS "
cp ${BASEDIR}/tools/ndk/Android.lts.mk ${BASEDIR}/android/jni/Android.mk 1>>${BASEDIR}/build.log 2>&1
cp ${BASEDIR}/tools/release/android/build.lts.gradle ${BASEDIR}/android/app/build.gradle 1>>${BASEDIR}/build.log 2>&1
else
cp ${BASEDIR}/tools/ndk/Android.mk ${BASEDIR}/android/jni/Android.mk 1>>${BASEDIR}/build.log 2>&1
cp ${BASEDIR}/tools/release/android/build.gradle ${BASEDIR}/android/app/build.gradle 1>>${BASEDIR}/build.log 2>&1
if [[ -z ${BUILD_FORCE} ]] && [[ ${ENABLED_ARCHITECTURES[${ARCH_ARM_V7A}]} -eq 1 ]]; then
echo -e "INFO: Disabled arm-v7a architecture which is not included in Main releases.\n" 1>>${BASEDIR}/build.log 2>&1
disable_arch "arm-v7a"
fi
fi
if [[ ! -z ${DISPLAY_HELP} ]]; then
display_help
exit 0
fi
if [[ -n ${BUILD_FULL} ]]; then
for library in {0..46}; do
if [ ${GPL_ENABLED} == "yes" ]; then
enable_library $(get_library_name $library)
else
if [[ $library -ne 18 ]] && [[ $library -ne 19 ]] && [[ $library -ne 20 ]] && [[ $library -ne 21 ]] && [[ $library -ne 22 ]]; then
enable_library $(get_library_name $library)
fi
fi
done
fi
if [[ -z ${BUILD_VERSION} ]]; then
echo -e "\nerror: Can not run git commands in this folder. See build.log.\n"
exit 1
fi
echo -e "\nBuilding mobile-ffmpeg ${BUILD_TYPE_ID}library for Android\n"
echo -e -n "INFO: Building mobile-ffmpeg ${BUILD_VERSION} ${BUILD_TYPE_ID}library for Android: " 1>>${BASEDIR}/build.log 2>&1
echo -e $(date) 1>>${BASEDIR}/build.log 2>&1
# PERFORM THIS CHECK ONLY ON LTS
if [[ ! -z ${MOBILE_FFMPEG_LTS_BUILD} ]] && [[ ${ENABLED_ARCHITECTURES[0]} -eq 0 ]] && [[ ${ENABLED_ARCHITECTURES[1]} -eq 1 ]]; then
ENABLED_ARCHITECTURES[ARCH_ARM_V7A]=1
echo -e "(*) arm-v7a architecture enabled since arm-v7a-neon will be built\n"
echo -e "(*) arm-v7a architecture enabled since arm-v7a-neon will be built\n" 1>>${BASEDIR}/build.log 2>&1
fi
print_enabled_architectures
print_enabled_libraries
print_reconfigure_requested_libraries
print_rebuild_requested_libraries
print_redownload_requested_libraries
# CHECK GPL LIBRARIES
for gpl_library in {18,19,20,21,22}; do
if [[ ${ENABLED_LIBRARIES[$gpl_library]} -eq 1 ]]; then
library_name=$(get_library_name ${gpl_library})
if [ ${GPL_ENABLED} != "yes" ]; then
echo -e "\n(*) Invalid configuration detected. GPL library ${library_name} enabled without --enable-gpl flag.\n"
echo -e "\n(*) Invalid configuration detected. GPL library ${library_name} enabled without --enable-gpl flag.\n" 1>>${BASEDIR}/build.log 2>&1
exit 1
else
DOWNLOAD_RESULT=$(download_gpl_library_source ${library_name})
if [[ ${DOWNLOAD_RESULT} -ne 0 ]]; then
echo -e "\n(*) Failed to download GPL library ${library_name} source. Please check build.log file for details. If the problem persists refer to offline building instructions.\n"
echo -e "\n(*) Failed to download GPL library ${library_name} source.\n" 1>>${BASEDIR}/build.log 2>&1
exit 1
fi
fi
fi
done
# SAVE API VALUE
export ORIGINAL_API=${API}
for run_arch in {0..4}; do
if [[ ${ENABLED_ARCHITECTURES[$run_arch]} -eq 1 ]]; then
if [[ (${run_arch} -eq ${ARCH_ARM64_V8A} || ${run_arch} -eq ${ARCH_X86_64}) && ${API} -lt 21 ]]; then
# 64 bit ABIs supported after API 21
export API=21
else
export API=${ORIGINAL_API}
fi
export ARCH=$(get_arch_name $run_arch)
export TOOLCHAIN=$(get_toolchain)
export TOOLCHAIN_ARCH=$(get_toolchain_arch)
. ${BASEDIR}/build/main-android.sh "${ENABLED_LIBRARIES[@]}" || exit 1
# CLEAR FLAGS
for library in {0..47}; do
library_name=$(get_library_name ${library})
unset $(echo "OK_${library_name}" | sed "s/\-/\_/g")
unset $(echo "DEPENDENCY_REBUILT_${library_name}" | sed "s/\-/\_/g")
done
fi
done
export API=${ORIGINAL_API}
rm -f ${BASEDIR}/android/build/.neon 1>>${BASEDIR}/build.log 2>&1
ANDROID_ARCHITECTURES=""
if [[ ${ENABLED_ARCHITECTURES[1]} -eq 1 ]]; then
ANDROID_ARCHITECTURES+="$(get_android_arch 0) "
mkdir -p ${BASEDIR}/android/build 1>>${BASEDIR}/build.log 2>&1
cat >"${BASEDIR}/android/build/.neon" <<EOF
EOF
elif [[ ${ENABLED_ARCHITECTURES[0]} -eq 1 ]]; then
ANDROID_ARCHITECTURES+="$(get_android_arch 0) "
fi
if [[ ${ENABLED_ARCHITECTURES[2]} -eq 1 ]]; then
ANDROID_ARCHITECTURES+="$(get_android_arch 2) "
fi
if [[ ${ENABLED_ARCHITECTURES[3]} -eq 1 ]]; then
ANDROID_ARCHITECTURES+="$(get_android_arch 3) "
fi
if [[ ${ENABLED_ARCHITECTURES[4]} -eq 1 ]]; then
ANDROID_ARCHITECTURES+="$(get_android_arch 4) "
fi
if [[ ! -z ${ANDROID_ARCHITECTURES} ]]; then
echo -n -e "\nmobile-ffmpeg: "
build_application_mk
MOBILE_FFMPEG_AAR=${BASEDIR}/prebuilt/android-aar/mobile-ffmpeg
# BUILDING ANDROID ARCHIVE LIBRARY
rm -rf ${BASEDIR}/android/libs 1>>${BASEDIR}/build.log 2>&1
mkdir -p ${MOBILE_FFMPEG_AAR} 1>>${BASEDIR}/build.log 2>&1
cd ${BASEDIR}/android 1>>${BASEDIR}/build.log 2>&1
${ANDROID_NDK_ROOT}/ndk-build -B 1>>${BASEDIR}/build.log 2>&1
if [ $? -eq 0 ]; then
echo "ok"
else
echo "failed"
exit 1
fi
echo -e -n "\n\nCreating Android archive under prebuilt/android-aar: "
./gradlew app:clean app:assembleRelease app:testReleaseUnitTest 1>>${BASEDIR}/build.log 2>&1
if [ $? -ne 0 ]; then
echo -e "failed\n"
exit 1
fi
cp ${BASEDIR}/android/app/build/outputs/aar/mobile-ffmpeg-release.aar ${MOBILE_FFMPEG_AAR}/mobile-ffmpeg.aar 1>>${BASEDIR}/build.log 2>&1
if [ $? -ne 0 ]; then
echo -e "failed\n"
exit 1
fi
echo -e "Created mobile-ffmpeg Android archive successfully.\n" 1>>${BASEDIR}/build.log 2>&1
echo -e "ok\n"
fi