Ubuntu下 Android NDK 编译 FFmpeg + x264 + fdk-aac (arm/x86)的配置脚本
系统是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,-z,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;
2.如果要生成非arm架构的库,也需要做对应修改;
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,--whole-archive -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,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/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方便调用。
如图:
文章来源: panda1234lee.blog.csdn.net,作者:panda1234lee,版权归原作者所有,如需转载,请联系作者。
原文链接:panda1234lee.blog.csdn.net/article/details/53099203
- 点赞
- 收藏
- 关注作者
评论(0)