1. Download and install
NDK https://developer.android.google.cn/ndk/downloads/
MInGW https://sourceforge.net/projects/mingw/files/
yasm http://www.tortall.net/projects/yasm/releases
FFMPEG source code https://ffmpeg.org/download.html
2. Install NDK
Configure environment variables:
Configure the ndk environment variable path and add D:\android\android-ndk;
3. MinGW download and installation configuration
Check all, execute the installation, click installation in the upper left corner, and then click apply change
Configure the environment variable path and add two paths to it:
;D:\MinGW\bin;
D:\MinGW\msys\1.0\bin
After the installation is complete, execute msys.bat instead of the cmd window of the window to execute the compilation command.
4. Download and install yasm
1) Download: http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
2) Unzip: yasm-1.3.0.tar.gz
3) Switch path: cd yasm-1.3.0
4) Execute configuration: ./configure
5) Compile: make
6) Installation: make install
5. Download the FFMPEG source code, modify the configure file, and create the build_android.sh script file
Download and unzip:
Modify 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)'
Create a new build_android.sh script file for configuration and compilation (the name is not unique)
#!/bin/sh
NDK_HOME=D:/Android/sdk/ndk-bundle
PREFIX=android-build
HOST_PLATFORM=linux-x86_64
PLATFORM=android-21
COMMON_OPTIONS="\
--target-os=android \
--disable-static \
--enable-shared \
--enable-small \
--enable-cross-compile \
--enable-neon \
--disable-programs \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-doc \
--disable-symver \
--disable-asm \
--enable-decoder=h264 \
--enable-decoder=mpeg4 \
--enable-decoder=mjpeg \
--enable-decoder=png \
--enable-decoder=vorbis \
--enable-decoder=opus \
--enable-decoder=flac
"
build_all(){
for version in armeabi armeabi-v7a arm64-v8a x86 x86_64; do
echo "======== > Start build $version"
case ${version} in
armeabi )
ARCH="arm"
CPU="armv5te"
CROSS_PREFIX="$NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/$HOST_PLATFORM/bin/arm-linux-androideabi-"
SYSROOT="$NDK_HOME/platforms/$PLATFORM/arch-arm/"
EXTRA_CFLAGS="-march=armv5te"
EXTRA_LDFLAGS="-Wl,-L${SYSROOT}/usr/lib"
;;
armeabi-v7a )
ARCH="arm"
CPU="armv7-a"
CROSS_PREFIX="$NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/$HOST_PLATFORM/bin/arm-linux-androideabi-"
SYSROOT="$NDK_HOME/platforms/$PLATFORM/arch-arm/"
EXTRA_CFLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -mvectorize-with-neon-quad"
EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L${SYSROOT}/usr/lib"
;;
arm64-v8a )
ARCH="aarch64"
CPU="armv8-a"
CROSS_PREFIX="$NDK_HOME/toolchains/aarch64-linux-android-4.9/prebuilt/$HOST_PLATFORM/bin/aarch64-linux-android-"
SYSROOT="$NDK_HOME/platforms/$PLATFORM/arch-arm64/"
EXTRA_CFLAGS="-march=armv8-a"
EXTRA_LDFLAGS="-Wl,-L${SYSROOT}/usr/lib"
;;
x86 )
ARCH="x86"
CPU="i686"
CROSS_PREFIX="$NDK_HOME/toolchains/x86-4.9/prebuilt/$HOST_PLATFORM/bin/i686-linux-android-"
SYSROOT="$NDK_HOME/platforms/$PLATFORM/arch-x86/"
EXTRA_CFLAGS="-march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32"
EXTRA_LDFLAGS="-Wl,-L${SYSROOT}/usr/lib"
;;
x86_64 )
ARCH="x86_64"
CPU="x86_64"
CROSS_PREFIX="$NDK_HOME/toolchains/x86_64-4.9/prebuilt/$HOST_PLATFORM/bin/x86_64-linux-android-"
SYSROOT="$NDK_HOME/platforms/$PLATFORM/arch-x86_64/"
EXTRA_CFLAGS="-march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel"
EXTRA_LDFLAGS="-Wl,-L${SYSROOT}/usr/lib"
;;
esac
echo "-------- > Start clean workspace"
make clean
echo "-------- > Start config makefile"
configuration="\
--prefix=${PREFIX} \
--libdir=${PREFIX}/libs/${version}
--incdir=${PREFIX}/includes/${version} \
--pkgconfigdir=${PREFIX}/pkgconfig/${version} \
--arch=${ARCH} \
--cpu=${CPU} \
--cross-prefix=${CROSS_PREFIX} \
--sysroot=${SYSROOT} \
--extra-ldexeflags=-pie \
${COMMON_OPTIONS}
"
echo "-------- > Start config makefile with ${configuration}"
./configure ${configuration}
echo "-------- > Start make ${version} with -j8"
make j8
echo "-------- > Start install ${version}"
make install
echo "++++++++ > make and install ${version} complete."
done
}
echo "-------- Start --------"
build_all
echo "-------- End --------"
Open msys.bat and enter the ffmpeg directory
Then enter
$chmod 777 build_android.sh
./build_android.sh
After compilation is completed, an android-build file will be generated in the ffmpeg source code folder.
Possible error: libavformat/os_support.c:194:10: error: 'ERROR_NOT_ENOUGH_MEMORY' undeclared (first use in this function)
Solution: FFmpeg\libavformat\os_support.h
add at the beginning#include "winerror.h"