使用 x264 为 Android 构建 FFMPEG [英] Build FFMPEG with x264 for Android

查看:37
本文介绍了使用 x264 为 Android 构建 FFMPEG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 libx264 for Android 构建 FFMPEG.

I am trying to build FFMPEG with libx264 for Android.

我可以成功构建和使用适用于 Android 的 FFMPEG,但我意识到我需要编码能力,因此我正在尝试使用 x264 构建 FFMPEG.

I can successfully build and use FFMPEG for Android but I realized that I need the ability to encode, therefore I am trying to build FFMPEG with x264.

我正在使用本教程为 Android 构建 FFmpeg http://www.roman10.net/how-to-build-ffmpeg-for-android/

I am using this tutorial to build FFmpeg for Android http://www.roman10.net/how-to-build-ffmpeg-for-android/

在尝试构建 FFMPEG 时出现错误:

When trying to build FFMPEG I get an error:

错误:找不到 libx264"

"ERROR: libx264 not found"

在我的日志中它说:

"/usr/local/lib/libx264.a:无法读取符号:存档没有指数;运行ranlib添加一个..."

"/usr/local/lib/libx264.a: could not read symbols: Archive has no index; run ranlib to add one..."

我有最新版本的 FFMPEG 和 x264.我知道 FFMPEG 在 usr/lib 和 usr/include 中寻找头文件和库,所以为了让它找到 x264,我使用了 cflags 和 ldflags:

I have the latest versions of both FFMPEG and x264. I understand that FFMPEG looks for the header and libraries in usr/lib and usr/include, so in order to make it find x264 I use the cflags and ldflags:

  • --extra-cflags = " -I/usr/local/include "
  • --extra-ldflags = "-L/usr/local/lib"

我尝试使用互联网上其他人说我需要的许多不同选项来构建 x264.例如.--enable-shared、--enable-static、--disable-pthreads 等.有的论坛说启用这个,其他的说不禁用那个.

I have tried building x264 with many different options that other people on the internet have said that i need. eg. --enable-shared, --enable-static, --disable-pthreads etc. Some forums say enable this, others say no disable that.

任何帮助将不胜感激,谢谢

Any help would be much appreciated, Thanks

如果我使用包含 libx264 的最简单命令构建 FFmpeg,那么它可以工作.即.

If I build FFmpeg with the simplest commands to include libx264 then it works. ie.

./configure --enable-gpl --enable-libx264 --extra-cflags="-I/usr/local/include" --extra-ldflags="-L/usr/local/lib" --enable-static --enable-shared

但是我需要它才能在 Android 上工作.我使用的脚本是:

However I need it to work for Android. The script I am using is:

NDK=~/Desktop/android-ndk-r7
PLATFORM=$NDK/platforms/android-8/arch-arm/
PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86
function build_one
{
./configure --target-os=linux 
    --prefix=$PREFIX 
    --enable-cross-compile 
    --enable-shared 
    --enable-static 
    --extra-libs="-lgcc" 
    --arch=arm 
    --cc=$PREBUILT/bin/arm-linux-androideabi-gcc 
    --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- 
    --nm=$PREBUILT/bin/arm-linux-androideabi-nm 
    --sysroot=$PLATFORM 
    --extra-cflags=" -O3 -fpic -DANDROID -DHAVE_SYS_UIO_H=1 -Dipv6mr_interface=ipv6mr_ifindex -fasm -Wno-psabi -fno-short-enums -fno-strict-aliasing -finline-limit=300 $OPTIMIZE_CFLAGS -I/usr/local/include" 
    --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L $PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog -L/usr/local/lib " 
    --enable-gpl 
    --enable-libx264 
    --disable-everything 
    --enable-demuxer=mov 
    --enable-demuxer=h264 
    --disable-ffplay 
    --enable-protocol=file 
    --enable-avformat 
    --enable-avcodec 
    --enable-decoder=rawvideo 
    --enable-decoder=mjpeg 
    --enable-decoder=h263 
    --enable-decoder=mpeg4 
    --enable-decoder=h264 
    --enable-encoder=mjpeg 
    --enable-encoder=h263 
    --enable-encoder=mpeg4 
    --enable-encoder=h264 
    --enable-parser=h264 
    --disable-network 
    --enable-zlib 
    --disable-avfilter 
    --disable-avdevice 
    $ADDITIONAL_CONFIGURE_FLAG

make clean
make  -j4 install
$PREBUILT/bin/arm-linux-androideabi-ar d libavcodec/libavcodec.a inverse.o
$PREBUILT/bin/arm-linux-androideabi-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib  -soname libffmpeg.so -shared -nostdlib  -z,noexecstack -Bsymbolic --whole-archive --no-undefined -o $PREFIX/libffmpeg.so libavcodec/libavcodec.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog  --warn-once  --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a
}

