android 编译libx264,Windows系统下编译FFmpeg for Android(支持x264)-Go语言中文社区

一、编译x264

1、下载并解压x264

下载地址:

https://www.videolan.org/developers/x264.html

322aa585dd80961cce5bbead24e23432.png

下载最新版本,解压后得到x264-snapshot-20190111-2245文件夹。

2、修改configure文件

将configure文件中的

if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then

define fseek fseeko

define ftell ftello

elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then

define fseek fseeko64

define ftell ftello64

elif cc_check "stdio.h" "" "_fseeki64(stdin,0,0);" ; then

define fseek _fseeki64

define ftell _ftelli64

fi

修改为

if cc_check "stdio.h" "" "fseeko(stdin,0,0);" ; then

define fseek fseek

define ftell ftell

elif cc_check "stdio.h" "" "fseeko64(stdin,0,0);" ; then

define fseek fseek

define ftell ftell

elif cc_check "stdio.h" "" "_fseeki64(stdin,0,0);" ; then

define fseek _fseek

define ftell _ftell

fi

否则在编译FFmpeg的时候会报以下错误:

ERROR:libx264 not found

查看FFmpeg的config.log,具体原因是

../android-lib/lib/libx264.a(encoder-8.o):encoder.c:function encoder_frame_end.part.8: error: undefined reference to 'fseeko64'

../android-lib/lib/libx264.a(opencl-8.o):opencl.c:function x264_8_opencl_lookahead_init: error: undefined reference to 'fseeko64'

../android-lib/lib/libx264.a(opencl-8.o):opencl.c:function x264_8_opencl_lookahead_init: error: undefined reference to 'ftello64'

../android-lib/lib/libx264.a(encoder-10.o):encoder.c:function encoder_frame_end.part.9: error: undefined reference to 'fseeko64'

../android-lib/lib/libx264.a(base.o):base.c:function x264_slurp_file: error: undefined reference to 'fseeko64'

../android-lib/lib/libx264.a(base.o):base.c:function x264_slurp_file: error: undefined reference to 'ftello64'

collect2.exe: error: ld returned 1 exit status

ERROR: libx264 not found

因此在这里修改x264的configure文件,杜绝编译FFmpeg不通过。(暂未发现其他解决方法)

3、在x264目录下新建build_android.sh脚本文件

文件内容如下:

#!/bin/bash

# 设置编译中临时文件目录,不然会报错 unable to create temporary file

export TMPDIR=./temp

mkdir $TMPDIR

# NDK的路径,根据实际安装位置设置

NDK=D:/Work_Files/android-ndk-r16b

# 编译针对的平台,这里选择最低支持android-23, arm架构,生成的so库是放在libs/armeabi文件夹下的,若针对x86架构,要选择arch-x86

SYSROOT=$NDK/platforms/android-23/arch-arm

# 工具链的路径,arm-linux-androideabi-4.9与上面设置的PLATFORM对应,4.9为工具的版本号

TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64

ARCH=armv7-a

PREFIX=./output/$ARCH

EXTRA_CFLAGS="-isystem $NDK/sysroot/usr/include -isystem $NDK/sysroot/usr/include/arm-linux-androideabi"

function build_one

{

./configure

--prefix=$PREFIX

--extra-cflags="$EXTRA_CFLAGS"

--enable-static

--host=arm-linux

--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi-

--sysroot=$SYSROOT

--disable-asm

--enable-pic

--disable-cli

}

build_one

4、执行build_android.sh脚本文件进行配置

./build_android.sh

5、执行make、make install命令进行编译安装

最后在D:Work_Filesx264-snapshot-20190111-2245outputarmv7-a目录下得到需要的头文件和库文件。

二、编译FFmpeg

1、修改FFmpeg的build_android.sh脚本文件

文件内容如下:

#!/bin/bash

# 设置编译中临时文件目录,不然会报错 unable to create temporary file

export TMPDIR=./temp

mkdir $TMPDIR

# NDK的路径,根据实际安装位置设置

NDK=D:/Work_Files/android-ndk-r16b

# 编译针对的平台,这里选择最低支持android-23, arm架构,生成的so库是放在libs/armeabi文件夹下的,若针对x86架构,要选择arch-x86

SYSROOT=$NDK/platforms/android-23/arch-arm

# 工具链的路径,arm-linux-androideabi-4.9与上面设置的PLATFORM对应,4.9为工具的版本号

TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64

ARCH=armv7-a

PREFIX=./output/$ARCH

EXTRA_CFLAGS="-I D:/Work_Files/x264-snapshot-20190111-2245/output/armv7-a/include -fdata-sections -ffunction-sections -fstack-protector-strong -ffast-math -fstrict-aliasing -march=$ARCH -D__ANDROID_API__=23 -isystem $NDK/sysroot/usr/include -isystem $NDK/sysroot/usr/include/arm-linux-androideabi"

EXTRA_LDFLAGS="-L D:/Work_Files/x264-snapshot-20190111-2245/output/armv7-a/lib -Wl,--gc-sections -Wl,-z,relro -Wl,-z,now"

function build_one

{

./configure

--prefix=$PREFIX

--enable-static

--disable-shared

--enable-small

--enable-runtime-cpudetect

--disable-programs

--disable-ffmpeg

--disable-ffplay

--disable-ffprobe

--disable-doc

--enable-pthreads

--disable-decoders

--enable-decoder=h264

--disable-encoders

--disable-hwaccels

--disable-parsers

--enable-parser=h264

--disable-demuxers

--disable-muxers

--disable-protocols

--disable-filters

--disable-bsfs

--disable-indevs

--disable-outdevs

--disable-v4l2_m2m

--enable-jni

--enable-gpl

--enable-libx264

--arch=$ARCH

--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi-

--enable-cross-compile

--sysroot=$SYSROOT

--target-os=android

--disable-symver

--enable-asm

--enable-neon

--extra-cflags="$EXTRA_CFLAGS"

--extra-ldflags="$EXTRA_LDFLAGS"

$ADDITIONAL_CONFIGURE_FLAG

}

build_one

2、执行build_android.sh脚本文件进行配置

./build_android.sh

3、执行make、make install命令进行编译安装

最后在D:Work_Filesffmpeg-for-androidffmpeg-3.4.5outputarmv7-a目录下得到需要的头文件和库文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值