FFmpeg Mac Compiler Downloaded in Installation

Keywords: Mobile Android Linux brew sudo

Articles Catalogue

Compile ffmpeg

Here we use the mac system, which will be supplemented later by other systems.

download

git clone https://git.ffmpeg.org/ffmpeg.git

Help

cd ffmpeg
./configure --help | more
cd ffmpeg

Installation of necessary yasm

brew install yasm
// If the installation fails, use
sudo chown -R `whoami`:admin /usr/local/bin
sudo chown -R `whoami`:admin /usr/local/share
// Then perform the installation

ERROR: libfdk_aac not found
Look at this article, or you can directly execute the following commands
https://www.jianshu.com/p/b6ad3b706321

brew install fdk-aac

ERROR: speex not found using pkg-config

brew install speex
brew install pkg-config

ERROR: libx264 not found

brew install x264

ERROR: x265 not found using pkg-config

brew install x265

Installing SDL

If you don't install it, the generated ffmpeg has no ffplay

// download
http://www.libsdl.org/release/SDL2-2.0.8.tar.gz
// decompression
tar -zvxf SDL2-2.0.8.tar.gz
// Entry tray
cd /Users/admin/Downloads/SDL2-2.0.8 
// Generate Makefile
./configure --prefix=/usr/local
// install
sudo make -j 8 && make install

Check whether the SDL was installed successfully

cd /usr/local/lib
// Check to see if the installation was successful
ls | grep SDL 

Enter ffmpeg directory configuration

./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-filter=delogo --enable-debug --disable-optimizations --enable-libspeex --enable-videotoolbox --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --cc=clang --host-cflags= --host-ldflags=

If it is a static library

./configure --prefix=/usr/local/ffmpeg --pkg-config-flags=--static --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-filter=delogo --enable-debug --disable-optimizations --enable-libspeex --enable-videotoolbox --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --cc=clang --host-cflags= --host-ldflags=
// Untested
--disable-shared --enable-static
// Because the associated libx264 are all default dynamic, only. a < static library > files are left to delete the corresponding directory files.

After waiting
Check the file to confirm success

vi Makefile 

Compile

sudo make
sudo make  install

Check if the compilation is successful

/usr/local/ffmpeg/bin/ffmpeg

Add environment variables

 vim ~/.bash_profile 
 // Add this sentence
export PATH=$PATH:/usr/local/ffmpeg/bin
// Then exit vim
wq
// Updating environmental variables
source  ~/.bash_profile 
// Input test on command line
ffmpeg

So you can use the ffmpeg command directly

Recording issues

No package 'libavformat' found

# Entry into the environment
export PKG_CONFIG_PATH="$PATH:/usr/local/ffmpeg/lib/pkgconfig"

Android cross-compilation

What is cross compilation?

Compiling an executable program from one platform to another is cross-compiling.

Download ndk

Official address
https://developer.android.com/ndk/downloads/
What I'm using here is
More stable version ndk-r10e
https://dl.google.com/android/repository/android-ndk-r10e-darwin-x86_64.zip

// Here I unzip it and put it here.
/Users/admin/Library/Android/android-ndk-r10e

mac.sh script

PREFIX=android-build

#Set up your own NDK location
NDK_HOME=/Users/superlea/android-ndk-r10e
#Set up your own platform. On Mac, change Linux to linux-x86_64
NDK_HOST_PLATFORM=darwin-x86_64

COMMON_OPTIONS="\
    --target-os=android \
    --disable-static \
    --enable-shared \
    --enable-small \
    --disable-programs \
    --disable-ffmpeg \
    --disable-ffplay \
    --disable-ffprobe \
    --disable-doc \
    --disable-symver \
    --disable-asm \
    "

function build_android {
    ./configure \
    --libdir=${PREFIX}/libs/armeabi-v7a \
    --incdir=${PREFIX}/includes/armeabi-v7a \
    --pkgconfigdir=${PREFIX}/pkgconfig/armeabi-v7a \
    --arch=arm \
    --cpu=armv7-a \
    --cross-prefix="${NDK_HOME}/toolchains/arm-linux-androideabi-4.9/prebuilt/${NDK_HOST_PLATFORM}/bin/arm-linux-androideabi-" \
    --sysroot="${NDK_HOME}/platforms/android-19/arch-arm/" \
    --extra-cflags="-march=armv7-a -mfloat-abi=softfp -mfpu=neon" \
    --extra-ldexeflags=-pie \
    ${COMMON_OPTIONS}
    make clean
    make -j8 && make install

    ./configure \
    --libdir=${PREFIX}/libs/arm64-v8a \
    --incdir=${PREFIX}/includes/arm64-v8a \
    --pkgconfigdir=${PREFIX}/pkgconfig/arm64-v8a \
    --arch=aarch64 \
    --cpu=armv8-a \
    --cross-prefix="${NDK_HOME}/toolchains/aarch64-linux-android-4.9/prebuilt/${NDK_HOST_PLATFORM}/bin/aarch64-linux-android-" \
    --sysroot="${NDK_HOME}/platforms/android-21/arch-arm64/" \
    --extra-ldexeflags=-pie \
    ${COMMON_OPTIONS} 
    make clean
    make -j8 && make install

    ./configure \
    --libdir=${PREFIX}/libs/x86 \
    --incdir=${PREFIX}/includes/x86 \
    --pkgconfigdir=${PREFIX}/pkgconfig/x86 \
    --arch=x86 \
    --cpu=i686 \
    --cross-prefix="${NDK_HOME}/toolchains/x86-4.9/prebuilt/${NDK_HOST_PLATFORM}/bin/i686-linux-android-" \
    --sysroot="${NDK_HOME}/platforms/android-19/arch-x86/" \
    --extra-ldexeflags=-pie \
    ${COMMON_OPTIONS} 
    make clean
    make -j8 && make install

    ./configure \
    --libdir=${PREFIX}/libs/x86_64 \
    --incdir=${PREFIX}/includes/x86_64 \
    --pkgconfigdir=${PREFIX}/pkgconfig/x86_64 \
    --arch=x86_64 \
    --cpu=x86_64 \
    --cross-prefix="${NDK_HOME}/toolchains/x86_64-4.9/prebuilt/${NDK_HOST_PLATFORM}/bin/x86_64-linux-android-" \
    --sysroot="${NDK_HOME}/platforms/android-21/arch-x86_64/" \
    --extra-ldexeflags=-pie \
    ${COMMON_OPTIONS}
    make clean
    make -j8 && make install

};

build_android

Posted by poe on Fri, 01 Feb 2019 19:15:15 -0800