注意:这里由于本人对mac 脚本命令不熟(先简单看了半天linux shell命令行,推荐大家看这本书, Linux 运维之道,半天就上手了),本篇只是自己操作的,仅仅是个走下流程的Demo说明。接着上篇笔记,来实现android 多平台编译(armeabi arm64-v8a armv7a x86 x86-64) 。
第一个脚本主要是用来具体编译某一个平台的, 先上脚本,我在说明!!
set -e
echo --------
echo ANDROID_NDK path is ok !
ANDROID_NDK=/Users/cievon/Documents/AndroidSDK/android-ndk-r10e
echo --------
echo ROOT_PREFIX Include and lib output paths ! You can set up your own path here
ROOT_PREFIX=$(pwd)/../build/x264
ROOT=$(pwd)
echo --------
echo 1.Check the NDK path
mkdir $ROOT_PREFIX
if [ -z "$ANDROID_NDK" ]; then
echo "You must define ANDROID_NDK before starting."
echo "They must point to your NDK directories.\n"
exit 1
fi
#--------------------
echo --------
echo 2.Check and compile platform for android
FF_ARCH=$1
if [ -z "$FF_ARCH" ]; then
echo "You must specific an architecture 'arm, armv7a, x86, ...'.\n"
exit 1
fi
echo --------
echo 3.configure params for different platforms
FF_ANDROID_PLATFORM=android-9
#----- armv7a begin -----
if [ "$FF_ARCH" = "armv7a" ]; then
PREBUILT=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt
export PATH=$PATH:$PREBUILT/darwin-x86_64/bin/
PLATFORM=$ANDROID_NDK/platforms/$FF_ANDROID_PLATFORM/arch-arm
CROSS_PREFIX=$PREBUILT/darwin-x86_64/bin/arm-linux-androideabi-
HOST=arm-linux
PREFIX=$ROOT_PREFIX/$FF_ARCH/
FF_CFG_CONF="$FF_CFG_CONF --disable-asm"
elif [ "$FF_ARCH" = "armv5" ]; then
PREBUILT=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt
export PATH=$PATH:$PREBUILT/darwin-x86_64/bin/
PLATFORM=$ANDROID_NDK/platforms/$FF_ANDROID_PLATFORM/arch-arm
CROSS_PREFIX=$PREBUILT/darwin-x86_64/bin/arm-linux-androideabi-
HOST=arm-linux
PREFIX=$ROOT_PREFIX/$FF_ARCH/
FF_CFG_CONF="$FF_CFG_CONF --disable-asm"
elif [ "$FF_ARCH" = "arm64" ]; then
FF_ANDROID_PLATFORM=android-21
PREBUILT=$ANDROID_NDK/toolchains/aarch64-linux-android-4.9/prebuilt
export PATH=$PATH:$PREBUILT/darwin-x86_64/bin/
PLATFORM=$ANDROID_NDK/platforms/$FF_ANDROID_PLATFORM/arch-arm64
CROSS_PREFIX=$PREBUILT/darwin-x86_64/bin/aarch64-linux-android-
HOST=aarch64-linux
PREFIX=$ROOT_PREFIX/$FF_ARCH/
FF_CFG_CONF="$FF_CFG_CONF --enable-asm"
elif [ "$FF_ARCH" = "x86" ]; then
PREBUILT=$ANDROID_NDK/toolchains/x86-4.9/prebuilt
export PATH=$PATH:$PREBUILT/darwin-x86_64/bin/
PLATFORM=$ANDROID_NDK/platforms/$FF_ANDROID_PLATFORM/arch-x86
CROSS_PREFIX=$PREBUILT/darwin-x86_64/bin/i686-linux-android-
HOST=i686-linux
PREFIX=$ROOT_PREFIX/$FF_ARCH/
FF_CFG_CONF="$FF_CFG_CONF --disable-asm"
elif [ "$FF_ARCH" = "x86_64" ]; then
FF_ANDROID_PLATFORM=android-21
PREBUILT=$ANDROID_NDK/toolchains/x86_64-4.9/prebuilt
export PATH=$PATH:$PREBUILT/darwin-x86_64/bin/
PLATFORM=$ANDROID_NDK/platforms/$FF_ANDROID_PLATFORM/arch-x86_64
CROSS_PREFIX=$PREBUILT/darwin-x86_64/bin/x86_64-linux-android-
HOST=x86_64-linux
PREFIX=$ROOT_PREFIX/$FF_ARCH/
FF_CFG_CONF="$FF_CFG_CONF --disable-asm"
else
echo --------
echo "unknown architecture $FF_ARCH";
exit 1
fi
echo --------
mkdir $PREFIX
echo Enter your x264 source directory ! You have to modify it into your own source path
cd $ROOT/../x264-$FF_ARCH
echo --------
echo Build the necessary and other attributes for configure
FF_CFG_CONF="$FF_CFG_CONF --prefix=$PREFIX"
# FF_CFG_CONF="$FF_CFG_CONF --enable-shared"
FF_CFG_CONF="$FF_CFG_CONF --enable-static"
FF_CFG_CONF="$FF_CFG_CONF --disable-cli"
# FF_CFG_CONF="$FF_CFG_CONF --disable-opencl"
FF_CFG_CONF="$FF_CFG_CONF --disable-thread"
# FF_CFG_CONF="$FF_CFG_CONF --enable-pic"
# FF_CFG_CONF="$FF_CFG_CONF --enable-strip"
# FF_CFG_CONF="$FF_CFG_CONF --disable-avs"
# FF_CFG_CONF="$FF_CFG_CONF --disable-swscale"
# FF_CFG_CONF="$FF_CFG_CONF --disable-lavf"
# FF_CFG_CONF="$FF_CFG_CONF --disable-ffms"
FF_CFG_CONF="$FF_CFG_CONF --disable-gpac"
FF_CFG_CONF="$FF_CFG_CONF --disable-lsmash"
FF_CFG_CONF="$FF_CFG_CONF --host=$HOST"
FF_CFG_CONF="$FF_CFG_CONF --cross-prefix=$CROSS_PREFIX"
FF_CFG_CONF="$FF_CFG_CONF --sysroot=$PLATFORM"
echo --------
echo configure: $FF_CFG_CONF
echo
./configure $FF_CFG_CONF
echo --------
echo make
make
sudo make install
echo --------
echo finish ! ! !
echo --------
NDK编译工具要配置3个路径 :android ndk 目录;ndk 下面的 platforms 和 toolchains ,剩下的就是android 支持的平台参数配置不同了,看下这两个目录 对比下一目了然,D:\android-sdk\ndk-bundle\platforms\android-21 和 D:\android-sdk\ndk-bundle\toolchains。
x264源码编译的配置,流程如下,配置configure 参数,执行 ./configure ....参数内容 ,然后 make ,再 make install ,就得到你要的 include 和lib 目录了!!!脚本里面的配置 有三个必要的配置,这里呢!!!我这里贴图 ,到源码目录下,有个configure文件,这就是总开关了,打开里面,如下图:
是不是懵逼了!!! 我建议先按照我的配置来,先编出来!! 有时间,可以仔细看这个脚本配置。
首先NDK 交叉编译 这单个是必须的:
FF_CFG_CONF="$FF_CFG_CONF --host=$HOST"
FF_CFG_CONF="$FF_CFG_CONF --cross-prefix=$CROSS_PREFIX"
FF_CFG_CONF="$FF_CFG_CONF --sysroot=$PLATFORM"!
然后是你要的格式要动态库还是静态库 :
# FF_CFG_CONF="$FF_CFG_CONF --enable-shared" // 编译成动态库 .so
FF_CFG_CONF="$FF_CFG_CONF --enable-static"//编译成静态库.a !!!
注意的是:你可以在源码目录下面,打开shell 执行 ./configure --help 上面有队每个配置的说明,也不多好像就20多个!!
下面还有个脚本,主要为了方便 ,先看脚本
UNI_BUILD_ROOT=`pwd`
FF_TARGET=$1
set -e
set +x
FF_ACT_ARCHS_32="armv5 armv7a x86"
FF_ACT_ARCHS_64="armv5 armv7a arm64 x86 x86_64"
FF_ACT_ARCHS_ALL=$FF_ACT_ARCHS_64
echo_archs() {
echo "===================="
echo "[*] check archs"
echo "===================="
echo "FF_ALL_ARCHS = $FF_ACT_ARCHS_ALL"
echo "FF_ACT_ARCHS = $*"
echo ""
}
echo_usage() {
echo "Usage:"
echo " compile-x264.sh armv5|armv7a|arm64|x86|x86_64"
echo " compile-x264.sh all|all32"
echo " compile-x264.sh all64"
echo " compile-x264.sh clean"
echo " compile-x264.sh check"
exit 1
}
echo_nextstep_help() {
#----------
echo ""
echo "--------------------"
echo "[*] Finished"
echo "--------------------"
echo "# to continue to build ffmpeg, run script below,"
echo "sh compile-ffmpeg.sh "
echo "# to continue to build ijkplayer, run script below,"
echo "sh compile-ijk.sh "
}
#----------
case "$FF_TARGET" in
"")
echo_archs armv7a
sh tools/do-compile-x264.sh armv7a
;;
armv5|armv7a|arm64|x86|x86_64)
echo_archs $FF_TARGET
sh tools/do-compile-x264.sh $FF_TARGET
echo_nextstep_help
;;
all32)
echo_archs $FF_ACT_ARCHS_32
for ARCH in $FF_ACT_ARCHS_32
do
sh tools/do-compile-x264.sh $ARCH
done
echo_nextstep_help
;;
all|all64)
echo_archs $FF_ACT_ARCHS_64
for ARCH in $FF_ACT_ARCHS_64
do
sh tools/do-compile-x264.sh $ARCH
done
echo_nextstep_help
;;
clean)
echo_archs FF_ACT_ARCHS_64
for ARCH in $FF_ACT_ARCHS_ALL
do
if [ -d x264-$ARCH ]; then
cd x264-$ARCH && cd -
fi
done
rm -rf ./build/x264-*
;;
check)
echo_archs FF_ACT_ARCHS_ALL
;;
*)
echo_usage
exit 1
;;
esac
这个脚本也是仿照ijkplayer 里面的脚本写的,很简单 一句命令:
sh tools/do-compile-x264.sh armv7a
注意一点,就是这个脚本会调用第一个脚本路径一定要配对!!!还有一个脚本就更简单了!!
export ANDROID_NDK=/Users/cievon/Documents/AndroidSDK/android-ndk-r10e/
cd contrib
FF_ARCH=$1
./compile-x264.sh $FF_ARCH
把这几行生成一个脚本,里面会去调用上面第二个脚本,后面可以指定参数!如我的这个脚本名字 compile.sh
到这个目录下面执行 :结果会编译出所有五个平台的 include 和 lib
./compile.sh all ```
./compile.sh all32 或者 ./compile.sh arm64
很简单! !! 其实这三个脚本只是为了方便编译多平台的时候参数配置麻烦,如果大家一下子不明白,可以参考我的上篇日记 https://www.jianshu.com/p/67b733fcded0, 每一个平台搞一套源码目录,里面新建对应的平台脚本,然后执行: ./(你的脚本名称),也能生成你的 头文件,库文件,pc文件,都在源码的当前目录下,用的时候,你需要手动copy到你用的地方去!!! 容易理解,但是效率太低!!!!
欢迎FFmpeg大神 戳我liugstick@163.com!!!!!