Compile ffmpeg for Android

Before Continuing this page, if u want to enable x264, please complete building x264 using android toolchain first. Check this.

Please put x264 folder at same level of hierarchy with ffmpeg fodler

╭─yesimroy@RoyMBPR  ~/Documents/
╰─$ ls
x264 ffmpeg-3.0

This tutorial is for generating android jni needed ffmpeg shared libraries for platform (armeabi, armeabi-v7a, arm64-v8a, x86, x86_64, mips).

1. Download and Unzip ffmpeg

Download ffmpeg from the link, please check lib version first. It shows the description about the version of libries it has.

For ex, FFmpeg 3.0 "Einstein" includes the following library versions:


libavutil      55. 17.103
libavcodec     57. 24.102
libavformat    57. 25.100
libavdevice    57.  0.101
libavfilter     6. 31.100
libavresample   3.  0.  0
libswscale      4.  0.100
libswresample   2.  0.101
libpostproc    54.  0.100

2. Edit output shared library file name

For the output format like this libavcodec-55.so, which is accepted in Android. You need to edit ffmpeg/configure as follow:

Warning: Cause of Markdown double dollar sign ($) issue, the dollar sign $$ bellow should be correct into the right $$

Find these codes:

 SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
 LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
 SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'
 SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)'

And modify into these ones:

SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
SLIB_INSTALL_LINKS='$(SLIBNAME)'

3. Download build scripts of ffmpeg & x264 for android ndk from my repository

Link to my ffmpeg + x264 build scripts repository

4. Copy build scripts into ffmpeg folder

Copy the scripts inside build-scripts-of-ffmpeg-x264-for-android-ndk-master/ffmpeg to your downloaded ffmpeg src code folder. Ex.

Here take ffmpeg-3.0 as an example.

cp build-scripts-of-ffmpeg-x264-for-android-ndk-master/ffmpeg/* ffmpeg-3.0/

Open text editor, check each build script, whether the ndk path and toolchain path are correct or not.

#check the paths bellow, make sure any words is correct.
#for ex. if you want to build shared libraries for arm64, the lowest platform level is 21. for 32 bits, usually i choose android-18. (as you want)
NDK=/Users/yesimroy/Library/Android/sdk/ndk-bundle
PLATFORM=$NDK/platforms/android-21/arch-arm64/
PREBUILT=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64

5. Run the build-all script for generating all platform shared library

Run the build-all script and wait for it, you can check the console logs in case there is an error.

cd ffmpeg-3.0

./build_android_all.sh

6. After compiling success

After compiling success, you will see an folder called android including all platform libraries inside your ffmpeg folder.

╭─yesimroy@MBPR  ~/Documents/ffmpeg-3.0
╰─$ ls android
arm64-v8a  armeabi  armeabi-v7a  x86  x86_64  mips

References

  1. https://github.com/hrydgard/ppsspp-ffmpeg
  2. http://blog.csdn.net/myxuan475/article/details/48625823
  3. http://stackoverflow.com/questions/4119359/build-ffmpeg-on-osx
  4. http://blog.csdn.net/jinrall/article/details/50556328
  5. https://dl.dropboxusercontent.com/u/22605641/ffmpeg_android/main.html
  6. https://trac.ffmpeg.org/attachment/ticket/4928/build_ffmpeg.sh
  7. https://github.com/hrydgard/ppsspp-ffmpeg/tree/master/android
  8. http://vinsol.com/blog/2014/07/30/cross-compiling-ffmpeg-with-x264-for-android/
  9. http://codex.wiki/post/174761-227
  10. http://stackoverflow.com/questions/27421134/system-loadlibrary-couldnt-find-native-library-in-my-case
  11. https://github.com/ongakuer/javacpp-presets/blob/custom_ffmpeg/ffmpeg/cppbuild.sh
  12. http://m.blog.csdn.net/article/details?id=50500444
  13. http://www.pcpop.com/doc/2/2541/2541831.shtml