交叉编译支持多线程的Android版X264库

本文详细介绍了如何使用x264编译工具为ARM平台的Linux系统添加多线程支持,并通过配置脚本进行安装的过程。通过修改配置文件和脚本内容,确保在Android NDK环境下正确集成线程处理库,同时提供了编译、安装的完整步骤,最终实现了x264在多核处理器上的高效运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一步 下载最新版的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,已经支持多线程了


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值