How to fucking build and use FFmpeg with Android Studio!!!
Source: Android Native Development Kit Cookbook, Blog, Roman10, Ph0b
Question: How to FUCKING build and use FFmpeg with Android Studio!!!
Answer: For FFMPEG v3.0.2 and NDK r11
Install Linux Mint in VirtualBox (building on Windows is a NIGHTMARE, don't even try)
Download and Install Android NDK (v11) <- Add link to setup NDK gist
After downloading NDK, simply decompress the archive.
Note: - We’ll use $NDK
to represent the root path of the decompressed NDK.
Download FFMPEG (version v3.0.2) and decompress it into $NDK/sources
folder.
Open ffmpeg-3.0.2/configure
file with a text editor and locate the following lines:
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 replace with 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)'
build_android.sh
under the $NDK/sources/ffmpeg-3.0.2
folder and paste below code, need to update NDK
's path to your NDK folder, update SYSROOT
and TOOLCHAIN
depending on the versions coming with your NDK. Possible NOTICE:#!/bin/bash
NDK=/home/viet/Android/android-ndk-r11c
SYSROOT=$NDK/platforms/android-23/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
function build_one
{
./configure \
--prefix=$PREFIX \
--disable-shared \
--enable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--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
After saving this file, it will disabled static library and enabled shared library (.so files).
Open the terminal in FFmpeg 3.0.2 folder and run below commands:
Validate the script is executable:
sudo chmod +x build_android.sh
Excute the script:
sudo ./build_android.sh
After build completion we can check the shared libraries in $NDK/sources/ ffmpeg-2.2.3/android/arm/lib folder (e.g.: - libavcodec-55.so).
Note: - lib folder also contains the symbolic links (e.g.: - libavcodec.so). We can remove them to avoid the confusion.