FFmpeg编译

1.FFmpeg源码下载

官网下载源码:http://ffmpeg.org/download.html

点击下载

FFmpeg编译_第1张图片
image.png

安装JDK, NDK并配置相应环境,这里就不介绍具体按照方法。网上很多介绍。

2.修改配置

修改FFmpeg下的configure配置文件生成标准的 .so,而不是 .so.xxx

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.编译脚本

#!/bin/bash
export TMPDIR=/Users/zhouwen/Desktop/ffmpeg/ffmpeg-4.1.3/ffmpegoutput #需要指定编译输出的临时文件夹,不然会报错 unable to create temporary file in

# NDK的路径,根据自己的安装位置进行设置
NDK=/Users/zhouwen/Desktop/ffmpeg/android-ndk-r10e

# 编译针对的平台,可以根据自己的需求进行设置
# 这里选择最低支持android-14, arm架构,生成的so库是放在
# libs/armeabi文件夹下的,若针对x86架构,要选择arch-x86
PLATFORM=$NDK/platforms/android-14/arch-arm

# 工具链的路径,根据编译的平台不同而不同
# arm-linux-androideabi-4.9与上面设置的PLATFORM对应,4.9为工具的版本号,
# 根据自己安装的NDK版本来确定,一般使用最新的版本
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64

function build_one
{
./configure \
    --prefix=$PREFIX \
    --enable-shared \
    --disable-static \
    --disable-doc \
    --disable-avformat \
    --enable-ffmpeg \
    --enable-ffplay \
    --enable-ffprobe \
    --disable-x86asm \
    --disable-avdevice \
    --disable-doc \
    --disable-symver \
    --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
    --target-os=android \
    --arch=arm \
    --enable-cross-compile \
    --sysroot=$PLATFORM \
    --extra-cflags="-I$PLATFORM/usr/include" \
#    --extra-ldflags="-L$PLATFORM/usr/lib -nostdlib" \ #①这一句我注释掉了,不然会报 ld: -single_module: unknown option

$ADDITIONAL_CONFIGURE_FLAG
sed -i '' 's/HAVE_LRINT 0/HAVE_LRINT 1/g' config.h
sed -i '' 's/HAVE_LRINTF 0/HAVE_LRINTF 1/g' config.h
sed -i '' 's/HAVE_ROUND 0/HAVE_ROUND 1/g' config.h
sed -i '' 's/HAVE_ROUNDF 0/HAVE_ROUNDF 1/g' config.h
sed -i '' 's/HAVE_TRUNC 0/HAVE_TRUNC 1/g' config.h
sed -i '' 's/HAVE_TRUNCF 0/HAVE_TRUNCF 1/g' config.h
sed -i '' 's/HAVE_CBRT 0/HAVE_CBRT 1/g' config.h
sed -i '' 's/HAVE_RINT 0/HAVE_RINT 1/g' config.h

make clean
make -j4
make install
echo "编译完成"
}

# arm v7vfp
CPU=armv7-a
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "
PREFIX=$(pwd)/android/$CPU
ADDITIONAL_CONFIGURE_FLAG=
echo "开始编译ffmpeg"
echo "OPTIMIZE_CFLAGS ${OPTIMIZE_CFLAGS}"
echo "PREFIX ${PREFIX}"
echo "NDK ${NDK}"
echo "TOOLCHAIN ${TOOLCHAIN}"
build_one

4.执行编译脚本

执行build_android.sh这个脚本,如下:

➜  ~ /Users/zhouwen/Desktop/ffmpeg/ffmpeg-4.1.3 
➜  ffmpeg-4.1.3 
➜  ffmpeg-4.1.3 sh build_android.sh 
开始编译ffmpeg
OPTIMIZE_CFLAGS -mfloat-abi=softfp -mfpu=vfp -marm -march=armv7-a 
PREFIX /Users/zhouwen/Desktop/ffmpeg/ffmpeg-4.1.3/android/armv7-a
NDK /Users/zhouwen/Desktop/ffmpeg/android-ndk-r10e
TOOLCHAIN /Users/zhouwen/Desktop/ffmpeg/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64
Unable to create temporary directory in /Users/zhouwen/Desktop/ffmpeg/ffmpeg-4.1.3/ffmpegtemp.

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
[email protected] mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.
GEN libavutil/libavutil.version
GEN libswscale/libswscale.version
GEN libswresample/libswresample.version
GEN libavcodec/libavcodec.version
。
。
。
INSTALL libavutil/tea.h
INSTALL libavutil/lzo.h
INSTALL libavutil/avconfig.h
INSTALL libavutil/ffversion.h
INSTALL libavutil/libavutil.pc
编译完成

5.ffmpeg编译结果

会在android/armv7-a架构目录里生成编解码,滤镜等相关的so文件及include头文件。然后将so及对应的头文件copy到as工程的jniLibs目录下即可。编译so包如下:


FFmpeg编译_第2张图片
image.png

6.打其他CPU平台的包如何打?

看到android_build.sh脚本下面有行:CPU=armv7-a,这是指定打那种cup平台的so包。armv6,arm,x86等


FFmpeg编译_第3张图片
image.png

用以下替换上面的即可打出不同cpu架构的so包

# CPU=armv
# PREFIX=$(pwd)/android/$CPU
# ADDI_CFLAGS="-marm"
# build_one

#arm v6
#CPU=armv6
#OPTIMIZE_CFLAGS="-marm -march=$CPU"
#PREFIX=./android/$CPU 
#ADDITIONAL_CONFIGURE_FLAG=
#build_one

#arm v7vfpv3
# CPU=armv7-a
# OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU "
# PREFIX=./android/$CPU
# ADDITIONAL_CONFIGURE_FLAG=
# build_one

#arm v7n
#CPU=armv7-a
#OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon -marm -march=$CPU -mtune=cortex-a8"
#PREFIX=./android/$CPU 
#ADDITIONAL_CONFIGURE_FLAG=--enable-neon
#build_one

#arm v6+vfp
#CPU=armv6
#OPTIMIZE_CFLAGS="-DCMP_HAVE_VFP -mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU"
#PREFIX=./android/${CPU}_vfp 
#ADDITIONAL_CONFIGURE_FLAG=
#build_one

That's All

你可能感兴趣的:(FFmpeg编译)