#!/bin/bash source "${BASEDIR}/scripts/function.sh" prepare_inline_sed enable_default_android_architectures() { ENABLED_ARCHITECTURES[ARCH_ARM_V7A]=1 ENABLED_ARCHITECTURES[ARCH_ARM_V7A_NEON]=1 ENABLED_ARCHITECTURES[ARCH_ARM64_V8A]=1 ENABLED_ARCHITECTURES[ARCH_X86]=1 ENABLED_ARCHITECTURES[ARCH_X86_64]=1 } enable_default_android_libraries() { ENABLED_LIBRARIES[LIBRARY_CPU_FEATURES]=1 } get_ffmpeg_kit_version() { local FFMPEG_KIT_VERSION=$(grep '#define FFMPEG_KIT_VERSION' "${BASEDIR}"/android/ffmpeg-kit-android-lib/src/main/cpp/ffmpegkit.h | grep -Eo '\".*\"' | sed -e 's/\"//g') echo "${FFMPEG_KIT_VERSION}" } display_help() { local COMMAND=$(echo "$0" | sed -e 's/\.\///g') echo -e "\n'$COMMAND' builds FFmpegKit for Android platform. By default five Android architectures (armeabi-v7a, \ armeabi-v7a-neon, arm64-v8a, x86 and x86_64) are built without any external libraries enabled. Options can be used to \ disable architectures 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]... [VAR=VALUE]...\n" echo -e "Specify environment variables as VARIABLE=VALUE to override default build options.\n" display_help_options " -l, --lts\t\t\tbuild lts packages to support API 16+ devices" " --api-level=api\t\toverride Android api level" " --no-ffmpeg-kit-protocols\tdisable custom ffmpeg-kit protocols (fd, saf)" display_help_licensing echo -e "Architectures:" echo -e " --disable-arm-v7a\t\tdo not build arm-v7a architecture [yes]" echo -e " --disable-arm-v7a-neon\tdo not build arm-v7a-neon architecture [yes]" echo -e " --disable-arm64-v8a\t\tdo not build arm64-v8a architecture [yes]" echo -e " --disable-x86\t\t\tdo not build x86 architecture [yes]" echo -e " --disable-x86-64\t\tdo not build x86-64 architecture [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]" display_help_common_libraries display_help_gpl_libraries display_help_advanced_options " --no-archive\t\t\tdo not build Android archive [no]" } enable_main_build() { export API=24 } enable_lts_build() { export FFMPEG_KIT_LTS_BUILD="1" # LTS RELEASES USE API LEVEL 16 / Android 4.1 (JELLY BEAN) export API=16 } build_application_mk() { if [[ -n ${FFMPEG_KIT_LTS_BUILD} ]]; then local LTS_BUILD_FLAG="-DFFMPEG_KIT_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="-DFFMPEG_KIT_BUILD_DATE=$(date +%Y%m%d 2>>"${BASEDIR}"/build.log)" rm -f "${BASEDIR}/android/jni/Application.mk" cat >"${BASEDIR}/android/jni/Application.mk" <>"${BASEDIR}"/build.log 2>&1 fi ;; libvpx) echo "-lc -lm ${COMMON_LIBRARY_PATHS}" ;; tesseract | x265) echo "-lc -lm -ldl -llog -lc++_shared ${COMMON_LIBRARY_PATHS}" ;; *) echo "-lc -lm -ldl -llog ${COMMON_LIBRARY_PATHS}" ;; esac } get_size_optimization_ldflags() { if [[ -z ${NO_LINK_TIME_OPTIMIZATION} ]]; then local LINK_TIME_OPTIMIZATION_FLAGS="-flto" else local LINK_TIME_OPTIMIZATION_FLAGS="" fi case ${ARCH} in arm64-v8a) case $1 in ffmpeg) echo "-Wl,--gc-sections ${LINK_TIME_OPTIMIZATION_FLAGS} -fuse-ld=lld -O2 -ffunction-sections -fdata-sections -finline-functions" ;; *) echo "-Wl,--gc-sections -Os -ffunction-sections -fdata-sections" ;; esac ;; *) case $1 in ffmpeg) echo "-Wl,--gc-sections,--icf=safe ${LINK_TIME_OPTIMIZATION_FLAGS} -O2 -ffunction-sections -fdata-sections -finline-functions" ;; *) echo "-Wl,--gc-sections,--icf=safe -Os -ffunction-sections -fdata-sections" ;; esac ;; esac } get_arch_specific_ldflags() { case ${ARCH} in arm-v7a) echo "-march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -Wl,--fix-cortex-a8" ;; arm-v7a-neon) echo "-march=armv7-a -mfpu=neon -mfloat-abi=softfp -Wl,--fix-cortex-a8" ;; arm64-v8a) echo "-march=armv8-a" ;; x86) echo "-march=i686" ;; x86-64) echo "-march=x86-64" ;; esac } get_ldflags() { local ARCH_FLAGS=$(get_arch_specific_ldflags) if [[ -z ${FFMPEG_KIT_DEBUG} ]]; then local OPTIMIZATION_FLAGS="$(get_size_optimization_ldflags "$1")" else local OPTIMIZATION_FLAGS="${FFMPEG_KIT_DEBUG}" fi local COMMON_LINKED_LIBS=$(get_common_linked_libraries "$1") echo "${ARCH_FLAGS} ${OPTIMIZATION_FLAGS} ${COMMON_LINKED_LIBS} -Wl,--hash-style=both -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libunwind.a" } create_mason_cross_file() { cat >"$1" <"${INSTALL_PKG_CONFIG_DIR}/libchromaprint.pc" <"${INSTALL_PKG_CONFIG_DIR}/fontconfig.pc" <= 21.0.15, uuid, expat >= 2.2.0, libiconv Requires.private: Libs: -L\${libdir} -lfontconfig Libs.private: Cflags: -I\${includedir} EOF } create_freetype_package_config() { local FREETYPE_VERSION="$1" cat >"${INSTALL_PKG_CONFIG_DIR}/freetype2.pc" <"${INSTALL_PKG_CONFIG_DIR}/giflib.pc" <"${INSTALL_PKG_CONFIG_DIR}/gmp.pc" <"${INSTALL_PKG_CONFIG_DIR}/gnutls.pc" <"${INSTALL_PKG_CONFIG_DIR}/aom.pc" <"${INSTALL_PKG_CONFIG_DIR}/libiconv.pc" <"${INSTALL_PKG_CONFIG_DIR}/libmp3lame.pc" <"${INSTALL_PKG_CONFIG_DIR}/vorbis.pc" <"${INSTALL_PKG_CONFIG_DIR}/vorbisenc.pc" <"${INSTALL_PKG_CONFIG_DIR}/vorbisfile.pc" <"${INSTALL_PKG_CONFIG_DIR}/libxml-2.0.pc" <"${INSTALL_PKG_CONFIG_DIR}/snappy.pc" <"${INSTALL_PKG_CONFIG_DIR}/soxr.pc" <"${INSTALL_PKG_CONFIG_DIR}/tesseract.pc" <"${INSTALL_PKG_CONFIG_DIR}/uuid.pc" <"${INSTALL_PKG_CONFIG_DIR}/x265.pc" <"${INSTALL_PKG_CONFIG_DIR}/xvidcore.pc" <"${INSTALL_PKG_CONFIG_DIR}/zlib.pc" <"${INSTALL_PKG_CONFIG_DIR}/cpu-features.pc" <>"${BASEDIR}"/build.log 2>&1 fi if [ ! -f "${ZLIB_PACKAGE_CONFIG_PATH}" ]; then create_zlib_system_package_config 1>>"${BASEDIR}"/build.log 2>&1 fi } build_android_lts_support() { # CLEAN OLD BUILD rm -f "${BASEDIR}"/android/ffmpeg-kit-android-lib/src/main/cpp/android_lts_support.o 1>>"${BASEDIR}"/build.log 2>&1 rm -f "${BASEDIR}"/android/ffmpeg-kit-android-lib/src/main/cpp/android_lts_support.a 1>>"${BASEDIR}"/build.log 2>&1 echo -e "INFO: Building android-lts-support objects for ${ARCH}\n" 1>>"${BASEDIR}"/build.log 2>&1 # PREPARE PATHS LIB_NAME="android-lts-support" set_toolchain_paths ${LIB_NAME} # PREPARE FLAGS HOST=$(get_host) CFLAGS=$(get_cflags "${LIB_NAME}") LDFLAGS=$(get_ldflags ${LIB_NAME}) # BUILD "${CC}" ${CFLAGS} -Wno-unused-command-line-argument -c "${BASEDIR}"/android/ffmpeg-kit-android-lib/src/main/cpp/android_lts_support.c -o "${BASEDIR}"/android/ffmpeg-kit-android-lib/src/main/cpp/android_lts_support.o ${LDFLAGS} 1>>"${BASEDIR}"/build.log 2>&1 "${AR}" rcs "${BASEDIR}"/android/ffmpeg-kit-android-lib/src/main/cpp/libandroidltssupport.a "${BASEDIR}"/android/ffmpeg-kit-android-lib/src/main/cpp/android_lts_support.o 1>>"${BASEDIR}"/build.log 2>&1 }