一:准备工作
1、操作系统是Ubuntu 12.04。
2、需要安装Google的NDK工具,因为在编译时使用了NDK提供的编译器。我的NDK的安装目录放在/home/shallon/android-ndk-r8d。另外,需要安装android的SDK,提供ADB等调试的工具
3、下载获取X264的源码。
git clone git://git.videolan.org/x264.git
4、使用配置编译的脚本
export ARM_ROOT=/home/shallon/android-ndk-r8d
export ARM_INC=$ARM_ROOT/platforms/android-14/arch-arm/usr/include/
export ARM_LIB=$ARM_ROOT/platforms/android-14/arch-arm/usr/lib/
export ARM_TOOL=$ARM_ROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
export ARM_LIBO=$ARM_TOOL/lib/gcc/arm-linux-androideabi/4.4.3
export PATH=$ARM_TOOL/bin:$PATH
export ARM_PRE=arm-linux-androideabi
./configure --disable-gpac --enable-pic --enable-strip --extra-cflags=" -I$ARM_INC -fPIC -DANDROID -fpic -mthumb-interwork -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -march=armv7-a -mtune=cortex-a9 -mfloat-abi=softfp -mfpu=neon -D__ARM_ARCH_7__ -D__ARM_ARCH_7A__ -Wno-psabi -msoft-float -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -DANDROID -Wa,--noexecstack -MMD -MP " --extra-ldflags="-nostdlib -Bdynamic -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$ARM_LIB -nostdlib $ARM_LIB/crtbegin_dynamic.o $ARM_LIB/crtend_android.o -lc -lm -ldl -lgcc" --cross-prefix=${ARM_PRE}- --host=arm-linux --enable-static --prefix=/home/shallon/x264/build
配置关键点1:指定使用的交叉编译的编译器、链接的头文件及类库所在
配置关键点2:-march=armv7-a -mtune=cortex-a9 -mfloat-abi=softfp -mfpu=neon -D__ARM_ARCH_7__ -D__ARM_ARCH_7A__ ,此处,针对armv7-a的CPU打开了NEON的优化运行指令。
配置关键点3:去掉--disable-asm选项。该选项的意思就是禁止neon的指令。
配置关键点4:添加--enable-static选项,生成静态链接的库供程序开发使用。
5、配置运行的环境
export ARM_LINUX_ANDROIDEABI_GCC=/home/shallon/android-ndk-r8d/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin
export PATH=$ARM_LINUX_ANDROIDEABI_GCC:$PATH
6、编译
直接运行 :make
在当前目录生成x264的执行文件,以及链接的.a文件
查看x264文件的类型看看交叉编译是否成功。
shallon@shallon-Joybook-R48:~/x264$ file x264
x264: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), stripped
7、上传到nexu 7上运行,nexu 7上需要有root的权限。
shallon@shallon-Joybook-R48:~/x264$ adb push x264 /sdcard/x264
829 KB/s (509135 bytes in 0.599s)
adb shell进入nexu 7设备,将x264文件拷贝到/data/app目录下,
cd /data/app
/data/app # cp /sdcard/x264 .
8、运行x264命令
root@android:/data/app # ./x264 -o test.264 ./352x288.yuv
yuv [info]: 352x288p 0:0 @ 25/1 fps (cfr)
x264 [info]: using cpu capabilities: ARMv6 NEON
x264 [info]: profile High, level 1.3
x264 [info]: frame I:2 Avg QP:23.74 size: 4170
x264 [info]: frame P:79 Avg QP:25.20 size: 1849
x264 [info]: frame B:65 Avg QP:26.13 size: 358
x264 [info]: consecutive B-frames: 35.6% 13.7% 4.1% 46.6%
x264 [info]: mb I I16..4: 8.8% 84.8% 6.3%
x264 [info]: mb P I16..4: 4.4% 15.0% 0.8% P16..4: 44.5% 11.5% 6.5% 0.0% 0.0% skip:17.1%
x264 [info]: mb B I16..4: 0.0% 0.0% 0.0% B16..8: 40.2% 0.8% 0.2% direct: 2.5% skip:56.3% L0:43.6% L1:53.1% BI: 3.3%
x264 [info]: 8x8 transform intra:75.3% inter:91.3%
x264 [info]: coded y,uvDC,uvAC intra: 49.8% 80.8% 75.4% inter: 15.0% 22.8% 9.1%
x264 [info]: i16 v,h,dc,p: 33% 17% 4% 47%
x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 9% 16% 4% 8% 17% 6% 6% 5%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 37% 9% 10% 4% 10% 20% 4% 4% 2%
x264 [info]: i8c dc,h,v,p: 47% 22% 30% 1%
x264 [info]: Weighted P-Frames: Y:21.5% UV:6.3%
x264 [info]: ref P L0: 65.7% 15.7% 13.6% 4.7% 0.4%
x264 [info]: ref B L0: 88.1% 10.4% 1.5%
x264 [info]: ref B L1: 94.2% 5.8%
x264 [info]: kb/s:243.40
encoded 146 frames, 10.81 fps, 243.40 kb/s