CPU=armv7-a
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU "
PREFIX=./android/$CPU
ADDITIONAL_CONFIGURE_FLAG=
build_one

我猜我的配置命令中的某些选项与启用 libx264 冲突

I am guessing that some option in my configure command is conflicting with enabling libx264

注意:如果我删除 --enable-libx264 那么它可以工作

NOTE: If I remove --enable-libx264 then it works

推荐答案

ffmpeg源码好像更新了,我可以用x264编译ffmpeg for Android NDK如下.

The ffmpeg source code seems to be updated, and I could compile ffmpeg with x264 for Android NDK as the following.

1 从 https://github.com/下载 halfninja 的 android-ffmpeg-x264 git 文件halfninja/android-ffmpeg-x264

2 在halfninja-android-ffmpeg-x264-fe12be0/Project/jni"目录下,修改configure_ffmpeg.sh"链接libgcc.a",解决__aeabi_f2uiz"无法解决的问题.

2 At "halfninja-android-ffmpeg-x264-fe12be0/Project/jni" directory, modify "configure_ffmpeg.sh" to link "libgcc.a" for solving a problem that can not resolve "__aeabi_f2uiz".

./configure $DEBUG_FLAG --enable-cross-compile 
--arch=arm5te 
--enable-armv5te 
--target-os=linux 
--disable-stripping 
--prefix=../output 
--disable-neon 
--enable-version3 
--disable-shared 
--enable-static 
--enable-gpl 
--enable-memalign-hack 
--cc=arm-linux-androideabi-gcc 
--ld=arm-linux-androideabi-ld 
--extra-cflags="-fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated -I../x264 -Ivideokit" 
 $featureflags 
--disable-ffmpeg 
--disable-ffplay 
--disable-ffprobe 
--disable-ffserver 
--disable-network 
--enable-filter=buffer 
--enable-filter=buffersink 
--disable-demuxer=v4l 
--disable-demuxer=v4l2 
--disable-indev=v4l 
--disable-indev=v4l2 
--extra-ldflags="-L../x264 -L../toolchain/lib/gcc/arm-linux-androideabi/4.4.3" 
--extra-libs="-lgcc"

3 修改Android.mk"以链接新库libswresample.a".

3 Modify "Android.mk" to link new library "libswresample.a".

FFMPEG_LIBS := $(addprefix ffmpeg/, 
 libavdevice/libavdevice.a 
 libavformat/libavformat.a 
 libavcodec/libavcodec.a 
 libavfilter/libavfilter.a 
 libswscale/libswscale.a 
 libavutil/libavutil.a 
 libswresample/libswresample.a 
 libpostproc/libpostproc.a )

4 将videokit目录下的ffmpeg.c和cmdutils.c替换成ffmpeg目录下的.

4 Replace ffmpeg.c and cmdutils.c in videokit directory with ones in ffmpeg directory.

5 遵循 README.textile 中描述的程序.

5 Follow a procedure described in README.textile.

这篇关于使用 x264 为 Android 构建 FFMPEG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