This tutorial will show how to compile ffmpeg 3.0 to use the powerful command line tool in any Android application. You can download this app to see how works FFmpeg in android: http://ztuber.josymardeleon.com
- Ubuntu 16.04 LTS
- Memory 3.8 GiB
- Intel® Core™ i5-3320M CPU @ 2.60GHz × 4
- FFmpeg 3.0
- Android NDK
- Android Studio
- Open a terminal and download Android NDK, then unzip
wget http://dl.google.com/android/repository/android-ndk-r12b-linux-x86_64.zip
unzip android-ndk-r12b-linux-x86_64.zip
or download the latest android ndk from here: https://developer.android.com/ndk/downloads/index.html and unzip
-
Inside NDK folder go to sources and create a new folder called external-libs (if you want to compile any other lib with ffmpeg like libmp3lame, libx264, etc)
-
Download FFmpeg 3.0 from https://www.ffmpeg.org/releases/ and unzip inside sources folder. You will have ffmpeg-3.0 folder
-
Update the file configure inside Ffmpeg folder
Replace this:
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)'
For this:
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
SLIB_INSTALL_LINKS='$(SLIBNAME)
-
Create temporal folder named ffmpegtemp inside FFmpeg folder.
-
Create new document called ffmpeg_build.sh inside FFmpeg folder and copy this: Note: You can edit this file with the options that you want to setup for ffmpeg
edit the NDK variable with your NDK path
Copy this:
#!/bin/bash
export TMPDIR=/your/path/ffmpeg/ffmpegtemp
NDK=/your/android/ndk/path/android-ndk
PLATFORM=$NDK/platforms/android-14/arch-arm
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
echo ""
echo ""
echo "********************* Zoe Developers by Josymar ***********************"
echo ""
echo "Compiling Shared library FFmpeg 3.0 for Android"
echo ""
echo "****************************************************************" `
function build_one
{
./configure \
--prefix=$PREFIX \
--target-os=linux \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--arch=arm \
--sysroot=$PLATFORM \
--extra-cflags="-I$NDK/sources/external-libs" \
--extra-ldflags="-L$NDK/sources/external-libs" \
--cc=$TOOLCHAIN/bin/arm-linux-androideabi-gcc \
--nm=$TOOLCHAIN/bin/arm-linux-androideabi-nm \
--disable-static \
--enable-shared \
--disable-runtime-cpudetect \
--enable-gpl \
--enable-small \
--enable-cross-compile \
--enable-asm \
--enable-neon \
--enable-yasm \
--disable-debug \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-postproc \
--disable-avdevice \
--disable-symver \
--disable-stripping \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make -j$(nproc)
make install
}
#for arm
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one
- Open a terminal and give permissions to the file created
chmod +x ffmpeg_build.sh
- Now compile the FFmpeg
bash ffmpeg_build.sh
Note: This process will take some time, depending your machine.
- After this, you will see a new folder called android. Your compile files will be inside the folder arm/lib. Just keep the files with a dash and number. For example libavcodec-57.so. You can deleted the original versions libavcodec.so
- Create an android project using Android Studio IDE
- Create a folder called jni at the same level of src.
- Inside jni folder create two folders: ffmpeg and so
- Inside so folder copy the binaries generated by the compiler: libavcodec-57.so, libavfilter-6.so, libavformat-57.so, libavutil-55.so, libswresample-2.so, libswscale-4.so
- Inside ffmpeg folder copy the folder include generated by the compiler.