注意:這里由于本人對mac 腳本命令不熟(先簡單看了半天linux shell命令行州叠,推薦大家看這本書, Linux 運維之道,半天就上手了)拜英,本篇只是自己操作的,僅僅是個走下流程的Demo說明读串。接著上篇筆記聊记,來實現(xiàn)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 支持的平臺參數(shù)配置不同了嫁佳,看下這兩個目錄 對比下一目了然,D:\android-sdk\ndk-bundle\platforms\android-21 和 D:\android-sdk\ndk-bundle\toolchains挨队。
x264源碼編譯的配置,流程如下蒿往,配置configure 參數(shù)盛垦,執(zhí)行 ./configure ....參數(shù)內(nèi)容 ,然后 make 瓤漏,再 make install 腾夯,就得到你要的 include 和lib 目錄了!J叱洹蝶俱!腳本里面的配置 有三個必要的配置,這里呢<⒙Uゴ簟!我這里貼圖 庸队,到源碼目錄下积蜻,有個configure文件,這就是總開關了彻消,打開里面浅侨,如下圖:
是不是懵逼了!Vづ颉如输! 我建議先按照我的配置來,先編出來!不见! 有時間澳化,可以仔細看這個腳本配置。
首先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"稳吮!
然后是你要的格式要動態(tài)庫還是靜態(tài)庫 :
# FF_CFG_CONF="$FF_CFG_CONF --enable-shared" // 編譯成動態(tài)庫 .so
FF_CFG_CONF="$FF_CFG_CONF --enable-static"http://編譯成靜態(tài)庫.a 6泄取!灶似!
注意的是:你可以在源碼目錄下面列林,打開shell 執(zhí)行 ./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
注意一點,就是這個腳本會調(diào)用第一個腳本路徑一定要配對v昀痢D凼怠!還有一個腳本就更簡單了?摇甲献!
export ANDROID_NDK=/Users/cievon/Documents/AndroidSDK/android-ndk-r10e/
cd contrib
FF_ARCH=$1
./compile-x264.sh $FF_ARCH
把這幾行生成一個腳本,里面會去調(diào)用上面第二個腳本颂翼,后面可以指定參數(shù)晃洒!如我的這個腳本名字 compile.sh
到這個目錄下面執(zhí)行 :結果會編譯出所有五個平臺的 include 和 lib
./compile.sh all ```
./compile.sh all32 或者 ./compile.sh arm64
很簡單! >卫稹锥累! 其實這三個腳本只是為了方便編譯多平臺的時候參數(shù)配置麻煩缘挑,如果大家一下子不明白集歇,可以參考我的上篇日記 http://www.reibang.com/p/67b733fcded0, 每一個平臺搞一套源碼目錄语淘,里面新建對應的平臺腳本诲宇,然后執(zhí)行: ./(你的腳本名稱),也能生成你的 頭文件惶翻,庫文件姑蓝,pc文件,都在源碼的當前目錄下吕粗,用的時候纺荧,你需要手動copy到你用的地方去!!宙暇! 容易理解输枯,但是效率太低!U计丁L蚁ā!
歡迎FFmpeg大神 戳我liugstick@163.com!!!!!