Introduction to the

Learning FFmpeg can’t be avoided. Ffmpeg and FFMProbe two core executable programs, and the application in the mobile terminal essential need to compile into Android can use the SO library. This article mainly introduces the compilation of FFmpeg on MAC into two parts

  1. Compile to a MAC environment
  2. Compile to the Android SO library

FFmpeg compiles to a MAC environment

If yASM is not installed

FFmpeg yasm/nasm not found or too old. Use --disable-yasm for a crippledbuild
Copy the code

1.1.1 download YASM

Download YASM

1.1.2 Accessing the YASM Directory

/ / the first stepcd/configure // sudo make install // sudo make installCopy the code

YASM has been installed

Install the SDL

Download and install

1.2.1 Accessing the SDL Directory

/ / the first stepcdMake -j 16 // sudo make installCopy the code

1.3. Install FFmpeg

Go to the authorities and find the version you want

1.3.1 Installation Process

// Go to the download directory $cd/configure --prefix=/usr/local/ffmpeg --enable-debug=3 --enable-shared --disable-static make -j 4 sudo make installCopy the code

1.3.2 Configuring Environment Variables

Vi ~/.bash_profile // step 2export PATH="$PATH:/usr/local/ffmpeg/bin"/ / the third stepsource ~/.bash_profile
Copy the code

The ffmpeg command succeeded

2. Compile into the Android library

2.1 Download FFMPEG from official website

I downloaded version 4.1

2.2 download the NDK

Android Studio NDK cannot be used. I am using 17 r

2.3 Adding a Script

Create a new android_build.sh file in the root directory of ffmpeg

Just change the NDK and output directory

#! /bin/bash

ADDI_CFLAGS="-marm"
API=19
PLATFORM=arm-linux-androideabi
CPU=x86_64 # 'armeabi-v7a' 'x86_64'
NDK=/Users/yinzelin/ndk/android-ndk-r17c # change to your local NDK path.
SYSROOT=$NDK/platforms/android-$API/arch-arm/
ISYSROOT=$NDK/sysroot
ASM=$ISYSROOT/usr/include/$PLATFORM
TOOLCHAIN=$NDK/toolchains/$PLATFORM4.9 / prebuilt/Darwin - x86_64 OUTPUT = / Users/yinzelin/ffmpeg/ProgramFiles# specify an output directory for the generated files.
function build
{
echo "Start compiling FFmPEG"

./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=armeabi-v7a \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-I$ASM -isysroot $ISYSROOT -Os -fpic -marm" \
--extra-ldflags="-marm" \
$ADDITIONAL_CONFIGURE_FLAG
  make clean
  I used 4 cpus and usually compiled within 5 minutes
  make -j4
  make install

echo "Finish compiling!"
}

build
Copy the code

2.4 Changing the Configuration to Android

Open the ffmpeg root directory to modify the. Configure file

Before the change

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

The modified

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

2.5 Executing scripts

./build_android.sh

Results in output directory