系统是Ubuntu 16.04 LTS,x264 和 fdk-aac 都是当前的最新版,FFmpeg是2.8.8,使用的NDK 版本是r10e
主要参考自http://blog.chinaunix.net/uid-26000296-id-5213411.html 和http://www.itnose.net/detail/6219672.html、http://zhangcb666.blog.163.com/blog/static/46963529201392362743670/
我的目录结构是
生成的库文件和头文件最终会根据prefix的指定,在make install之后被放置到各个android目录下
arm的 x264 的config.sh
export NDK=/home/pan/Downloads/android-ndk-r10e export SYSROOT=$NDK/platforms/android-9/arch-arm/ export TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64 function build_one { ./configure \ --prefix=$PREFIX \ --enable-static \ --enable-shared \ --enable-pic \ --disable-asm \ --enable-strip \ --host=arm-linux-androideabi \ --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \ --sysroot=$SYSROOT \ --extra-cflags="-Os -fpic $ADDI_CFLAGS" \ --extra-ldflags="$ADDI_LDFLAGS" \ $ADDITIONAL_CONFIGURE_FLAG } cpu=arm PREFIX=$(pwd)/android/$cpu ADDI_CFLAGS="" build_one
arm的fdk-aac 的config.sh
#!/bin/sh export NDK_HOME=/home/pan/Downloads/android-ndk-r10e ANDROID_API=android-14 SYSROOT=$NDK_HOME/platforms/$ANDROID_API/arch-arm ANDROID_BIN=$NDK_HOME/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/ CROSS_COMPILE=${ANDROID_BIN}/arm-linux-androideabi- export PATH=$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools ARM_INC=$SYSROOT/usr/include ARM_LIB=$SYSROOT/usr/lib LDFLAGS=" -nostdlib -Bdynamic -Wl,--whole-archive -Wl,--no-undefined -Wl,-z,noexecstack -Wl,nocopyreloc -Wl,-soname,/system/lib/libz.so -Wl,-rpath-link=$ARM_LIB,-dynamic-linker=/system/bin/linker -L$NDK_HOME/sources/cxx-stl/gnu-libstdc++/libs/armeabi -L$NDK_HOME/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/arm-linux-androideabi/lib -L$ARM_LIB -lc -lgcc -lm -ldl " FLAGS="--host=arm-linux-androideabi --enable-static --disable-shared" export CXX="${CROSS_COMPILE}g++ --sysroot=${SYSROOT}" export LDFLAGS="$LDFLAGS" export CC="${CROSS_COMPILE}gcc --sysroot=${SYSROOT}" cpu=arm ./configure $FLAGS \ --prefix=$(pwd)/android/$cpu
arm的FFmpeg 的config.sh
export NDK=/home/pan/Downloads/android-ndk-r10e export SYSROOT=$NDK/platforms/android-14/arch-arm/ export TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64 export TMPDIR=/home/pan/Downloads/tmp function build_one { ./configure \ --prefix=$PREFIX \ --enable-shared \ --disable-static \ --disable-doc \ --disable-ffserver \ --disable-asm \ --enable-gpl \ --enable-libx264 \ --enable-libfdk-aac \ --enable-cross-compile \ --enable-nonfree \ --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \ --target-os=linux \ --arch=arm \ --sysroot=$SYSROOT \ --extra-cflags="-Os -fpic $ADDI_CFLAGS" \ --extra-ldflags="$ADDI_LDFLAGS" \ $ADDITIONAL_CONFIGURE_FLAG } cpu=arm PREFIX=$(pwd)/android/$cpu ADDI_CFLAGS="-marm -I/home/pan/Downloads/x264/android/arm/include -I/home/pan/Downloads/fdk-aac/android/arm/include -DANDROID " ADDI_LDFLAGS="-L/home/pan/Downloads/x264/android/arm/lib -L/home/pan/Downloads/fdk-aac/android/arm/lib" build_one
以上路径需要根据自己的目录结构进行修改,尤其是FFmpeg的config.sh,ADDI_CFLAGS 和 ADDI_LDFLAGS 分别指定了 x264 和 fdk-aac 的头文件和库文件的路径。
注意:
1.如果需要去掉生成库的版本号,可以参考这篇文章——http://www.itnose.net/detail/6219672.html;
x86的 x264 的config.sh:
export NDK=/home/pan/Downloads/android-ndk-r10e export SYSROOT=$NDK/platforms/android-9/arch-x86/ export TOOLCHAIN=$NDK/toolchains/x86-4.8/prebuilt/linux-x86_64 function build_one { ./configure \ --prefix=$PREFIX \ --enable-static \ --enable-shared \ --enable-pic \ --disable-asm \ --enable-strip \ --host=i686-linux-android \ --cross-prefix=$TOOLCHAIN/bin/i686-linux-android- \ --sysroot=$SYSROOT \ --extra-cflags="-Os -fpic $ADDI_CFLAGS" \ --extra-ldflags="$ADDI_LDFLAGS" \ $ADDITIONAL_CONFIGURE_FLAG } cpu=x86 PREFIX=$(pwd)/android/$cpu ADDI_CFLAGS="" build_one
x86的 fdk-aac 的config.sh
#!/bin/sh export NDK_HOME=/home/pan/Downloads/android-ndk-r10e ANDROID_API=android-14 SYSROOT=$NDK_HOME/platforms/$ANDROID_API/arch-x86 ANDROID_BIN=$NDK_HOME/toolchains/x86-4.8/prebuilt/linux-x86_64/bin/ CROSS_COMPILE=${ANDROID_BIN}/i686-linux-android- export PATH=$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools ARM_INC=$SYSROOT/usr/include ARM_LIB=$SYSROOT/usr/lib LDFLAGS=" -nostdlib -Bdynamic -Wl,-dynamic-linker=/system/bin/linker -L$NDK_HOME/sources/cxx-stl/gnu-libstdc++/libs/x86 -L$NDK_HOME/toolchains/x86-4.8/prebuilt/linux-x86_64/i686-linux-android/lib -L$ARM_LIB -lc -lgcc -lm -ldl " FLAGS="--host=i686-linux-android --enable-static --disable-shared" export CXX="${CROSS_COMPILE}g++ --sysroot=${SYSROOT}" export LDFLAGS="$LDFLAGS" export CC="${CROSS_COMPILE}gcc --sysroot=${SYSROOT}" cpu=x86 ./configure $FLAGS \ --prefix=$(pwd)/android/$cpu
x86的 ffmpeg 的 config.sh
export NDK=/home/pan/Downloads/android-ndk-r10e export SYSROOT=$NDK/platforms/android-14/arch-x86/ export TOOLCHAIN=$NDK/toolchains/x86-4.8/prebuilt/linux-x86_64 export TMPDIR=/home/pan/Downloads/tmp function build_one { ./configure \ --prefix=$PREFIX \ --enable-shared \ --disable-static \ --disable-doc \ --disable-ffserver \ --disable-asm \ --enable-gpl \ --enable-libx264 \ --enable-libfdk-aac \ --enable-cross-compile \ --enable-nonfree \ --cross-prefix=$TOOLCHAIN/bin/i686-linux-android- \ --target-os=linux \ --arch=x86 \ --sysroot=$SYSROOT \ --extra-cflags="-Os -fpic $ADDI_CFLAGS" \ --extra-ldflags="$ADDI_LDFLAGS" \ $ADDITIONAL_CONFIGURE_FLAG } cpu=x86 PREFIX=$(pwd)/android/$cpu ADDI_CFLAGS="-I/home/pan/Downloads/x264/android/x86/include -I/home/pan/Downloads/fdk-aac/android/x86/include -DANDROID " ADDI_LDFLAGS="-L/home/pan/Downloads/x264/android/x86/lib -L/home/pan/Downloads/fdk-aac/android/x86/lib" build_one
3.目前这种方法生成的是多个带版本号的so,也可以通过写一个Bash将它们打包为一个ffmpeg.so方便调用。
如图: