ndk
版本:android-ndk-r20b
FFmpeg
版本:ffmpeg-4.4.3
lame
使用ndk
编译参考:centos7使用ndk编译lamex264
使用ndk
编译参考:centos7使用ndk编译x264fdk-aac
使用ndk
编译参考:centos使用ndk编译fdk-acc-2.0.2脚本位置:ffmpeg-4.4.3/build_android.sh
#!/bin/bash
function build_android
{
./configure \
--enable-shared \
--enable-static \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-avdevice \
--disable-devices \
--disable-postproc \
--disable-indevs \
--disable-outdevs \
--disable-asm \
--disable-yasm \
--disable-x86asm \
--disable-doc \
--disable-debug \
--enable-small \
--enable-gpl \
--enable-neon \
--enable-nonfree \
--disable-bsfs \
--enable-bsf=aac_adtstoasc \
--enable-bsf=h264_mp4toannexb \
--enable-libfdk_aac \
--enable-libx264 \
--enable-libmp3lame \
--enable-cross-compile \
--enable-jni \
--enable-pic \
--enable-pthreads \
--enable-cross-compile \
--target-os=android \
--prefix=$PREFIX \
--arch=$ARCH \
--cpu=$CPU \
--cc=$CC \
--cxx=$CXX \
--cross-prefix=$CROSS_PREFIX \
--sysroot=$SYSROOT \
--extra-cflags="-I${LAME_INCLUDE} -I${X264_INCLUDE} -I${FDK_INCLUDE} -Os -fpic ${OPTIMIZE_CFLAGS}" \
--extra-ldflags="-lm -L${LAME_LIB} -L${FDK_LIB} -L${X264_LIB} ${ADDI_LDFLAGS}"
make clean
make -j8
make install
}
# NDK所在目录
NDK_ROOT=/root/workspace/android-ndk-r20b
TOOLCHAIN="${NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64"
SYSROOT=$TOOLCHAIN/sysroot
# 最低支持的Android版本
V=21
# 其他库所在目录公共前缀
BASE_PATH=/root/workspace
#32位V7 # armeabi-v7a armv7a-linux-androideabi
PREFIX=$(pwd)/android/armeabi-v7a
ARCH=arm
CPU=armv7-a
HOST=armv7a-linux-androideabi
CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-
CC=$TOOLCHAIN/bin/$HOST$V-clang
CXX=$TOOLCHAIN/bin/$HOST$V-clang++
LIB_TARGET_ABI=armeabi-v7a
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=${CPU} "
ADDI_LDFLAGS="-marm -march=${CPU}"
# 指定fdk-aac的头文件和静态库目录
FDK_INCLUDE=$BASE_PATH/fdk-aac-2.0.2/android/$LIB_TARGET_ABI/include
FDK_LIB=$BASE_PATH/fdk-aac-2.0.2/android/$LIB_TARGET_ABI/lib
# 指定x264的头文件和静态库目录
X264_INCLUDE=$BASE_PATH/x264-master/android/$LIB_TARGET_ABI/include
X264_LIB=$BASE_PATH/x264-master/android/$LIB_TARGET_ABI/lib
# 指定lame的头文件和库目录
LAME_INCLUDE=$BASE_PATH/lame-3.100/android/$LIB_TARGET_ABI/include
LAME_LIB=$BASE_PATH/lame-3.100/android/$LIB_TARGET_ABI/lib
build_android
#64位V8 # arm64-v8a aarch64-linux-android
# PREFIX=$(pwd)/android/arm64-v8a
# ARCH=aarch64
# CPU=armv8-a
# HOST=aarch64-linux-android
# CROSS_PREFIX=$TOOLCHAIN/bin/aarch64-linux-android-
# CC=$TOOLCHAIN/bin/$HOST$V-clang
# CXX=$TOOLCHAIN/bin/$HOST$V-clang++
# LIB_TARGET_ABI=arm64-v8a
# OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=${CPU} "
# ADDI_LDFLAGS="-marm -march=${CPU}"
# 指定fdk-aac的头文件和静态库目录
# FDK_INCLUDE=$BASE_PATH/fdk-aac-2.0.2/android/$LIB_TARGET_ABI/include
# FDK_LIB=$BASE_PATH/fdk-aac-2.0.2/android/$LIB_TARGET_ABI/lib
# 指定x264的头文件和静态库目录
# X264_INCLUDE=$BASE_PATH/x264-master/android/$LIB_TARGET_ABI/include
# X264_LIB=$BASE_PATH/x264-master/android/$LIB_TARGET_ABI/lib
# 指定lame的头文件和库目录
# LAME_INCLUDE=$BASE_PATH/lame-3.100/android/$LIB_TARGET_ABI/include
# LAME_LIB=$BASE_PATH/lame-3.100/android/$LIB_TARGET_ABI/lib
# build_android
#32位x86 # x86 i686-linux-android
# PREFIX=$(pwd)/android/x86
# ARCH=x86
# CPU=x86
# HOST=i686-linux-android
# CROSS_PREFIX=$TOOLCHAIN/bin/i686-linux-android-
# CC=$TOOLCHAIN/bin/$HOST$V-clang
# CXX=$TOOLCHAIN/bin/$HOST$V-clang++
# LIB_TARGET_ABI=x86
# OPTIMIZE_CFLAGS="-march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32 "
# ADDI_LDFLAGS="-marm -march=${CPU}"
# 指定fdk-aac的头文件和静态库目录
# FDK_INCLUDE=$BASE_PATH/fdk-aac-2.0.2/android/$LIB_TARGET_ABI/include
# FDK_LIB=$BASE_PATH/fdk-aac-2.0.2/android/$LIB_TARGET_ABI/lib
# 指定x264的头文件和静态库目录
# X264_INCLUDE=$BASE_PATH/x264-master/android/$LIB_TARGET_ABI/include
# X264_LIB=$BASE_PATH/x264-master/android/$LIB_TARGET_ABI/lib
# 指定lame的头文件和库目录
# LAME_INCLUDE=$BASE_PATH/lame-3.100/android/$LIB_TARGET_ABI/include
# LAME_LIB=$BASE_PATH/lame-3.100/android/$LIB_TARGET_ABI/lib
# build_android
#64位x86_64 # x86-64 x86_64-linux-android
# PREFIX=$(pwd)/android/x86_64
# ARCH=x86_64
# CPU=x86-64 # 注意此处中间为-,不是_
# HOST=x86_64-linux-android
# CROSS_PREFIX=$TOOLCHAIN/bin/x86_64-linux-android-
# CC=$TOOLCHAIN/bin/$HOST$V-clang
# CXX=$TOOLCHAIN/bin/$HOST$V-clang++
# LIB_TARGET_ABI=x86_64
# OPTIMIZE_CFLAGS="-msse4.2 -mpopcnt -m64 -mtune=intel -march=${CPU} "
# ADDI_LDFLAGS="-marm -march=${CPU}"
# 指定fdk-aac的头文件和静态库目录
# FDK_INCLUDE=$BASE_PATH/fdk-aac-2.0.2/android/$LIB_TARGET_ABI/include
# FDK_LIB=$BASE_PATH/fdk-aac-2.0.2/android/$LIB_TARGET_ABI/lib
# 指定x264的头文件和静态库目录
# X264_INCLUDE=$BASE_PATH/x264-master/android/$LIB_TARGET_ABI/include
# X264_LIB=$BASE_PATH/x264-master/android/$LIB_TARGET_ABI/lib
# 指定lame的头文件和库目录
# LAME_INCLUDE=$BASE_PATH/lame-3.100/android/$LIB_TARGET_ABI/include
# LAME_LIB=$BASE_PATH/lame-3.100/android/$LIB_TARGET_ABI/lib
# build_android
单独编译FFmpeg
,不使用lame
、fdk-aac
、x264
的脚本:
#!/bin/bash
function build_android
{
./configure \
--enable-shared \
--enable-static \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-avdevice \
--disable-devices \
--disable-postproc \
--disable-indevs \
--disable-outdevs \
--disable-asm \
--disable-yasm \
--disable-x86asm \
--disable-doc \
--disable-debug \
--enable-small \
--enable-gpl \
--enable-neon \
--enable-nonfree \
--disable-bsfs \
--enable-bsf=aac_adtstoasc \
--enable-bsf=h264_mp4toannexb \
--enable-cross-compile \
--enable-jni \
--enable-pic \
--enable-pthreads \
--enable-cross-compile \
--target-os=android \
--prefix=$PREFIX \
--arch=$ARCH \
--cpu=$CPU \
--cc=$CC \
--cxx=$CXX \
--cross-prefix=$CROSS_PREFIX \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic ${OPTIMIZE_CFLAGS}" \
--extra-ldflags="-lm ${ADDI_LDFLAGS}"
make clean
make -j8
make install
}
# NDK所在目录
NDK_ROOT=/root/workspace/android-ndk-r20b
TOOLCHAIN="${NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64"
SYSROOT=$TOOLCHAIN/sysroot
# 最低支持的Android版本
V=21
#32位V7 # armeabi-v7a armv7a-linux-androideabi
# PREFIX=$(pwd)/android_2/armeabi-v7a
# ARCH=arm
# CPU=armv7-a
# HOST=armv7a-linux-androideabi
# CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-
# CC=$TOOLCHAIN/bin/$HOST$V-clang
# CXX=$TOOLCHAIN/bin/$HOST$V-clang++
# LIB_TARGET_ABI=armeabi-v7a
# OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=${CPU} "
# ADDI_LDFLAGS="-marm -march=${CPU}"
# build_android
#64位V8 # arm64-v8a aarch64-linux-android
PREFIX=$(pwd)/android_2/arm64-v8a
ARCH=aarch64
CPU=armv8-a
HOST=aarch64-linux-android
CROSS_PREFIX=$TOOLCHAIN/bin/aarch64-linux-android-
CC=$TOOLCHAIN/bin/$HOST$V-clang
CXX=$TOOLCHAIN/bin/$HOST$V-clang++
LIB_TARGET_ABI=arm64-v8a
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=${CPU} "
ADDI_LDFLAGS="-marm -march=${CPU}"
build_android
#32位x86 # x86 i686-linux-android
# PREFIX=$(pwd)/android_2/x86
# ARCH=x86
# CPU=x86
# HOST=i686-linux-android
# CROSS_PREFIX=$TOOLCHAIN/bin/i686-linux-android-
# CC=$TOOLCHAIN/bin/$HOST$V-clang
# CXX=$TOOLCHAIN/bin/$HOST$V-clang++
# LIB_TARGET_ABI=x86
# OPTIMIZE_CFLAGS="-march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32 "
# ADDI_LDFLAGS="-marm -march=${CPU}"
# build_android
#64位x86_64 # x86-64 x86_64-linux-android
# PREFIX=$(pwd)/android_2/x86_64
# ARCH=x86_64
# CPU=x86-64 # 注意此处中间为-,不是_
# HOST=x86_64-linux-android
# CROSS_PREFIX=$TOOLCHAIN/bin/x86_64-linux-android-
# CC=$TOOLCHAIN/bin/$HOST$V-clang
# CXX=$TOOLCHAIN/bin/$HOST$V-clang++
# LIB_TARGET_ABI=x86_64
# OPTIMIZE_CFLAGS="-msse4.2 -mpopcnt -m64 -mtune=intel -march=${CPU} "
# ADDI_LDFLAGS="-marm -march=${CPU}"
# build_android
执行脚本:
# 1. 添加权限
chmod a+x build_android.sh
# 2. 执行脚本
./build_android.sh
1.编译x86-64
时遇到 C compiler test failed
原因:
# 查看编译日志
vim ffbuild/config.log
2. 编译x86
时遇到如下问题:
解决方法:
编译配置添加如下内容,取消汇编优化
--disable-asm \
--disable-yasm \
https://toscode.gitee.com/icebear221/AndroidFFmpeg