Download ffMPEG source code

Download address: www.ffmpeg.org/download.ht…

Download the NDK

Download: p1-jj.byteimg.com/tos-cn-i-t2…

Writing Android Scripts

After decompressing ffMPEG and NDK; Modify ffmpeg configure file

Since Android can only load dynamic libraries ending in *. So, it cannot recognize dynamic libraries ending in *.

#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)'Copy the code

Replace with:

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

Enter the following command on the terminal to set the permission (the specific directory can be modified based on the actual situation) :

Chmod 777 / Users / * * / ffmpeg - 3.2.4 / build_android. ShCopy the code

Enter the terminal in the FFmpeg directory and run the following command:

./configure
Copy the code

Note that if you do not enter this step, errors will be reported later during compilation

Unknown option "--disable-ffserver"...
Copy the code

After the above operations are complete, write an Android compilation script

Create the build_android.sh file under ffmPEG-3.2.4 / and copy the following into this file:

#! /bin/bash export NDK_HOME=/Users/*/Library/Android/sdk/ndk-bundle export PLATFORM_VERSION=android-14 function build { echo "start build ffmpeg for $ARCH" ./configure --target-os=linux \ --prefix=$PREFIX --arch=$ARCH \ --disable-doc \ --enable-shared \ --disable-static \ --disable-yasm \ --disable-asm \ --disable-symver \ --enable-gpl \ --disable-ffmpeg  \ --disable-ffplay \ --disable-ffprobe \ --disable-ffserver \ --cross-prefix=$CROSS_COMPILE \ --enable-cross-compile \ --sysroot=$SYSROOT \ --enable-small \ --extra-cflags="-Os -fpic $ADDI_CFLAGS" \ --extra-ldflags="$ADDI_LDFLAGS" \ $ADDITIONAL_CONFIGURE_FLAG make clean make make install echo "build ffmpeg for $ARCH finished" } #arm ARCH=arm CPU=arm The PREFIX = / Users / * / Documents/ffmpeg - 4.1.3 / arm TOOLCHAIN = $NDK_HOME toolchains/arm - Linux - androideabi - 4.9 / prebuilt Darwin - x86_64 CROSS_COMPILE=$TOOLCHAIN/bin/arm-linux-androideabi- ADDI_CFLAGS="-marm" SYSROOT=$NDK_HOME/platforms/$PLATFORM_VERSION/arch-$ARCH/ build #x86 ARCH=x86 CPU=x86 The PREFIX = / Users / * / Documents/ffmpeg - 4.1.3 / arm/x86 TOOLCHAIN = $NDK_HOME toolchains/x86-4.9 / prebuilt Darwin - x86_64 CROSS_COMPILE=$TOOLCHAIN/bin/i686-linux-android- ADDI_CFLAGS="-march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32" SYSROOT=$NDK_HOME/platforms/$PLATFORM_VERSION/arch-$ARCH/ buildCopy the code

The above script needs to be modified according to the actual installation directory:

After saving, execute:

./build_android.sh
Copy the code

After some time, the required so file is generated in the corresponding directory