FFmpeg porting Android platform

Keywords: Android Linux Google JDK

Development environment: FFmpge 3.3.9, JDK 1.8, Android Studio 3.5, NDK 14b, Android SDK, win10 64 bit system
1, Download FFmpeg (3.3.9)
1. Download address

http://www.ffmpeg.org/download.html#releases%20%EF%BC%89

2. Right click Download gzip tarball, copy the link, log in to the server and execute the following command:

wget http://www.ffmpeg.org/releases/ffmpeg-3.3.9.tar.gz

3. Decompress FFmpeg package

tar -zxvf ffmpeg-3.3.9.tar.gz


2, Download NDK (r14b)
1. Download the NDK address. Now download the NDK on the corresponding platform.

https://developer.android.google.cn/ndk/downloads/older_releases#ndk-14b-downloads

2. Right click the Linux package, copy the link, and log in to the server to execute the following command:

wget https://dl.google.com/android/repository/android-ndk-r14b-linux-x86_64.zip

3. Unzip NDK package

unzip android-ndk-r14b-linux-x86_64.zip

3, Android compilation script
1. Modify the configure file of FFmpeg

  • Because android can only load dynamic libraries at the end of *. so, it cannot recognize dynamic libraries at the end of *. so.57
//Modify the following file in the configure file
#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)'
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
SLIB_INSTALL_LINKS='$(SLIBNAME)'

2. Write Android compilation script (platform wide compilation script)

#!/bin/bash
export NDK_HOME=/root/FFmpeg_3_3_9/android-ndk-r14b

function build
{
	echo "start build ffmpeg for $CPU"
	./configure --target-os=linux \
	--prefix=$PREFIX --arch=$CPU \
	--disable-doc \
	--enable-shared \
	--disable-static \
	--disable-yasm \
	--disable-asm \
	--disable-symver \
	--disable-encoders \
	--disable-programs \
 	--disable-htmlpages \
  	--disable-manpages \
  	--disable-podpages \
  	--disable-txtpages \
	--disable-muxers \
	--disable-ffmpeg \
	--disable-ffplay \
	--disable-ffprobe \
	--disable-avdevice \
	--disable-avfilter \
	--disable-debug \
	--cross-prefix=$CROSS_COMPILE \
	--enable-cross-compile \
	--sysroot=$SYSROOT \
	--enable-small \
	--enable-protocols \
	--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
	--extra-ldflags="$ADDI_LDFLAGS" \
	$ADDITIONAL_CONFIGURE_FLAG
	make clean
	make
	make install
	echo "build ffmpeg for $CPU finished"
}

#arm
PLATFORM_VERSION=android-14
ARCH=arm
CPU=armeabi
PREFIX=$(pwd)/android_all/$CPU
TOOLCHAIN=$NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
CROSS_COMPILE=$TOOLCHAIN/bin/arm-linux-androideabi-
ADDI_CFLAGS="-marm -mthumb"
ADDI_LDFLAGS=""
SYSROOT=$NDK_HOME/platforms/$PLATFORM_VERSION/arch-$ARCH/
build

#arm-v7a
PLATFORM_VERSION=android-14
ARCH=arm
CPU=armeabi-v7a
PREFIX=$(pwd)/android_all/$CPU
TOOLCHAIN=$NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
CROSS_COMPILE=$TOOLCHAIN/bin/arm-linux-androideabi-
ADDI_CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -mfpu=neon"
ADDI_LDFLAGS="-march=armv7-a -Wl,--fix-cortex-a8"
SYSROOT=$NDK_HOME/platforms/$PLATFORM_VERSION/arch-$ARCH/
build


#arm64
PLATFORM_VERSION=android-21
ARCH=arm64
CPU=arm64
PREFIX=$(pwd)/android_all/$CPU
TOOLCHAIN=$NDK_HOME/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64
CROSS_COMPILE=$TOOLCHAIN/bin/aarch64-linux-android-
ADDI_CFLAGS=""
ADDI_LDFLAGS=""
SYSROOT=$NDK_HOME/platforms/$PLATFORM_VERSION/arch-$ARCH/
build


#x86
PLATFORM_VERSION=android-14
ARCH=x86
CPU=x86
PREFIX=$(pwd)/android_all/$CPU
TOOLCHAIN=$NDK_HOME/toolchains/x86-4.9/prebuilt/linux-x86_64
CROSS_COMPILE=$TOOLCHAIN/bin/i686-linux-android-
ADDI_CFLAGS="-march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32"
ADDI_LDFLAGS=""
SYSROOT=$NDK_HOME/platforms/$PLATFORM_VERSION/arch-$ARCH/
build

#x86_64
PLATFORM_VERSION=android-21
ARCH=x86_64
CPU=x86_64
PREFIX=$(pwd)/android_all/$CPU
TOOLCHAIN=$NDK_HOME/toolchains/x86_64-4.9/prebuilt/linux-x86_64
CROSS_COMPILE=$TOOLCHAIN/bin/x86_64-linux-android-
ADDI_CFLAGS="-march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel"
ADDI_LDFLAGS=""
SYSROOT=$NDK_HOME/platforms/$PLATFORM_VERSION/arch-$ARCH/
build

4, Start compilation
1. Execute configure file to generate makefile file

chmod 777 configure (modify permission)
. / configure (execute script)
  • Error will be reported when executing the above command:
yasm/nasm not found or too old. Use --disable-yasm for a crippled build.
  • Solution
sudo apt-get install yasm
  • The following file indicates that the compilation is successful

    2. Execute android compilation script
Chmod 777 build u android.sh (modify permission)
./build android.sh (execute script)
111 original articles published, 5 praised, 20000 visitors+
Private letter follow

Posted by Magneto on Tue, 25 Feb 2020 07:16:58 -0800