简体   繁体   English

使用x264 for Android构建FFMPEG

[英]Build FFMPEG with x264 for Android

I am trying to build FFMPEG with libx264 for Android. 我正在尝试使用libx264为Android构建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. 我可以成功构建和使用FFMPEG for Android但我意识到我需要编码的能力,因此我试图用x264构建FFMPEG。

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

When trying to build FFMPEG I get an error: 在尝试构建FFMPEG时出现错误:

"ERROR: libx264 not found" “错误:未找到libx264”

And in my log it says: 在我的日志中它说:

"/usr/local/lib/libx264.a: could not read symbols: Archive has no index; run ranlib to add one..." “/usr/local/lib/libx264.a:无法读取符号:存档没有索引;运行ranlib添加一个...”

I have the latest versions of both FFMPEG and x264. 我有FFMPEG和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: 我知道FFMPEG在usr / lib和usr / include中查找头文件和库,所以为了使它找到x264我使用cflags和ldflags:

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

I have tried building x264 with many different options that other people on the internet have said that i need. 我尝试构建x264,其中有许多不同的选项,互联网上的其他人都说我需要。 eg. 例如。 --enable-shared, --enable-static, --disable-pthreads etc. Some forums say enable this, others say no disable that. --enable-shared, - enable-static, - disable-pthreads等。有些论坛说启用这个,其他人说没有禁用它。

Any help would be much appreciated, Thanks 任何帮助将不胜感激,谢谢

EDIT: 编辑:

If I build FFmpeg with the simplest commands to include libx264 then it works. 如果我使用最简单的命令构建FFmpeg以包含libx264,那么它可以工作。 ie. 即。

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

However I need it to work for Android. 但是我需要它适用于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

I am guessing that some option in my configure command is conflicting with enabling libx264 我猜我的configure命令中的一些选项与启用libx264冲突

NOTE: If I remove --enable-libx264 then it works 注意:如果我删除--enable-libx264然后它工作

I had the same problem. 我有同样的问题。 But after downgrading NDK to version 5c it works as described by halfninja. 但在将NDK降级到版本5c之后,它的工作方式与halfninja所描述的相同。 (ubuntu 64bit). (ubuntu 64bit)。 there seem to be some changes in the toolchain from 5 to 7. 工具链似乎有一些从5到7的变化。

timo@serverplusplus:/tmp/android-ffmpeg-x264/Project/jni$ ndk-build 
Compile thumb  : ffmpeg <= ffmpeg.c
Compile thumb  : ffmpeg <= cmdutils.c
Executable     : ffmpeg
Install        : ffmpeg => libs/armeabi/ffmpeg
Compile thumb  : videokit <= uk_co_halfninja_videokit_Videokit.c
Compile thumb  : videokit <= ffmpeg.c
Compile thumb  : videokit <= cmdutils.c
SharedLibrary  : libvideokit.so
Install        : libvideokit.so => libs/armeabi/libvideokit.so

The ffmpeg source code seems to be updated, and I could compile ffmpeg with x264 for Android NDK as the following. ffmpeg源代码似乎已更新,我可以使用x264为Android NDK编译ffmpeg,如下所示。

1 Download the halfninja's android-ffmpeg-x264 git file from https://github.com/halfninja/android-ffmpeg-x264 1从https://github.com/halfninja/android-ffmpeg-x264下载halfninja的android-ffmpeg-x264 git文件

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". 2在“halfninja-android-ffmpeg-x264-fe12be0 / Project / jni”目录中,修改“configure_ffmpeg.sh”以链接“libgcc.a”以解决无法解析“__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 Modify "Android.mk" to link new library "libswresample.a". 3修改“Android.mk”以链接新库“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 Replace ffmpeg.c and cmdutils.c in videokit directory with ones in ffmpeg directory. 4将vidempit目录中的ffmpeg.c和cmdutils.c替换为ffmpeg目录中的ffmpeg.c和cmdutils.c。

5 Follow a procedure described in README.textile. 5按照README.textile中描述的步骤进行操作。

I've put together a Android build system for ffmpeg+x264 here: https://github.com/guardianproject/android-ffmpeg 我在这里为ffmpeg + x264组建了一个Android构建系统: https//github.com/guardianproject/android-ffmpeg

We're working on some wrapper Java too for running it, but that's not really usable yet. 我们正在开发一些包装Java来运行它,但那还不是真的可用。

These are my working flags: 这些是我的工作标志:

x264 (a recent stable): x264(最近稳定):

./configure --cross-prefix=arm-linux-androideabi- \
--enable-pic \
--enable-static \
--disable-cli \
--disable-asm \
--host=arm-linux

ffmpeg (release/0.10): ffmpeg(发布/0.10):

./configure --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-gcc \
--extra-cflags="-fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated" \
--disable-everything \
--enable-decoder=h264 \
--enable-demuxer=mov \
--enable-muxer=mp4 \
--enable-encoder=libx264 \
--enable-libx264 \
--enable-protocol=file \
--enable-decoder=aac \
--enable-encoder=aac \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-network \
--enable-filter=buffer \
--enable-filter=buffersink \
--enable-filter=scale \
--disable-demuxer=v4l \
--disable-demuxer=v4l2 \
--disable-indev=v4l \
--disable-indev=v4l2 \
--extra-cflags="-I../x264" \
--extra-ldflags="-L../x264" \
--extra-libs="-lgcc"

Obviously you will have to adjust the paths. 显然你必须调整路径。

I have met the same issue before, and I tried several times to find out the reason: 我以前遇到过同样的问题,我多次尝试找出原因:

You must make sure the x264 and the ffmpeg are using same way to compile. 您必须确保x264和ffmpeg使用相同的方式进行编译。 like: using Android NDK. 喜欢:使用Android NDK。 Using the same gcc compiler. 使用相同的gcc编译器。

So you can not compile ffmpeg with this command:"--cross-prefix=$PREBUILT/darwin-x86_64/bin/arm-linux-androideabi-", but compile the x264 without that. 所以你不能用这个命令编译ffmpeg:“ - cross-prefix = $ PREBUILT / darwin-x86_64 / bin / arm-linux-androideabi-”,但是没有它就编译x264。 Here is my x264 compile script: 这是我的x264编译脚本:

./configure --prefix=$PREFIX \
--enable-static \
--enable-pic \
--disable-asm \
--disable-cli \
--host=arm-linux \
--cross-prefix=$PREBUILT/darwin-x86_64/bin/arm-linux-androideabi- \
--sysroot=$PLATFORM

make
sudo make install
sudo ldconfig

I've discovered the --enable-static option does not have any effect on ffmpeg linking behaviour for libx264. 我发现--enable-static选项对libx264的ffmpeg链接行为没有任何影响。 I managed to build a copy of ffmpeg with libx264 included statically by editing the config.mak after I'd run ./configure 我设法通过在运行后编辑config.mak来静态包含libx264来构建ffmpeg的副本./configure

  • Build x264 from source in another directory 从另一个目录中的源构建x264
  • Add libx264.a to EXTRALIBS line in config.mak 将libx264.a添加到config.mak中的EXTRALIBS行
  • Remove -lx264 from EXTRALIBS line in config.mak 从config.mak中的EXTRALIBS行中删除-lx264

Before 之前

EXTRALIBS=-ldl -lX11 -lx264 etc.

After

EXTRALIBS=/home/adam/x264sourcebuild/libx264.a -ldl -lX11  etc.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM