Preface:

The end of developer tools must be the Mac!

Preparation before compilation

1. Ubantu18.0.4 LTS installation and visualization;

2, FFmpeg source: github.com/FFmpeg/FFmp… This version of the 4.2 branch is mainly due to the 4.2 FFmpeg extension support for ExoPlayer.

3, Openssl source :github.com/openssl/ope… Alternatively, you can download it from www.openssl.org/source/ and select version 1.1.1

3, the NDK version: android – the NDK – r21, dl.google.com/android/rep…

Ubantu installation and visual processing

1. Open the Microsoft Store of Windows, search for ubantu, and select download and install 18.04 LTS

If the message “Disable” is displayed, you need to set the Windows environment:

Click the Start button of the system to select Settings, click Update and Security, select development options, select Developer mode, then go back to the upper level, select “Apply”, and then click the programs and functions in the right bar to enter the following page:

Finally, click Enable or disable Windows functions and check Windows subsystem for Linux in the popup window:

Next is the ubantu visualization, many online tutorials, you can Google search, visualization is mainly for compilation convenience. The general process is as follows:

To open ubantu, enter the following input commands in sequence:

Update the source:

Sudo apt to get the update;

Sudo apt-get install xorg;

Sudo apt-get install xfce4;

Sudo apt-get install XRDP;

To configure the XRDP port, run the following command: sudo sed -i ‘s/port=3389/port=3390/g’ /etc/xrdp/xrdp.ini

Xfce4-session: sudo echo xfce4-session >~/.

Run the sudo service XRDP restart command to restart the XRDP service.

Connect to the Linux system desktop through the remote desktop:

Right-click the Start key of Win, select Run, enter MSTSC and confirm:

When you see the following page, enter the address and port and user name:

Click on the link and we will see the following page:

Compilation preparation and scripting

1. Create a folder named NDK and ffmpeg under ubantu’s home folder, download the source code from Firefox, and decompress it.

Modify configure in ffMPEG source code

#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)'Copy the code
Check_pkg_config openssl openssl openssl/SSL. H OPENSSL_init_ssl | | to add the following sentence check_lib openssl openssl/SSL. H OPENSSL_init_ssl -lssl -lcrypto ||Copy the code

Add compiled scripts:

Openssl build_android_openssl.sh:

#! /bin/bash CD openSSL-1.1.1 # Export ANDROID_NDK_ROOT=/home/qisan/ndk/android-ndk-r21 export You need to replace openssl-1.1.1 with your own directory PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH export ANDROID_NDK_HOME=$ANDROID_NDK_ROOT ./config function build { echo "begin build openssl for $PLATFORM_ABI " make clean ./Configure $PLATFORM_ABI -D__ANDROID_API__=$PLATFORM_API no-threads no-shared no-ssl3 no-comp no-hw no-engine --prefix=$PREFIX make make install Rm -r $PREFIX/bin rm -r $PREFIX/share rm -r $PREFIX/ SSL rm -r $PREFIX/lib/engines-1.1 echo "build openssl for $PLATFORM_ABI completed " } #arm-v7a PLATFORM_ABI=android-arm PLATFORM_API=19 The PREFIX = / home/qisan/ffmpeg/openssl - 1.1.1 / android/arm PATH = $ANDROID_NDK_ROOT toolchains/arm - Linux - androideabi - 4.9 / prebuilt/Linux - x86_64 / bin: $PATH build # arm64 PLATFORM_ABI=android-arm64 PLATFORM_API=21 The PREFIX = / home/qisan/ffmpeg/openssl - 1.1.1 / android/arm64 PATH = $ANDROID_NDK_ROOT toolchains/aarch64 - Linux - android - 4.9 / prebuilt/Linux - x86_64 / bin: $PATH build # x86 PLATFORM_ABI = android - x86 PLATFORM_API = 19 PREFIX = / home/qisan/ffmpeg/openssl - 1.1.1 / android/x86 PATH = $ANDROID_NDK_ROOT/toolchains/prebuilt/Linux/x86-4.9 - x86_64 / bin: $PATH build # x86_64 PLATFORM_ABI = android - x86_64 PLATFORM_API = 21 PREFIX = / home/qisan/ffmpeg/openssl - 1.1.1 / android/x86_64 PATH = $ANDROID_NDK_ROOT/toolchains/x86_64-4.9 / prebuilt/Linux - x86_64 / bin: $PATH buildCopy the code

Build_android_ffmpeg. sh:

