加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

Windows系统下编译FFmpeg for Android(支持x264)

发布时间:2020-12-14 02:37:32 所属栏目:Windows 来源:网络整理
导读:接上一篇:https://www.cnblogs.com/zuoao123/p/10253690.html 上次编译的FFmpeg在使用上有点问题,mediacodec软解码解码器打开失败,avcodec_open2()返回错误值-1。因此想编译一个支持x264的FFmpeg试试看。 一、编译x264 1、下载并解压x264 下载地址: http

接上一篇:https://www.cnblogs.com/zuoao123/p/10253690.html
上次编译的FFmpeg在使用上有点问题,mediacodec软解码解码器打开失败,avcodec_open2()返回错误值-1。因此想编译一个支持x264的FFmpeg试试看。

一、编译x264

1、下载并解压x264

下载地址:
https://www.videolan.org/developers/x264.html


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

2、修改configure文件

将configure文件中的

if cc_check "stdio.h" "" "fseeko(stdin,0);" ; then
    define fseek fseeko
    define ftell ftello
elif cc_check "stdio.h" "" "fseeko64(stdin,0);" ; then
    define fseek fseeko64
    define ftell ftello64
elif cc_check "stdio.h" "" "_fseeki64(stdin,0);" ; then
    define fseek _fseeki64
    define ftell _ftelli64
fi

修改为

if cc_check "stdio.h" "" "fseeko(stdin,0);" ; then
    define fseek fseek
    define ftell ftell
elif cc_check "stdio.h" "" "fseeko64(stdin,0);" ; then
    define fseek fseek
    define ftell ftell
elif cc_check "stdio.h" "" "_fseeki64(stdin,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,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目录下得到需要的头文件和库文件

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读