编译ffmpeg和x264吃了不少苦,很重要的一点就是如果你对这个编译不是很熟的话千万不要尝试用cygdrive+windows编译。建议在Ubuntu下编译!
1.首先要确保已经编译了x264的源码
这边是我x264的sh
export NDK=/home/mtb0157/workspace/android-ndk-r9 export PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64 export CC=$PREBUILT/bin/arm-linux-androideabi-gcc export LD=$PREBUILT/bin/arm-linux-androideabi-ld export AS=$PREBUILT/bin/arm-linux-androideabi-gcc export AR=$PREBUILT/bin/arm-linux-androideabi-ar export RANLIB=$PREBUILT/bin/arm-linux-androideabi-ranlib export STRIP=$PREBUILT/bin/arm-linux-androideabi-strip export PLATFORM=$NDK/platforms/android-8/arch-arm export PREFIX=/home/mtb0157/Project/lib export STRIP=$PREBUILT/bin/arm-linux-androideabi-strip ./configure --prefix=$PREFIX \ --enable-static \ --enable-pic \ --enable-strip \ --disable-cli \ --extra-cflags= "-march=armv7-a -mfloat-abi=softfp -mfpu=neon" \ #这个没啥用 --host=arm-linux \ --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \ --sysroot=$PLATFORM
于是我用上面的.sh定义我的
PREFIX=/home/mtb0157/Project/libx264编译完后 make install 就可以把库导到上面的目录了
3.在ffmpeg的sh里面加入额外的库和头文件
下面是我的sh
#!/bin/bash NDK=/home/mtb0157/workspace/android-ndk-r9 SYSROOT=$NDK/platforms/android-9/arch-arm/ TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64 export PLATFORM=$NDK/platforms/android-8/arch-arm export PREFIX=/home/mtb0157/Project/lib function build_one { ./configure --prefix=$PREFIX\ --disable-doc \ --enable-gpl \ --enable-libx264 \ --disable-symver \ --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \ --target-os=linux \ --arch=arm \ --enable-cross-compile \ --sysroot=$PLATFORM \ --extra-cflags=-I/home/mtb0157/Project/lib/include \ --extra-ldflags=-L/home/mtb0157/Project/lib/lib } CPU=arm PREFIX=$(pwd)/android/$CPU ADDI_CFLAGS="-marm" build_one
这边指定了之前我导出的x264的库
--extra-cflags=-I/home/mtb0157/Project/lib/include \ --extra-ldflags=-L/home/mtb0157/Project/lib/lib