android交叉编译ffmpeg

前言

目标

在windows下用ndk交叉编译编译ffmpeg库

环境

  • 平台:windows
  • msys2
  • ndk 21
  • ffmpeg 4.3.1(下载ffmpeg源码)

步骤

新建脚本

新建build_ffmpeg.sh

#!/bin/bash
set -e
SRC_DIR=D:/docker_samba/FFmpeg_android/FFmpeg-n4.3.1
DST_DIR=D:/docker_samba/FFmpeg_android/FFmpeg-n4.3.1/android_out
NDK=D:/software/androidsdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64
API=30
 
cd $SRC_DIR
 
function build_onearch
{
	echo ">> configure $CPU"
	./configure --enable-cross-compile --target-os=android  \
	--prefix=$DST_DIR/$ANDROID_ABI  --cross-prefix=$CROSS_PREFIX  \
	--cc=$CLANG_PREFIX --cxx=$CLANG_PREFIX++  \
	--arch=$ARCH  --cpu=$CPU  --sysroot=$NDK/sysroot \
	--enable-shared --disable-static \
	--enable-small --disable-programs --disable-doc \
	--enable-asm --enable-neon \
	--enable-jni --enable-mediacodec 
	
	echo "<< configure $CPU"
	make clean
	make
	make install
}
 
#ANDROID_ABI=arm64-v8a
#ARCH=arm64
#CPU=armv8-a
#CROSS_PREFIX=$NDK/bin/aarch64-linux-android-
#CLANG_PREFIX=$NDK/bin/aarch64-linux-android$API-clang
#build_onearch
 
ANDROID_ABI=armeabi-v7a
ARCH=arm
CPU=armv7-a
CROSS_PREFIX=$NDK/bin/arm-linux-androideabi-
CLANG_PREFIX=$NDK/bin/armv7a-linux-androideabi$API-clang
build_onearch

然后打开msys2的msys2.exe,执行这个脚本即可。

修改脚本支持x86 x64

#!/bin/bash
set -e
SRC_DIR=D:/docker_samba/FFmpeg_android/FFmpeg-n4.3.1
DST_DIR=D:/docker_samba/FFmpeg_android/FFmpeg-n4.3.1/android_out
NDK=D:/software/androidsdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64
API=30
 
cd $SRC_DIR
 
function build_onearch
{
	echo ">> configure $CPU"
	./configure --enable-cross-compile --target-os=android  \
	--prefix=$DST_DIR/$ANDROID_ABI  --cross-prefix=$CROSS_PREFIX  \
	--cc=$CLANG_PREFIX --cxx=$CLANG_PREFIX++  \
	--arch=$ARCH  --cpu=$CPU  --sysroot=$NDK/sysroot \
	--enable-shared --disable-static \
	--enable-small --disable-programs --disable-doc \
	--enable-asm --enable-neon \
	--enable-jni --enable-mediacodec \
	--disable-x86asm > log.txt
	
	echo "<< configure $CPU"
	make clean
	make
	make install
}
 
# arm64-v8a
#ANDROID_ABI=arm64-v8a
#ARCH=arm64
#CPU=armv8-a
#CROSS_PREFIX=$NDK/bin/aarch64-linux-android-
#CLANG_PREFIX=$NDK/bin/aarch64-linux-android$API-clang
#build_onearch
 
 
# armeabi-v7a
#ANDROID_ABI=armeabi-v7a
#ARCH=arm
#CPU=armv7-a
#CROSS_PREFIX=$NDK/bin/arm-linux-androideabi-
#CLANG_PREFIX=$NDK/bin/armv7a-linux-androideabi$API-clang
#build_onearch


# x86
ANDROID_ABI=x86
ARCH=x86
CPU=x86
CROSS_PREFIX=$NDK/bin/x86_64-linux-android-
CLANG_PREFIX=$NDK/bin/i686-linux-android$API-clang
build_onearch

# x86-64
#ANDROID_ABI=x86_64
#ARCH=x86_64
#CPU=x86-64
#CROSS_PREFIX=$NDK/bin/x86_64-linux-android-
#CLANG_PREFIX=$NDK/bin/x86_64-linux-android$API-clang
#build_onearch

新增了--disable-x86asm > log.txt,--disable-x86asm是因为asm报错, > log.txt是为了查看错误原因

x86会出现Android dlopen failed: has text relocations而armv7-a 、x86_64都没有这样的问题,所以只需要针对x86平台解决即可,可以通过编译时添加**--disable-asm**参数解决

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×