Compiling ffmpeg tutorials on Mac (Android edition)
This article is mainly about compiling ffmpeg to generate so libraries in a Mac environment.
FFmpeg Introduction
FFmpeg is not only a audio and video codec tool, but also a set of audio and video codec development kit, as a codec development kit, it provides developers with a wealth of audio and video processing of the call interface.
FFmpeg provides a variety of media formats package and package, including a variety of audio and video coding, multi-protocol streaming media, a variety of color format conversion, a variety of sample rate conversion, a variety of bit rate conversion. The FFMPEG framework provides a wide variety of plug-in modules, including encapsulation and encapsulation of plug-ins, encoding and decoding plug-ins, and so on.
Development environment
The environment for this compilation is as follows:
- MacOS High Sierra (10.13.5)
- FFmpeg source code (3.3.7)
- NDK (android-ndk-r14b)
To download the NDK first, it is recommended that you do not use the Ndk-bundle that comes with Android studio, and then configure the NDK's global environment to add the configuration in. Bash_profile:
export ANDROID_NDK_ROOT=/Users/jiangshuaijie/android-ndk-r14b/buildexport PATH=${PATH}:${ANDROID_NDK_ROOT}
Then enter the Ndk-build test environment on the command line to see if the configuration is successful.
Download FFmpeg source code
FFmpeg source code can be downloaded in https://ffmpeg.org/download.html#releases, you can also use Git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg Clone to Local. It is recommended to download the 3.3.x version of the library, the latest library compilation problems more, various paths are not normal and so on.
Modify the Configure file
After you download the FFmpeg source code, you first need to modify the Configure file in the source code. Because the version number of the compiled dynamic library file name is after. So (for example, "libavcodec.so.5.100.1"), and the Android platform does not recognize such a file name, you need to modify the file name. Find the following lines of code 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)‘
Replaced by
SLIBNAME_WITH_MAJOR=‘$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)‘LIB_INSTALL_EXTRA_CMD=‘$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"‘SLIB_INSTALL_NAME=‘$(SLIBNAME_WITH_MAJOR)‘SLIB_INSTALL_LINKS=‘$(SLIBNAME)‘
Writing scripts to generate class libraries
The
Creates a build_android.sh script in FFmpeg and gives the executable permissions, the script reads:
#!/bin/bashmake clean# ndk Path, set the export according to your installation location Tmpdir=/users/jiangshuaijie/ffmpeg-3.3.7/ffmpeg_installexport Ndk=/users/jiangshuaijie/android-ndk-r14bexport sysroot= $NDK/platforms/android-21/arch-arm/export TOOLCHAIN= $NDK /toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64export cpu=armexport PREFIX=$ (pwd)/android/$ Cpuexport addi_cflags= "-marm" function build_one{./configure--prefix= $PREFIX--target-os=linux--cross-prefix= $TOOLCHAIN/bin/arm-linux-androideabi---arch=arm--sysroot= $SYSROOT--extra-cflags= "-os-fpic $ADDI _cflags" --extra-ldflags= "$ADDI _ldflags"--cc= $TOOLCHAIN/bin/arm-linux-androideabi-gcc--nm= $TOOLCHAIN/bin/arm-linux-andr OIDEABI-NM--enable-shared--enable-runtime-cpudetect--ENABLE-GPL--enable-small--enable-cross-compi Le--disable-debug--disable-static--disable-doc--disable-asm--disable-ffmpeg--disable-ffplay --disable-ffprobe--disable-ffserver--enable-postProc--enable-avdevice--disable-symver--disable-stripping $ADDITIONAL _configure_flagsed-i "S/have_lrint 0/have_lrint 1/g ' config.hsed-i ' s/have_lrintf 0/have_lrintf 1/g ' config.hsed-i ' ' S/have_round 0/HAVE_ROUND 1/g ' Co Nfig.hsed-i "s/have_roundf 0/have_roundf 1/g ' config.hsed-i" ' S/have_trunc 0/have_trunc 1/g ' config.hsed-i ' S/H AVE_TRUNCF 0/have_truncf 1/g ' config.hsed-i ' s/have_cbrt 0/have_cbrt 1/g ' config.hsed-i ' S/HAVE_RINT 0/HAVE_RINT 1 /g ' Config.hmake clean# here is defined with a few CPUs compiled, I use 4, typically compiled within 5 minutes to complete Make-j4make install}build_one
which
- Tmpdir directory where temporary files generated for compilation are stored
- Sysroot the minimum Android version of the platform directory supported for so files
- Platforms supported by the CPU for the specified so file
- Prefix directory for generated so files
- Toolchain the tool chain catalog used for compilation
- Cross-prefix the tool chain file used for compilation
- Enable and disable specify the items that need to be compiled
- Target-os is the target operating system;
Compiling ffmpeg
In the FFmpeg directory, execute the terminal command:
./build_android.sh
You can compile and wait for the so file to be generated.
Related information
Lei's Blog
Compiling ffmpeg tutorials on Mac (Android edition)