x264是一种免费的、具有更优秀算法的H.264/MPEG-4 AVC视频压缩编码格式。它同xvid一样都是开源项目,但x264是采用H.264标准的,而xvid是采用MPEG-4早期标准的。由于H.264是2003年正式发布的最新的视频编码标准,因此,在通常情况下,x264压缩出的视频文件在相同质量下要比xvid压缩出的文件要小,或者也可以说,在相同体积下比xvid压缩出的文件质量要好。它符合GPL许可证。
x264在视频应用中经常使用,很多github上的项目都使用该编码,我这里只是讲一下如何在linux上编译它,并为Android NDK调用服务,你可以按照以下步骤来进行:
1. 安装Android NDK(我安装的是android-ndk-r10c-linux-x86_64.bin);
2. 下载x264:
git clone git:
//git.videolan.org
/x264.git
export NDK_SYSROOT= /opt /ndk /platforms /android- 9 /arch-arm
export PATH= $PATH: /opt /ndk /toolchains /arm-linux-androideabi- 4.6 /prebuilt /linux-x86_64 /bin /
. /configure --cross-prefix=arm-linux-androideabi- \
--sysroot= "$NDK_SYSROOT" --host=arm-linux \
--enable-pic --enable-static --disable-cli
. / make STRIP=
export NDK_SYSROOT= /opt /ndk /platforms /android- 9 /arch-arm
export PATH= $PATH: /opt /ndk /toolchains /arm-linux-androideabi- 4.6 /prebuilt /linux-x86_64 /bin /
. /configure --cross-prefix=arm-linux-androideabi- \
--sysroot= "$NDK_SYSROOT" --host=arm-linux \
--enable-pic --enable-static --disable-cli
. / make STRIP=
以上片段中有很多参数,特别配置时的参数,我们来聊一下:
–sysroot
--sysroot="Android/ndk/platforms/$ANDROID_API_VERSION/arch-arm"
#sysroot option provides the logical root directory for
headers and libraries. This is useful when you don’t
want the headers/libraries in the standard paths
affect your build. As we want to use Android cross
compiler so we need to set the path of Android cross
compiler as sysroot.
当我们在进行跨平台编译时,为了不使我们的编译受当前平台的影响,
我们指定跨平台编译的头文件和库。
#sysroot option provides the logical root directory for
headers and libraries. This is useful when you don’t
want the headers/libraries in the standard paths
affect your build. As we want to use Android cross
compiler so we need to set the path of Android cross
compiler as sysroot.
当我们在进行跨平台编译时,为了不使我们的编译受当前平台的影响,
我们指定跨平台编译的头文件和库。
–cross-prefix
--cross-prefix=arm-linux-androideabi-
#cross prefix used for locating compilation
tools in PATH env variable e.g in place of
gcc it will use arm-linux-androideabi-gcc
指定跨平台的编译器而不是linux默认的gcc或者你指定的其它编译器,因为我们是编译android平台
#cross prefix used for locating compilation
tools in PATH env variable e.g in place of
gcc it will use arm-linux-androideabi-gcc
指定跨平台的编译器而不是linux默认的gcc或者你指定的其它编译器,因为我们是编译android平台
–host
--host=arm-linux
#host system for which we are compiling.
Here we are compiling for 2 different Android
architectures namely armv7 and armv7-a neon
#host system for which we are compiling.
Here we are compiling for 2 different Android
architectures namely armv7 and armv7-a neon
–enable-pic
--enable-pic
#position-independent code commonly used for shared libraries
#position-independent code commonly used for shared libraries
–enable-static
--enable-static
#build static library
#build static library
–disable-cli
--disable-cli
#disable cli
#disable cli
编译参数
STRIP
# delete local/anonymous symbols,
so they don't show up in oprofile
# delete local/anonymous symbols,
so they don't show up in oprofile
3. 将编译好的libx264.a,x264.h和x264_config.h三个文件防盗jni对应的位置,然后在Android.mk里进行配置;
还好我用的linux,看看那些windows的,比较麻烦,不过习惯就好了。