Android NDK & FFMPEG build
Solution 1
I made a tutorial on how to build ffmpeg
and x264
for android
:
zip with build of ffmpeg with x264
You can also download the zip file containing the files you need to make an application on android
.
Solution 2
If you want more detailed instruction of how to build ffmpeg and how to use it to build Android apps, please refer to the book Android NDK cookbook: http://www.packtpub.com/android-native-development-kit-cookbook/book
The Bonus Chapter 1 is dedicated to multimedia app development with Android NDK and ffmpeg, and it is available for free at http://www.packtpub.com/sites/default/files/downloads/Developing_Multimedia_Applications_with_NDK.pdf
Solution 3
First of all, you should read the documentation for Android NDK and check out some sample apps. You'll find these details in android_NDK_home/docs and android_NDK_home/samples (where android_NDK_home is the folder name for your android NDK).
Also, check this link on stackoverflow: Using FFmpeg with Android-NDK
For a stept by step tutorial, this is a pretty good one: http://www.roman10.net/how-to-build-ffmpeg-for-android/
Also, you'll have to install/configure some elements on your Eclipse to enable support for developing applications that are built with the NDK: http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/ http://wiki.eclipse.org/Sequoyah/ndk_checklist
And a pretty good project that uses the ffmpeg library: https://github.com/havlenapetr/FFMpeg
Solution 4
ffmpeg uses autoconf as its build system. As of the time of this writing, no one has yet put together a Gradle build package for ffmpeg on Android. As far as I can tell, Gradle doesn't yet support autoconf, which makes it pretty difficult to do so
That said, after trying several of the tutorials that were out there, as well as some of the pre-built packages, we decided to roll our own Android build script wrapper for ffmpeg that includes support for OpenSSL and librtmp.
You can find it here: https://github.com/cine-io/android-ffmpeg-with-rtmp
Prerequisite: The Android NDK must be installed
Instructions:
$ git clone [email protected]:cine-io/android-ffmpeg-with-rtmp.git
$ cd android-ffmpeg-with-rtmp
$ ./build.sh
When the script is finished, the required shared libraries and ffmpeg
executable will be put into the build/dist
directory. You can include them in your project just like any other native binary.
Comments
-
Android-Droid almost 2 years
I'm trying to build FFMPEG library for my android application using the NDK. I have downloaded the source code from it's website and I think I build it (it's my first try working with NDK and ffmpeg). I have created a
build.sh
file which I'm using to execute it from command line on Mac OS X. But I have a few questions...First things is as I know I need Android.mk file so I can use the builded library in my application,but I don't know how to do that for reasons which I told you above. After I run my
build.sh
I getandroid
folder with a few folders and some libraries. So my first question is, how can I build the Android.mk file which I need...and maybe if someone can explain me why I need it.My second question is I need some libraries from ffmpeg to be able to use them from my app, but after the build i can't see them in my source tree. I know that I have to enable them in my
build.sh
and I think I did,but I can't see them. So any kind of information about my build file will be helpful for me to understand how to configure it. Here is how it looks like :#!/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=~/Desktop/android-ndk-r5b 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=darwin \ --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-doc \ --disable-ffmpeg \ --disable-ffplay \ --disable-ffserver \ --disable-ffprobe \ --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" \ --enable-zlib \ --enable-version3 \ --enable-nonfree \ --enable-libmp3lame \ --enable-libspeex \ --enable-libtheora \ --enable-libfaac \ --enable-libvorbis \ --enable-libaacplus \ --prefix=$DIST_DIR \ $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 } #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
Thanks for any kind of useful information/suggestions/examples and etc.