用Android NDK r10编译FFmpeg 2.3

我想按照这个教程来编译FFMpeg 2.3和Android NDK r10: http ://www.roman10.net/how-to-build-ffmpeg-for-android/

得到几个错误后,我修改了这样的构build脚本:

#!/bin/bash ###################################################### # Usage: # put this script in top of FFmpeg source tree # ./build_android # It generates binary for following architectures: # ARMv6 # ARMv6+VFP # ARMv7+VFPv3-d16 (Tegra2) # ARMv7+Neon (Cortex-A8) # Customizing: # 1. Feel free to change ./configure parameters for more features # 2. To adapt other ARM variants # set $CPU and $OPTIMIZE_CFLAGS # call build_one ###################################################### NDK=/usr/local/src/android-ndk-r10 PLATFORM=$NDK/platforms/android-8/arch-arm/ PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64 function build_one { ./configure --target-os=linux \ --prefix=$PREFIX \ --enable-cross-compile \ --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 " \ --disable-shared \ --enable-static \ --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" \ --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=h265 \ --enable-decoder=mpeg4 \ --enable-decoder=h264 \ --enable-parser=h264 \ --enable-parser=h265 --enabled-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 -nostdlib,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 --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.8/libgcc.a } #arm v6 #CPU=armv6 #OPTIMIZE_CFLAGS="-marm -march=$CPU" #PREFIX=./android/$CPU #ADDITIONAL_CONFIGURE_FLAG= #build_one #arm v7vfpv3 CPU=armv7-a OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU " PREFIX=./android/$CPU ADDITIONAL_CONFIGURE_FLAG= build_one #arm v7vfp #CPU=armv7-a #OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU " #PREFIX=./android/$CPU-vfp #ADDITIONAL_CONFIGURE_FLAG= #build_one #arm v7n #CPU=armv7-a #OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon -marm -march=$CPU -mtune=cortex-a8" #PREFIX=./android/$CPU #ADDITIONAL_CONFIGURE_FLAG=--enable-neon #build_one #arm v6+vfp #CPU=armv6 #OPTIMIZE_CFLAGS="-DCMP_HAVE_VFP -mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU" #PREFIX=./android/${CPU}_vfp #ADDITIONAL_CONFIGURE_FLAG= #build_one 

但不幸的是我得到以下错误:

  INSTALL ffmpeg INSTALL ffprobe INSTALL ffserver /usr/local/src/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld: error: /usr/local/src/android-ndk-r10/platforms/android-8/arch-arm//usr/lib/libc.a(eventfd.o): multiple definition of 'eventfd' /usr/local/src/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld: /usr/local/src/android-ndk-r10/platforms/android-8/arch-arm//usr/lib/libc.a(eventfd.o): previous definition here /usr/local/src/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld: error: /usr/local/src/android-ndk-r10/platforms/android-8/arch-arm//usr/lib/libc.a(_rand48.o): multiple definition of '__dorand48' /usr/local/src/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld: /usr/local/src/android-ndk-r10/platforms/android-8/arch-arm//usr/lib/libc.a(_rand48.o): previous definition here /usr/local/src/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld: error: /usr/local/src/android-ndk-r10/platforms/android-8/arch-arm//usr/lib/libc.a(_rand48.o): multiple definition of '__rand48_mult' /usr/local/src/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld: /usr/local/src/android-ndk-r10/platforms/android-8/arch-arm//usr/lib/libc.a(_rand48.o): previous definition here /usr/local/src/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld: error: /usr/local/src/android-ndk-r10/platforms/android-8/arch-arm//usr/lib/libc.a(_rand48.o): multiple definition of '__rand48_add' /usr/local/src/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld: /usr/local/src/android-ndk-r10/platforms/android-8/arch-arm//usr/lib/libc.a(_rand48.o): previous definition here /usr/local/src/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld: error: /usr/local/src/android-ndk-r10/platforms/android-8/arch-arm//usr/lib/libc.a(_rand48.o): multiple definition of '__rand48_seed' /usr/local/src/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld: /usr/local/src/android-ndk-r10/platforms/android-8/arch-arm//usr/lib/libc.a(_rand48.o): previous definition here /usr/local/src/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld: error: /usr/local/src/android-ndk-r10/platforms/android-8/arch-arm//usr/lib/libm.a(s_scalbn.o): multiple definition of 'ldexp' /usr/local/src/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld: /usr/local/src/android-ndk-r10/platforms/android-8/arch-arm//usr/lib/libc.a(ldexp.o): previous definition here /usr/local/src/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld: error: cannot find -lz /usr/local/src/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld: error: cannot find -ldl /usr/local/src/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld: error: cannot find -llog libavformat/http.c:384: error: undefined reference to 'inflateEnd' libavformat/http.c:385: error: undefined reference to 'inflateInit2_' libavformat/http.c:390: error: undefined reference to 'zlibCompileFlags' libavformat/http.c:1029: error: undefined reference to 'inflateEnd' libavformat/http.c:867: error: undefined reference to 'inflate' libavformat/id3v2.c:840: error: undefined reference to 'uncompress' libavformat/mov.c:2934: error: undefined reference to 'uncompress' bionic/libc/bionic/drand48.c:24: error: undefined reference to '_rand48_seed' bionic/libc/bionic/erand48.c:21: error: undefined reference to '_dorand48' 

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

Solutions Collecting From Web of "用Android NDK r10编译FFmpeg 2.3"

在你的构建中, ld寻找静态系统库( libc.alibz.a ,…),而它应该寻找这些库的共享版本。

有一个可以帮助的-Bshared标志,但是要完全控制正在发生的事情,我会建议下面的链接步骤:

 $PREBUILT/bin/arm-linux-androideabi-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib \ -soname libffmpeg.so -nostdlib,noexecstack -Bsymbolic \ --whole-archive --no-undefined \ -o $PREFIX/libffmpeg.so libavcodec/libavcodec.a libavformat/libavformat.a \ libavutil/libavutil.a libswscale/libswscale.a \ $PLATFORM/usr/lib/libc.so $PLATFORM/usr/lib/libm.so \ $PLATFORM/usr/lib/libz.so \ $PLATFORM/usr/lib/libdl.so $PLATFORM/usr/lib/liblog.so \ --dynamic-linker=/system/bin/linker \ $PREBUILT/lib/gcc/arm-linux-androideabi/4.8/libgcc.a 

你似乎不需要可执行文件,所以你可以添加到你的./configure调用

 --disable-ffmpeg --disable-ffprobe --disable-ffserver 

并删除以下行:

 --extra-ldflags --extra-libs 

这对我工作:

首先,制作一个独立的工具链:

 android-ndk-r10/build/tools/make-standalone-toolchain.sh --platform=android-{your target here} --install-dir={pick a toolchain install directory} 

然后使用独立工具链配置ffmpeg:

 ./configure \ --prefix={where you want to install ffmpeg to} \ --cross-prefix={standalone toolchain install dir}/bin/arm-linux-androideabi- \ --target-os=linux \ --arch=arm \ --enable-cross-compile \ --sysroot={standaline toolchain install dir}/sysroot \ --disable-yasm 

我认为你需要禁用yasm,因为它不适用于ARM。

从那里你可以“安装”,它应该工作。