MAC-AndroidStudio-NDK环境环境下FFmpeg的编译
环境:
mac OS 10.15.4
AndroidStudio 3.5.3
ffmpeg 3.3.6
ndk android-ndk-r15c
platform android-21
配置
操作步骤:
1.修改configure,去掉so文件输出时的版本信息
修改内容如下:
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
SLIB_INSTALL_LINKS='\$(SLIBNAME)'
2.创建build_android.sh文件,并增加内容如下:
#!/bin/bash
export NDK_HOME=「你下载的NDK解压目录」如:/Users/用户/android-ndk-r15c
export PLATFORM_VERSION=android-21「根据你的需要修改」
function build
{echo "start build ffmpeg for $ARCH"./configure --target-os=linux \--prefix=$PREFIX --arch=$ARCH \--disable-doc \--disable-static \--disable-yasm \--disable-asm \--disable-symver \--disable-ffmpeg \--disable-ffplay \--disable-ffprobe \--disable-ffserver \--cross-prefix=$CROSS_COMPILE \--enable-cross-compile \--enable-shared \--enable-gpl \--sysroot=$SYSROOT \--enable-small \--extra-cflags="-Os -fpic $ADDI_CFLAGS" \--extra-ldflags="$ADDI_LDFLAGS" \$ADDITIONAL_CONFIGURE_FLAGmake cleanmakemake installecho "build ffmpeg for $ARCH finished"
}
PLATFORM_VERSION=android-21「根据你的需要修改」
ARCH=x86_64「根据你的需要修改,如下:其它配置方案」
CPU=x86_64
PREFIX=$(pwd)/android_all/$CPU
TOOLCHAIN=$NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64
CROSS_COMPILE=$TOOLCHAIN/bin/arm-linux-androideabi-
ADDI_CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -mfpu=neon"
ADDI_LDFLAGS="-march=armv7-a -Wl,--fix-cortex-a8"
SYSROOT=$NDK_HOME/platforms/$PLATFORM_VERSION/arch-$ARCH/
build
其它配置方案:
PLATFORM_VERSION=android-14
ARCH=arm
CPU=armeabi
PLATFORM_VERSION=android-14
ARCH=arm
CPU=armeabi-v7a
PLATFORM_VERSION=android-21
ARCH=arm64
CPU=arm64
PLATFORM_VERSION=android-14
ARCH=x86
CPU=x86
PLATFORM_VERSION=android-21
ARCH=x86_64
CPU=x86_64
PLATFORM_VERSION=android-14
ARCH=mips
CPU=mips
PLATFORM_VERSION=android-21
ARCH=mips64
CPU=mips64
3.执行build_android.sh文件
这里有几个需要注意的地方
1.修改build_android.sh为可执行文件,方法如下:
chmod 777 build_android.sh
2.解除mac对任何来源的应用程序运行的限制
sudo spctl --master-disable
使用此命令可以检查一下你的系统设置安全与隐私的
是否可以允许任何来源
3.运行build_android.sh脚本
sudo ./build_android.sh
编译过程大概需要五六分钟左右,编译完成后可以根据脚本中你指定的输出目录中查看编译好的so文件,脚本默认输出目录是:ffmpeg当前目录/android_all/CPU架构/ , 类似如下图所示:
备注:我在使用过程中遇到的其它问题
在mac系统下编译x86_64的so时候,提示
yasm/nasm not found or too old. Use --disable-yasm for a crippled build.
解决办法参考:https://blog.csdn.net/l1028386804/article/details/80976376
原文内容:
===------------------------
安装ffmpeg过程中,执行./configure时,报yasm/nasm not found or too old. Use --disable-yasm for a crippledbuild错误,分析、解决如下:
分析:yasm是汇编编译器,ffmpeg为了提高效率使用了汇编指令,如MMX和SSE等。所以系统中未安装yasm时,就会报上面错误。
解决:安装yasm编译器。安装方法如下:
在http://www.tortall.net/projects/yasm/releases下面找到适合自己平台的yasm版本。然后进行安装。举例如下:
1)下载:wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz「可以手动下载到mac本地」
2)解压:tar zxvf yasm-1.3.0.tar.gz「可手动解压」
3)切换路径: cd yasm-1.3.0
4)执行配置: ./configure
5)编译:make
6)安装:make install
===------------------------
另一种build_android.sh配置方案
#!/bin/shMY_LIBS_NAME=ffmpeg-3.3.6
MY_DIR=ffmpeg-3.3.6
MY_BUILD_DIR=binaryNDK_PATH=/Users/xxxx/Downloads/android-ndk-r15c
BUILD_PLATFORM=darwin-x86_64
TOOLCHAIN_VERSION=4.9
ANDROID_VERSION=21ANDROID_ARMV5_CFLAGS="-march=armv5te"
ANDROID_ARMV7_CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=neon"
ANDROID_ARMV8_CFLAGS="-march=armv8-a"
ANDROID_X86_CFLAGS="-march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32"
ANDROID_X86_64_CFLAGS="-march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel"
build_bin() {echo "-------------------star build $2-------------------------"ARCH=$1 ANDROID_ARCH_ABI=$2 PREFIX=$(pwd)/dist/${MY_LIBS_NAME}/${ANDROID_ARCH_ABI}/HOST=$3SYSROOT=${NDK_PATH}/platforms/android-${ANDROID_VERSION}/arch-${ARCH}CFALGS=$5TOOLCHAIN=${NDK_PATH}/toolchains/${HOST}-${TOOLCHAIN_VERSION}/prebuilt/${BUILD_PLATFORM}CROSS_PREFIX=${TOOLCHAIN}/bin/$4-BUILD_DIR=./${MY_BUILD_DIR}/${ANDROID_ARCH_ABI}echo "pwd==$(pwd)"echo "ARCH==${ARCH}"echo "PREFIX==${PREFIX}"echo "HOST==${HOST}"echo "SYSROOT=${SYSROOT}"echo "CFALGS=$5"echo "CFALGS=${CFALGS}"echo "TOOLCHAIN==${TOOLCHAIN}"echo "CROSS_PREFIX=${CROSS_PREFIX}"./configure \--prefix=${PREFIX} \--target-os=linux \--arch=${ARCH} \--sysroot=$SYSROOT \--enable-cross-compile \--cross-prefix=${CROSS_PREFIX} \--extra-cflags="$CFALGS -Os -fPIC -DANDROID -Wfatal-errors -Wno-deprecated" \--extra-cxxflags="-D__thumb__ -fexceptions -frtti" \--extra-ldflags="-L${SYSROOT}/usr/lib" \--enable-shared \--enable-asm \--enable-neon \--disable-encoders \--enable-encoder=aac \--enable-encoder=mjpeg \--enable-encoder=png \--disable-decoders \--enable-decoder=aac \--enable-decoder=aac_latm \--enable-decoder=h264 \--enable-decoder=mpeg4 \--enable-decoder=mjpeg \--enable-decoder=png \--disable-demuxers \--enable-demuxer=image2 \--enable-demuxer=h264 \--enable-demuxer=aac \--disable-parsers \--enable-parser=aac \--enable-parser=ac3 \--enable-parser=h264 \--enable-gpl \--disable-doc \--disable-ffmpeg \--disable-ffplay \--disable-ffprobe \--disable-symver \--disable-debug \--enable-smallmake cleanmakemake installecho "-------------------$2 build end-------------------------"
}
build_bin x86_64 x86_64 x86_64 x86_64-linux-android "$ANDROID_X86_64_CFLAGS"