- 如果需要支持硬件解码,推荐看这篇文章 FFmpeg一键编译Android armv7-a arm64
1.搭建编译环境
1.安装ubuntu14.04,安装完成后执行以下命令
apt-get update
apt-get install yasm
apt-get install pkg-config
2.下载ndk
这里用最新稳定版ndk r19c:下载ndk-r19c
将ndk下载到 /home/ndk/目录下,下载完成后执行unzip android-ndk-r19c-linux-x86_64.zip
解压
3.下载FFmpeg4.1.3
下载FFmpeg-n4.1.3
下载完成后执行tar -zxvf n4.1.3.tar.gz
解压
2.编译FFmpeg
1.修改configure
进入源码根目录,用vim打开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)'
2.配置编译脚本
在源码根目录新建build.sh,内容如下:
#!/bin/bash
NDK=/home/ndk/android-ndk-r19c
ADDI_LDFLAGS="-fPIE -pie"
ADDI_CFLAGS="-fPIE -pie -march=armv7-a -mfloat-abi=softfp -mfpu=neon"
CPU=armv7-a
ARCH=arm
HOST=arm-linux
SYSROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot
TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin
PREFIX=$(pwd)/android/$CPU
x264=$(pwd)/x264/android/$CPU
export PATH=$x264/bin:$PATH
export PATH=$x264/include:$PATH
export PATH=$x264/lib:$PATH
export PKG_CONFIG_PATH=$x264/lib/pkgconfig:$PKG_CONFIG_PATH
configure()
{
./configure \
--prefix=$PREFIX \
--toolchain=clang-usan \
--enable-cross-compile \
--target-os=android \
--arch=$ARCH \
--sysroot=$SYSROOT \
--cc=$TOOLCHAIN/armv7a-linux-androideabi21-clang \
--cxx=$TOOLCHAIN/armv7a-linux-androideabi21-clang++ \
--strip=$TOOLCHAIN/arm-linux-androideabi-strip \
--extra-cflags="$ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
--disable-encoders \
--disable-decoders \
--disable-avdevice \
--disable-static \
--disable-doc \
--disable-ffplay \
--disable-network \
--disable-doc \
--disa