#! / bin/bash the OUTPUT path = # replace their own environment/home/qisan/ffmpeg/ffmpeg - 4.2 / android the NDK = / home/qisan/the NDK/android - the NDK - r21 # here refers to the openssl library SSL = / home/qisan/ffmpeg openssl / 1.1.1 / android TOOLCHAIN = $the NDK/toolchains/LLVM/prebuilt/Linux - ffmpeg x86_64 CD - 4.2 function  build_android { echo "Compiling FFmpeg for $CPU" ./configure \ --prefix=$PREFIX \ --disable-x86asm \ --disable-asm \ --disable-hwaccels \ --disable-gpl \ --disable-postproc \ --enable-shared \ --enable-jni \ --disable-mediacodec \ --disable-decoder=h264_mediacodec \ --disable-static \ --disable-doc \ --disable-ffmpeg \ --disable-ffplay \ --disable-ffprobe \ --disable-avdevice \ --disable-doc \ --disable-symver \ --cross-prefix=$CROSS_PREFIX \ --target-os=android \ --arch=$ARCH \ --cpu=$CPU \ --cc=$CC \ --cxx=$CXX \ --enable-cross-compile \ --sysroot=$SYSROOT \ --enable-openssl \ --enable-protocols \ --extra-cflags="-Os -fpic $OPTIMIZE_CFLAGS $SSL_CFLAGS" \ -- extra-ldFLAGS ="$ADDI_LDFLAGS $SSL_LDFLAGS" \ $ADDITIONAL_CONFIGURE_FLAG # -- ADDITIONAL_CONFIGURE_FLAG # --extra-cflags=" -os-fpic $OPTIMIZE_CFLAGS $SSL_CFLAGS" # --extra-ldflags="$ADDI_LDFLAGS $SSL_LDFLAGS Function build_arm {ARCH=arm CPU=armv7-a API=19 SSL_CFLAGS=-I$SSL/$ARCH/include SSL_LDFLAGS=-L$SSL/$ARCH/lib CC=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang CXX=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang++ SYSROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi- PREFIX=$OUTPUT/$CPU OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU " build_android } #armv8-a function build_arm64 { ARCH=arm64 CPU=armv8-a API=21 SSL_CFLAGS=-I$SSL/$ARCH/include SSL_LDFLAGS=-L$SSL/$ARCH/lib CC=$TOOLCHAIN/bin/aarch64-linux-android$API-clang CXX=$TOOLCHAIN/bin/aarch64-linux-android$API-clang++ SYSROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot CROSS_PREFIX=$TOOLCHAIN/bin/aarch64-linux-android- PREFIX=$OUTPUT/$CPU OPTIMIZE_CFLAGS="-march=$CPU" build_android } #x86 function build_x86 { ARCH=x86 CPU=x86 API=19 SSL_CFLAGS=-I$SSL/$ARCH/include SSL_LDFLAGS=-L$SSL/$ARCH/lib CC=$TOOLCHAIN/bin/i686-linux-android$API-clang CXX=$TOOLCHAIN/bin/i686-linux-android$API-clang++ SYSROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot CROSS_PREFIX=$TOOLCHAIN/bin/i686-linux-android- PREFIX=$OUTPUT/$CPU OPTIMIZE_CFLAGS="-march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32" build_android } #x86_64 function build_x86_64 { ARCH=x86_64 CPU=x86-64 API=21 SSL_CFLAGS=-I$SSL/$ARCH/include SSL_LDFLAGS=-L$SSL/$ARCH/lib CC=$TOOLCHAIN/bin/x86_64-linux-android$API-clang CXX=$TOOLCHAIN/bin/x86_64-linux-android$API-clang++ SYSROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot CROSS_PREFIX=$TOOLCHAIN/bin/x86_64-linux-android- Build_android =$OUTPUT/$CPU OPTIMIZE_CFLAGS="-march=$cpu-msse4.2 -mpopcnt-m64 -mtune= Intel "build_android} function dash { echo '------------------------------------------------------------' echo '------------------------------------------------------------' echo '------------------------------------------------------------' } build_arm dash build_arm64 dash build_x86 dash build_x86_64Copy the code

/configure –disable-x86asm is not generated because xmakefiles are not generated. Run the following command to Open the ffmpeg script:

chmod 777 build_android_openssl.sh
chmod 777 build_android_ffmpeg.sh
Copy the code

Executing a compilation script

./build_android_openssl.sh
./build_android_ffmpeg.sh
Copy the code

After the openSSL script is executed, ffmpeg is executed, which takes a long time. Finally, the following library is obtained:

At this point, compilation is successful!

Thank you: www.jianshu.com/p/5b3cf2054… Blog.csdn.net/qq_15260769…