4.2.1版本较为难编译
其中关键是arm amrv7 和arm64应该分开编译
编译流程如下
openssl文件请看上篇文章
1.下载ffmpeg gzip文件:http://www.ffmpeg.org/download.html#releases
2.解压gzip文件夹得到ffmpeg-4.2.1文件夹用于arm和armv7的编译。
再解压一次gzip文件夹得到arm64-ffmpeg-4.2.1文件夹等下用于
arm64的编译
3.进入ffmpeg-4.2.1文件夹
4.用记事本打开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)'
5.注释掉openssl的验证代码,后保存并关闭记事本
# enabled openssl && { check_pkg_config openssl openssl openssl/ssl.h OPENSSL_init_ssl ||
# check_pkg_config openssl openssl openssl/ssl.h SSL_library_init ||
# check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto ||
# check_lib openssl openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
# check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
# die "ERROR: openssl not found"; }
6将androidOpenssl文件夹拷贝到当前目录下
7.将编译脚本build_androidWithOpensSL.sh拷贝到当前文件夹下
脚本内容
这里只有arm 和armv7的编译,因为arm64的编译会有其他错误
和arm 和armv7环境相冲突
#!/bin/bash
export NDK_HOME=/Volumes/yeyibo/libs/Android/android-ndk-r14b
function build
{
echo "start build ffmpeg for $CPU"
./configure --target-os=linux \
--prefix=$PREFIX --arch=$ARCH \
--disable-debug \
--disable-doc \
--disable-x86asm \
--disable-asm \
--disable-symver \
--disable-programs \
--disable-htmlpages \
--disable-manpages \
--disable-podpages \
--disable-txtpages \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-everything \
--enable-avcodec \
--enable-avformat \
--enable-swresample \
--enable-swscale \
--enable-network \
--enable-protocols \
--enable-parsers \
--enable-demuxers \
--enable-decoders \
--enable-encoder=mjpeg \
--enable-encoder=aac \
--enable-bsfs \
--enable-shared \
--enable-nonfree \
--cross-prefix=$CROSS_COMPILE \
--enable-cross-compile \
--sysroot=$SYSROOT \
--enable-openssl \
--enable-small \
--extra-cflags="-Os -fpic $ADDI_CFLAGS $ADDI_CFLAGS_OPENSSL" \
--extra-ldflags="$ADDI_LDFLAGS $ADDI_LDFLAGS_OPENSSL" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make -j8
make install
echo "build ffmpeg for $CPU finished"
}
# --enable-openssl \
arm
PLATFORM_VERSION=android-14
ARCH=arm
CPU=armeabi
PREFIX=$(pwd)/android/$CPU
TOOLCHAIN=$NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64
CROSS_COMPILE=$TOOLCHAIN/bin/arm-linux-androideabi-
ADDI_CFLAGS="-marm -mthumb"
ADDI_LDFLAGS=""
ADDI_CFLAGS_OPENSSL="-I/Volumes/WORKSPACE/ffm/ffmAndroid/oldVersion/ffmpeg-4.2.1/androidOpenssl/armeabi/include"
ADDI_LDFLAGS_OPENSSL="-L/Volumes/WORKSPACE/ffm/ffmAndroid/oldVersion/ffmpeg-4.2.1/androidOpenssl/armeabi/lib"
# 绝对路径,相对路径编译不过,不要openssl就打开以下两行
# ADDI_CFLAGS_OPENSSL=""
# ADDI_LDFLAGS_OPENSSL=""
SYSROOT=$NDK_HOME/platforms/$PLATFORM_VERSION/arch-$ARCH/
build
#arm-v7a
PLATFORM_VERSION=android-14
ARCH=arm
CPU=armeabi-v7a
PREFIX=$(pwd)/android/$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"
ADDI_CFLAGS_OPENSSL="-I/Volumes/WORKSPACE/ffm/ffmAndroid/oldVersion/ffmpeg-4.2.1/androidOpenssl/armeabi/include"
ADDI_LDFLAGS_OPENSSL="-L/Volumes/WORKSPACE/ffm/ffmAndroid/oldVersion/ffmpeg-4.2.1/androidOpenssl/armeabi/lib"
#绝对路径,相对路径编译不过,不要openssl就打开以下两行
# ADDI_CFLAGS_OPENSSL=""
# ADDI_LDFLAGS_OPENSSL=""
SYSROOT=$NDK_HOME/platforms/$PLATFORM_VERSION/arch-$ARCH/
build
8.运行脚本
./build_androidWithOpensSL.sh
编译成功后会多出arm和armv7的文件夹
9.在arm64-ffmpeg-4.2.1文件夹中重复步骤4到步骤8
步骤7中脚本内容不一样
#!/bin/bash
export NDK_HOME=/Volumes/yeyibo/libs/Android/android-ndk-r14b
function build
{
echo "start build ffmpeg for $CPU"
./configure --target-os=linux \
--prefix=$PREFIX --arch=$ARCH \
--disable-debug \
--disable-doc \
--disable-x86asm \
--disable-asm \
--disable-symver \
--disable-programs \
--disable-htmlpages \
--disable-manpages \
--disable-podpages \
--disable-txtpages \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-everything \
--enable-avcodec \
--enable-avformat \
--enable-swresample \
--enable-swscale \
--enable-network \
--enable-protocols \
--enable-parsers \
--enable-demuxers \
--enable-decoders \
--enable-encoder=mjpeg \
--enable-encoder=aac \
--enable-bsfs \
--enable-shared \
--enable-nonfree \
--cross-prefix=$CROSS_COMPILE \
--enable-cross-compile \
--sysroot=$SYSROOT \
--enable-openssl \
--enable-small \
--extra-cflags="-Os -fpic $ADDI_CFLAGS $ADDI_CFLAGS_OPENSSL" \
--extra-ldflags="$ADDI_LDFLAGS $ADDI_LDFLAGS_OPENSSL" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make -j8
make install
echo "build ffmpeg for $CPU finished"
}
#arm64
PLATFORM_VERSION=android-21
ARCH=arm64
CPU=arm64
PREFIX=$(pwd)/android/$CPU
TOOLCHAIN=$NDK_HOME/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64
CROSS_COMPILE=$TOOLCHAIN/bin/aarch64-linux-android-
ADDI_CFLAGS=""
ADDI_LDFLAGS=""
ADDI_CFLAGS_OPENSSL="-I/Volumes/WORKSPACE/ffm/ffmAndroid/oldVersion/arm64-ffmpeg-4.2.1/androidOpenssl/armeabi/include"
ADDI_LDFLAGS_OPENSSL="-L/Volumes/WORKSPACE/ffm/ffmAndroid/oldVersion/arm64-ffmpeg-4.2.1/androidOpenssl/armeabi/lib"
#不要openssl打开以下两行
# ADDI_CFLAGS_OPENSSL=""
# ADDI_LDFLAGS_OPENSSL=""
SYSROOT=$NDK_HOME/platforms/$PLATFORM_VERSION/arch-$ARCH/
build
这里我把.a库和.so库都编译出来了,可以自行选择
arm64需要解决4个编译错误
1.libavformat/udp.c 文件 注释290到295行
// mreqs.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
// if (local_addr)
// mreqs.imr_interface= ((struct sockaddr_in *)local_addr)->sin_addr;
// else
// mreqs.imr_interface.s_addr= INADDR_ANY;
// mreqs.imr_sourceaddr.s_addr = ((struct sockaddr_in *)&sources[i])->sin_addr.s_addr;
全局替换
2.libavcodec/aaccoder.c 文件 B0改成b0
3.libavcodec/hevc_mvs.c文件的变量B0改成b0,xB0改成xb0,yB0改成yb0
4.libavcodec/opus_pvq.c文件的变量B0改成b0
到此为止 就可以编译成功了
接下来就是在代码里面测试验证即可。