Android - Integrating ffmpeg and android-ndk-r9c

2019-04-24 16:33发布

I have seen a lot of posts about FFmpeg and using FFmpeg in Android, but I am finding that a majority of these posts are for older versions of either FFmpeg or Android NDK. I was able to get a result from https://github.com/mconf/android-ffmpeg, which includes the files: "libavcodec.so", "libavformat.so", "libavutil.so", "libswscale.so". However, simply adding these files to my project does not seem to be enough to use FFmpeg. (I followed https://stackoverflow.com/a/21773572/1877798 as a reference guide). It's possible that either I've done something wrong in configuring these files in my project, or I've done something wrong in building FFmpeg for Android. (Should there be more files?)

I was wondering if there are any recent guides for building or integrating FFmpeg in an Android project. I am using FFmpeg (as of 2/27/14) and Android NDK 9c. If not, does anyone have other recommendations for other libraries? I am trying to take a set of image files and create a video/animated gif programatically.

Thanks! :-)


~~ EDIT ~~

I have found http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/comment-page-4/ and a couple others found on GitHub. However, they all seem to struggle in building FFmpeg. I am using Mac OS X

Here is my script:

#!/bin/bash
NDK=/Downloads/android-ndk-r9c
SYSROOT=$NDK/platforms/android-18/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64
# Note: Change the TOOLCHAIN to match that available for your host system.
# darwin-x86_64 is for Mac OS X, but you knew that.
function build_one
{
./configure \
    --prefix=$PREFIX \
    --enable-shared \
    --disable-static \
    --disable-doc \
    --disable-programs \
    --disable-doc \
    --disable-symver \
    --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
    --target-os=linux \
    --arch=arm \
    --enable-cross-compile \
    --sysroot=$SYSROOT \
    --extra-cflags="-Os -fpic $ADDI_CFLAGS" \
    --extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
}
CPU=arm
PREFIX=$(pwd)/android/$CPU 
ADDI_CFLAGS="-marm"
build_one

Here is the log:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-        dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
/Downloads/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc is unable to create an executable file.
C compiler test failed.

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "config.log" produced by configure as this will help
solving the problem.
Makefile:2: config.mak: No such file or directory
Makefile:48: /common.mak: No such file or directory
Makefile:91: /libavutil/Makefile: No such file or directory
Makefile:91: /library.mak: No such file or directory
Makefile:168: /doc/Makefile: No such file or directory
Makefile:169: /tests/Makefile: No such file or directory
make: *** No rule to make target `/tests/Makefile'.  Stop.
Makefile:2: config.mak: No such file or directory
Makefile:48: /common.mak: No such file or directory
Makefile:91: /libavutil/Makefile: No such file or directory
Makefile:91: /library.mak: No such file or directory
Makefile:168: /doc/Makefile: No such file or directory
Makefile:169: /tests/Makefile: No such file or directory
make: *** No rule to make target `/tests/Makefile'.  Stop.
Makefile:2: config.mak: No such file or directory
Makefile:48: /common.mak: No such file or directory
Makefile:91: /libavutil/Makefile: No such file or directory
Makefile:91: /library.mak: No such file or directory
Makefile:168: /doc/Makefile: No such file or directory
Makefile:169: /tests/Makefile: No such file or directory
make: *** No rule to make target `/tests/Makefile'.  Stop.

4条回答
Juvenile、少年°
2楼-- · 2019-04-24 17:07

You need to fix your NDK path its not correct. It may be : NDK=/user//Downloads/android-ndk-r9c

And you wanna check in browser as :

file:///user/xyz/Downloads/android-ndk-r9c

if valid then open "android-ndk-r9c" folder. When you success then put it on your NDK path and build.

查看更多
Bombasti
3楼-- · 2019-04-24 17:09

I am using android ndk r10e with ffmpeg 2.7.1 and yasm 1.2.0 (all in downloads folder) in mac os x

#!/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)
# set $CPU and $OPTIMIZE_CFLAGS
# call build_one

NDK=$Users/samavesh/Downloads/android-ndk-r10e
SYSROOT=$NDK/platforms/android-9/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-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" \
--enable-parsers \
--enable-encoders  \
--enable-decoders \
--disable-muxers \
--enable-demuxers \
--enable-swscale  \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--enable-network \
--enable-indevs \
--disable-bsfs \
--enable-filters \
--enable-protocols  \
--enable-asm \
$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 \
-Bsymbolic --whole-archive --no-undefined -o $PREFIX/libffmpeg.so \
libavcodec/libavcodec.a libavdevice/libavdevice.a libavfilter/libavfilter.a \
libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a \
libswresample/libswresample.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
查看更多
叼着烟拽天下
4楼-- · 2019-04-24 17:12

I had that same error.

"Makefile:2: config.mak: No such file or directory Makefile:48: /common.mak: No such file or directory Makefile:91: /libavutil/Makefile: No such file or directory Makefile:91: /library.mak: No such file or directory Makefile:168: /doc/Makefile: No such file or directory Makefile:169: /tests/Makefile: No such file or directory make: *** No rule to make target `/tests/Makefile'. Stop."

Please check your directory paths inside of your script are correct. i.e.:'/Downloads/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/"

I think it actually is "$HOME/Downloads"

Also make sure you are running the script in the ".../android-ndk-r9c/sources/FFMPEG/" directory.

查看更多
Explosion°爆炸
5楼-- · 2019-04-24 17:13

Try this one which is best I have used so far: https://github.com/bbcallen/ijkplayer

查看更多
登录 后发表回答