一:准備工作
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