Structured --arch, --cc and --cross-prefix evaluating

ffmpeg_4.4.2
Javernaut 5 years ago
parent 848ab4dec6
commit cbd525e033
  1. 4
      README.md
  2. 75
      ffmpeg-android-maker.sh

@ -7,8 +7,8 @@ Here is a script that downloads the source code of [FFmpeg](https://www.ffmpeg.o
The actual content of all this directories depends on how the FFmpeg was configured before assembling. For my purpose I enabled only *libavcodec*, *libavformat*, *libavutil* and *libswscale*, but you can set your own configuration to make the FFmpeg you need. The actual content of all this directories depends on how the FFmpeg was configured before assembling. For my purpose I enabled only *libavcodec*, *libavformat*, *libavutil* and *libswscale*, but you can set your own configuration to make the FFmpeg you need.
The version of FFmpeg here by default is **4.1.4** (but can be overridden). And the script expects to use **at least** Android NDK **r19** (*r20* also works ok). Starting with FFmpeg 4.1 and NDK r19 the whole process became much simpler. The version of FFmpeg here by default is **4.1.4** (but can be overridden). And the script expects to use **at least** Android NDK **r19** (*r20* also works ok). Starting with FFmpeg 4.1 and NDK r19 the whole process became much simpler.
## Supported Android architectures ## Supported Android ABIs
a
* armeabi-v7a * armeabi-v7a
* arm64-v8a * arm64-v8a
* x86 * x86

@ -96,67 +96,78 @@ function ensureSources() {
esac esac
} }
# Actual magic of configuring and compiling of FFmpeg for a certain architecture. # Actual magic of configuring and compiling of FFmpeg for a certain ABIs.
# Supported architectures are: armeabi-v7a, arm64-v8a, x86 and x86_64 # Supported ABIs are: armeabi-v7a, arm64-v8a, x86 and x86_64
function assemble() { function assemble() {
cd ${FFMPEG_SOURCES} cd ${FFMPEG_SOURCES}
ARCH=$1 ABI=$1
API_LEVEL=$2 API_LEVEL=$2
TOOLCHAIN_PATH=${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/${HOST_TAG} TOOLCHAIN_PATH=${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/${HOST_TAG}
SYSROOT=${TOOLCHAIN_PATH}/sysroot SYSROOT=${TOOLCHAIN_PATH}/sysroot
CC_ANDROID_POSTFIX=
EXTRA_CFLAGS= EXTRA_CFLAGS=
EXTRA_CONFIGURE_FLAGS= EXTRA_CONFIGURE_FLAGS=
case $ARCH in TARGET_TRIPLE_MACHINE_BINUTILS=
TARGET_TRIPLE_MACHINE_CC=
TARGET_TRIPLE_OS="android"
case $ABI in
armeabi-v7a) armeabi-v7a)
FFMPEG_ARCH_FLAG=arm #cc armv7a-linux-androideabi16-clang
CROSS_PREFIX=arm-linux-androideabi- #binutils arm -linux-androideabi -ld
CC_PREFIX=armv7a TARGET_TRIPLE_MACHINE_BINUTILS=arm
CC_ANDROID_POSTFIX=eabi TARGET_TRIPLE_MACHINE_CC=armv7a
TARGET_TRIPLE_OS=androideabi
;; ;;
arm64-v8a) arm64-v8a)
FFMPEG_ARCH_FLAG=aarch64 #cc aarch64-linux-android21-clang
CROSS_PREFIX=aarch64-linux-android- #binutils aarch64-linux-android -ld
CC_PREFIX=aarch64 TARGET_TRIPLE_MACHINE_BINUTILS=aarch64
;; ;;
x86) x86)
FFMPEG_ARCH_FLAG=x86 #cc i686-linux-android16-clang
CROSS_PREFIX=i686-linux-android- #binutils i686-linux-android -ld
CC_PREFIX=i686 TARGET_TRIPLE_MACHINE_BINUTILS=i686
EXTRA_CFLAGS=-mno-stackrealign EXTRA_CFLAGS=-mno-stackrealign
EXTRA_CONFIGURE_FLAGS=--disable-asm EXTRA_CONFIGURE_FLAGS=--disable-asm
;; ;;
x86_64) x86_64)
FFMPEG_ARCH_FLAG=x86_64 #cc x86_64-linux-android21-clang
CROSS_PREFIX=x86_64-linux-android- #binutils x86_64-linux-android -ld
CC_PREFIX=x86_64 TARGET_TRIPLE_MACHINE_BINUTILS=x86_64
EXTRA_CONFIGURE_FLAGS=--x86asmexe=${TOOLCHAIN_PATH}/bin/yasm EXTRA_CONFIGURE_FLAGS=--x86asmexe=${TOOLCHAIN_PATH}/bin/yasm
;; ;;
esac esac
CC=${TOOLCHAIN_PATH}/bin/${CC_PREFIX}-linux-android${CC_ANDROID_POSTFIX}${API_LEVEL}-clang # If the cc-specific variable isn't set, we fallback to binutils version
[ -z "${TARGET_TRIPLE_MACHINE_CC}" ] && TARGET_TRIPLE_MACHINE_CC=${TARGET_TRIPLE_MACHINE_BINUTILS}
CROSS_PREFIX=${TOOLCHAIN_PATH}/bin/${TARGET_TRIPLE_MACHINE_BINUTILS}-linux-${TARGET_TRIPLE_OS}-
CC=${TOOLCHAIN_PATH}/bin/${TARGET_TRIPLE_MACHINE_CC}-linux-${TARGET_TRIPLE_OS}${API_LEVEL}-clang
DECODERS_TO_ENABLE= DECODERS_TO_ENABLE=
while IFS= read -r line; do DECODERS_TO_ENABLE="${DECODERS_TO_ENABLE} --enable-decoder=$line"; done < ${BASE_DIR}/video_decoders_list.txt while IFS= read -r line; do DECODERS_TO_ENABLE="${DECODERS_TO_ENABLE} --enable-decoder=$line"; done < ${BASE_DIR}/video_decoders_list.txt
./configure \ ./configure \
--prefix=${BUILD_DIR}/${ARCH} \ --prefix=${BUILD_DIR}/${ABI} \
--disable-doc \
--enable-cross-compile \ --enable-cross-compile \
--cross-prefix=${TOOLCHAIN_PATH}/bin/${CROSS_PREFIX} \ --cross-prefix=${CROSS_PREFIX} \
--arch=${TARGET_TRIPLE_MACHINE_BINUTILS} \
--target-os=android \ --target-os=android \
--cc=${CC} \ --cc=${CC} \
--arch=${FFMPEG_ARCH_FLAG} \
--extra-cflags="-O3 -fPIC $EXTRA_CFLAGS" \ --extra-cflags="-O3 -fPIC $EXTRA_CFLAGS" \
--sysroot=${SYSROOT} \ --sysroot=${SYSROOT} \
--enable-shared \ --enable-shared \
--disable-static \ --disable-static \
--disable-debug \ --disable-doc \
--disable-runtime-cpudetect \ --disable-runtime-cpudetect \
--disable-debug \
--disable-programs \ --disable-programs \
--disable-muxers \ --disable-muxers \
--disable-encoders \ --disable-encoders \
@ -177,7 +188,7 @@ function assemble() {
# Saving stats about text relocation presence. # Saving stats about text relocation presence.
# If the result file doesn't have 'TEXTREL' at all, then we are good. # If the result file doesn't have 'TEXTREL' at all, then we are good.
${TOOLCHAIN_PATH}/bin/${CROSS_PREFIX}readelf --dynamic ${BUILD_DIR}/${ARCH}/lib/*.so | grep 'TEXTREL\|File' >> ${STATS_DIR}/text-relocations.txt ${CROSS_PREFIX}readelf --dynamic ${BUILD_DIR}/${ABI}/lib/*.so | grep 'TEXTREL\|File' >> ${STATS_DIR}/text-relocations.txt
cd ${BASE_DIR} cd ${BASE_DIR}
} }
@ -194,16 +205,16 @@ function installLibs() {
} }
function build() { function build() {
ARCH=$1 ABI=$1
ANDROID_API=$2 ANDROID_API=$2
assemble ${ARCH} ${ANDROID_API} assemble ${ABI} ${ANDROID_API}
installLibs ${ARCH} installLibs ${ABI}
} }
# Placing build header files into the /bin directory # Placing build header files into the /bin directory.
# Note, there is a only one such a folder since this headers are the same for all architectures # Note, there is a only one such a folder since this headers are the same for all ABIs.
# May not be true for different configurations though # May not be true for different configurations though.
function installHeaders() { function installHeaders() {
cd ${BUILD_DIR} cd ${BUILD_DIR}
cd "$(ls -1 | head -n1)" cd "$(ls -1 | head -n1)"

Loading…
Cancel
Save