第一步 下载最新版的x264
ftp://ftp.videolan.org/pub/videolan/x264/snapshots/
1.解压到指定的目录
2.切换当前目录为该目录
3.创建一个shell脚本build_x264.sh,内容如下:
export NDK=/home/robin/桌面/android-ndk-r8c
export PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt
export PLATFORM=$NDK/platforms/android-8/arch-arm
export PREFIX=/home/robin/android-x264
./configure --prefix=$PREFIX \
--enable-static \
--enable-pic \
--disable-asm \
--disable-cli \
--host=arm-linux \
--cross-prefix=$PREBUILT/linux-x86/bin/arm-linux-androideabi- \
--sysroot=$PLATFORM
第二步 修改x264的configure
libpthread=""
if [ "$thread" = "auto" ]; then
thread="no"
case $SYS in
BEOS)
thread="beos"
define HAVE_BEOSTHREAD
;;
WINDOWS)
if cc_check pthread.h -lpthread "pthread_create(0,0,0,0);" ; then
thread="posix"
libpthread="-lpthread"
elif cc_check pthread.h -lpthreadGC2 "pthread_create(0,0,0,0);" ; then
thread="posix"
libpthread="-lpthreadGC2"
elif cc_check pthread.h "-lpthreadGC2 -lwsock32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
thread="posix"
libpthread="-lpthreadGC2 -lwsock32"
define PTW32_STATIC_LIB
elif cc_check pthread.h "-lpthreadGC2 -lws2_32 -DPTW32_STATIC_LIB" "pthread_create(0,0,0,0);" ; then
thread="posix"
libpthread="-lpthreadGC2 -lws2_32"
define PTW32_STATIC_LIB
else
# default to native threading if pthread-win32 is unavailable
thread="win32"
fi
;;
QNX)
cc_check pthread.h -lc && thread="posix" && libpthread="-lc"
;;
*)
cc_check pthread.h -lc && thread="posix" && libpthread="-lc"
;;
esac
fi
改为红色行的内容,因为android的ndk虽然有pthread.h,但是没有libpthread.a,集成到libc.a里了
第三步 修改x264/common/cpu.c
int getNrOfCPUs()
{
FILE* fp;
int res, i = -1, j = -1;
/* open file */
fp = fopen("/sys/devices/system/cpu/present", "r");
if (fp == 0)
{
return -1; /* failure */
}
/* read and interpret line */
res = fscanf(fp, "%d-%d", &i, &j);
/* close file */
fclose(fp);
/* interpret result */
if (res == 1 && i == 0) /* single-core? */
{
return 1;
}
if (res == 2 && i == 0) /* 2+ cores */
{
return j+1;
}
return 1; /* failure */
}
int x264_cpu_num_processors( void )
{
return getNrOfCPUs();
}
第四步 编译
chmod 777 build_x264.sh
./build_x264.sh
make
sudo make install
sudo ldconfig
platform: ARM
system: LINUX
cli: yes
libx264: internal
shared: no
static: no
asm: yes
interlaced: yes
avs: avxsynth
lavf: no
ffms: no
gpac: no
gpl: yes
thread: posix
opencl: yes
filters: crop select_every
debug: no
gprof: no
strip: no
PIC: no
visualize: no
bit depth: 8
chroma format: all
可以看到
thread: posix,已经支持多线程了