Compile FFmpeg for Android and ffmpeg for android
FFmpeg is a useful audio and video library with powerful functions, but it is not very convenient to use. I have never wanted to use FFmpeg before, because it is too troublesome to compile, but it is time to use FFmpeg. I can't help it. Refer to the methods of the online experts and record them here for later viewing.
I. Environment
Ubuntu14.04
Ii. NDK environment Configuration
NDK download link: https://developer.android.google.cn/ndk/downloads/index.html
After the download is complete, decompress the package to any path, and then Alt + T open the terminal and execute the following command. The value of NDK_HOME is changed to your own NDK path.
export NDK_HOME=/home/y/adm/software/android-ndk-r14bexport PATH=$NDK_HOME:$PATH
3. FFmpeg source code download and ConfigurationFFmpeg: http://www.ffmpeg.org/download.html
Decompress the file to any path, and find the unzipped directory/ffmpeg-3.3.4/configure, open the file to modify the content:
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)'
Changed:
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'SLIB_INSTALL_LINKS='$(SLIBNAME)'
Iv. CompilationCreate an empty document in the FFmpeg root directory and change it to build. sh.
Write the following content:
Some of them need to be modified.
1. TMPDIR = is a temporary directory. Create a new directory and write the path here.
2. NDK = your own NDK path
3. SYSROOT = the platform version at compilation. Select a version as needed.
4. TOOLCHAIN = The NDK path of the front edge must be changed to your own
5. PREFIX = the generated path of the compiled so file. Create a new folder and write the path here.
#!/bin/bashexport TMPDIR=/home/y/adm/software/ffmpeg/tmpdirNDK=/home/y/adm/software/android-ndk-r14bSYSROOT=$NDK/platforms/android-16/arch-arm/TOOLCHAIN=/home/y/adm/software/android-ndk-r14b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64CPU=armPREFIX=/home/y/adm/software/ffmpeg/result/ADDI_CFLAGS="-marm"function build_one{./configure \--prefix=$PREFIX \--enable-shared \--disable-static \--disable-doc \--disable-ffmpeg \--disable-ffplay \--disable-ffprobe \--disable-ffserver \--disable-doc \--disable-symver \--enable-small \--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_FLAGmake cleanmakemake install}build_one
After the modification, open the terminal, switch to the FFmpeg root directory, and execute:sh build.sh
It may take several minutes to wait for the compilation result.
After compilation, open the directory specified by PREFIX, which has two folders: include and lib. Delete the pkgconfig folder and the so link file in the lib folder. At this time, only the so library is left in the folder, the remaining include and lib files are required for development.
PS: at the end of the compilation, there was such a sentence:
build.sh: 35: build.sh: build_one: not found
However, the compilation result seems to be normal. It is the last sentence of the sh file and should not affect the result.