ffmpeg 编译Android

环境 macOS 10.15.4    NDK 21.3.6528147   ffmpeg 4.2.3

1.执行sudo xcodebuild -license,防止编译的时候找不到一些文件报错

2.下载ffmpeg(4.2.3),解压后进入主目录,修改configure文件,找到

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)‘

3.下载NDK,我这里直接在Android Studio上下载,路径在~/Library/Android/sdk/ndk/21.3.6528147 ,将NDK路径加入path

编辑~/.bash_profile:

NDK_HOME=~/Library/Android/sdk/ndk/21.3.6528147
PATH=${PATH}:${NDK_HOME}

export PATH
export NDK_HOME

执行source ~/.bash_profile,使得路径实时生效

4.

#!/bin/sh# 测试通过 sh android.sh armv8-a   sh android.sh armv7a sh android.sh i686 sh android.sh x86-64NDK=${NDK_HOME}ANDROID_API=29# armv8-a armv7a aarch64 i686 x86_64CPU=armv8-a# arm aarch64 i686 x86_64ARCH=arm64PLATFORM=darwin-x86_64TOOLCHAIN=${NDK}/toolchains/llvm/prebuilt/${PLATFORM}#OPTIMIZE_CFLAGS="-march=$CPU"if [ "$#" -lt 1 ]; then    CPU=armv8-aelse    CPU=$(tr [A-Z] [a-z] <<< "$1")ficase ${CPU} in    arm|armv5|armv6|armv7|armeabi)    echo ${CPU}    ;;    armv7a|armeabi-v7a)    ARCH=arm    CC=${TOOLCHAIN}/bin/armv7a-linux-androideabi${ANDROID_API}-clang    CXX=${TOOLCHAIN}/bin/armv7a-linux-androideabi${ANDROID_API}-clang++    CROSS_PREFIX=${TOOLCHAIN}/bin/arm-linux-androideabi-    ;;    hard|armv7a-hard|armeabi-v7a-hard)    echo ${CPU}    ;;    neon|armv7a-neon)    ;;    armv8|armv8-a|aarch64|arm64|arm64-v8a)    # 验证成功    ARCH=arm64    CC=${TOOLCHAIN}/bin/aarch64-linux-android${ANDROID_API}-clang    CXX=${TOOLCHAIN}/bin/aarch64-linux-android${ANDROID_API}-clang++    CROSS_PREFIX=${TOOLCHAIN}/bin/aarch64-linux-android-    ;;    mips|mipsel)    echo ${CPU}    ;;    mips64|mipsel64|mips64el)    echo ${CPU}    ;;    i686)    ARCH=x86    CC=${TOOLCHAIN}/bin/i686-linux-android${ANDROID_API}-clang    CXX=${TOOLCHAIN}/bin/i686-linux-android${ANDROID_API}-clang++    CROSS_PREFIX=${TOOLCHAIN}/bin/i686-linux-android-    ;;    x86-64|x64)    ARCH=x86_64    CC=${TOOLCHAIN}/bin/x86_64-linux-android${ANDROID_API}-clang    CXX=${TOOLCHAIN}/bin/x86_64-linux-android${ANDROID_API}-clang++    CROSS_PREFIX=${TOOLCHAIN}/bin/x86_64-linux-android-    ;;esacecho "CPU:${CPU}"echo "ARCH:${ARCH}"# mac下是darwin-x86_64,Windows是windows-x86_64#TARGET=${CPU}-linux-androideabiPREFIX=$(pwd)/android/$CPUSYSROOT=${TOOLCHAIN}/sysrootPREFIX=$(pwd)/android/$CPUCFFLAGS="-Os -fpic -march=${CPU}"LDFLAGS="-marm"function build_android{    ./configure \    --prefix=${PREFIX} \    --cross-prefix=${CROSS_PREFIX} \    --target-os=android \    --arch=${ARCH} \    --cpu=${CPU} \    --sysroot=${SYSROOT} \    --extra-cflags="-Os -fpic -march=${CPU}" \    --extra-ldflags=${LDFLAGS} \    --cc=${CC} \    --cxx=${CXX} \    --disable-doc \    --disable-ffplay \    --disable-ffprobe \    --disable-symver \    --disable-static \    --enable-ffmpeg \    --enable-avdevice \    --enable-cross-compile \    --enable-shared \    --enable-jni \    --enable-neon \    --enable-hwaccels \    --enable-gpl \    --enable-postproc \    $ADDITIONAL_CONFIGURE_FLAG    make clean    make -j16    make install}build_android

相关推荐