If you need to do audio and video related content, inevitably around the one east east is FFmpeg. It is an open source computer program that can record, convert, and stream digital audio and video. Under LGPL or GPL license. It provides a complete solution for recording, converting and streaming audio and video. It includes a very advanced audio/video codec library called LibavCodec. In order to ensure high portability and codec quality, much of libavCodec code is developed from scratch. In short, FFmpeg is a very powerful library for audio and video processing. Let’s start with source code compilation to uncover its mystery.

Compilation prepared

  1. Mac environment, this is compiled on the Mac environment, so you need a MacOs computer
  2. FFmpeg source code library, enterFFmpeg websiteClick to download the latest FFmpeg source code (here is version 4.1.3) to the local

    The following folder is obtained after decompression

  3. NDK, you can’t use the NDK configured for AndroidStudio because some header files are missing. Needs to be independently drawn fromThe NDK’s official websiteDownload the standalone and complete NDK version. This is NDK17

    Ps: the NDK16 version is used initially, but the following error will be reported when compiling:

libavformat/udp.c: In function 'udp_set_multicast_sources':
libavformat/udp.c:290:28: error: request for member 's_addr' in something not a structure or union
Copy the code

So the NDK17 version was chosen

Compilation practice

To compile, you need to make some modifications to the FFmpeg configuration and write your own compile SH script, which you can then use to compile the required libraries.

Modify the configuration

Find configure in the FFmpeg file



Before modification:

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

After modification:

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

Compile scripts (important)

Copy an existing shell script named version from FFmpeg

#! /bin/bash
 
ADDI_CFLAGS="-marm"
API=19
PLATFORM=arm-linux-androideabi
CPU=armv7-a
#The local NDK path.NDK=/Users/cainjiang/ProgramFiles/android-ndk-r17c SYSROOT=$NDK/platforms/android-$API/arch-arm/ ISYSROOT=$NDK/sysroot ASM = $ISYSROOT/usr/include / $PLATFORM TOOLCHAIN = $the NDK/toolchains / $PLATFORM - 4.9 / prebuilt Darwin - x86_64#Specify an output directory for the generated files.The OUTPUT = / Users/cainjiang/ProgramFiles/ffmpeg - 4.1.3 / android_out function build {. / configure -- prefix = $OUTPUT \ --enable-shared \ --disable-static \ --disable-doc \ --disable-ffmpeg \ --disable-ffplay \ --disable-ffprobe \ --disable-avdevice \ --disable-doc \ --disable-symver \ --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \ --target-os=android \ --arch=arm \ --enable-cross-compile \ --sysroot=$SYSROOT \ --extra-cflags="-I$ASM -isysroot $ISYSROOT -Os -fpic -marm" \ --extra-ldflags="-marm" \$ADDITIONAL_CONFIGURE_FLAG
  make clean
  make 
  make install
}
build
Copy the code

The script here is my test can compile through, if you need to practice can directly copy the past use, only need to modify their own situation in the comments of the two.

Start the compilation

Finally, enter the root directory of FFmpeg in the console and set permissions for compiling scripts

The OUTPUT = / Users/cainjiang/ProgramFiles/ffmpeg - 4.1.3 / android_outCopy the code

reference

The latest ffMPEG 4.1 Android library for Windows cross-builds ffMPEG 4.1 for Android