文章参阅:https://blog.csdn.net/ericbar/article/details/76602720
FFmpeg编译成Android动态库 https://blog.csdn.net/chenxiaoping1993/article/details/80306928
Android Studio上进行ffmpeg开发 https://blog.csdn.net/yu544324974/article/details/77851429
在Android源码中如何吧so库打包编译进入apk, 集成第三方库(jar和so库)
https://blog.csdn.net/petib_wangwei/article/details/72844515
Android Studio打包.so库到apk中https://blog.csdn.net/way_ping_li/article/details/44631017
编译Android下可用的全平台FFmpeg(包含libx264与libfdk-aac)
https://blog.csdn.net/mabeijianxi/article/details/74544879
利用FFmpeg玩转Android视频录制与压缩https://blog.csdn.net/mabeijianxi/article/details/72983362
Android 集成 FFmpeg (一) 基础知识及简单调用https://blog.csdn.net/yhaolpz/article/details/76408829
1> 下载NDK及相应的代码
NDK下载:https://developer.android.google.cn/ndk/downloads/
FFmpeg源码下载地址:http://ffmpeg.org/download.html
libx264下载地址:http://www.videolan.org/developers/x264.html
libfdk-aac下载地址:http://www.linuxfromscratch.org/blfs/view/7.7/multimedia/fdk-aac.html
清单:
NDK: android-ndk-r16b
ffmpeg直接下载:git clone https://git.ffmpeg.org/ffmpeg.git
libx264直接下载最新: git clone http://git.videolan.org/git/x264.git
libfdk-aac: fdk-aac-2.1.tar.gz
将libx264及libfdkaac解压到ffmpeg目录下。
2> 选择make_standalone_toolchain的方式来制作编译链
cd /home/likai/Android/Sdk/ndk-bundle/build/tools
python make_standalone_toolchain.py --api 19 --install-dir /home/likai/workspace/my_toolchain --arch arm --stl libc++ --force
#如果是arm64
python make_standalone_toolchain.py --api 19 --install-dir /home/likai/workspace/my_toolchain64 --arch arm64 --stl libc++ --force
下面以编译arm-v7a为例,arm64-v8a及x86 x86_64一样同理。
3> 编译libx264
在libx264目录下新建配置及编译脚本my_build_libx264_arm.sh
#!/bin/bash
export TOOLCHAIN=/home/likai/workspace/my_toolchain
export PLATFORM=/home/likai/workspace/my_toolchain/sysroot
basepath=$(cd `dirname $0`; pwd)
echo "$basepath"
CPU=arm
PREFIX=${basepath}/android/$CPU
./configure \
--prefix=$PREFIX \
--enable-static \
--disable-asm \
--enable-pic \
--enable-strip \
--host=arm-linux-androideabi \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--sysroot=$PLATFORM \
--extra-cflags="-Os -fpic" \
--extra-ldflags="" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make -j4
make install
增加777权限,执行编译
chmod 777 my_build_libfdkaac_arm.sh
sh my_build_libfdkaac_arm.sh
4> 编译libfdkaac
在libfdkaac目录下新建配置及编译脚本
#!/bin/bash
export TOOLCHAIN=/home/likai/workspace/my_toolchain
export SYSROOT=$TOOLCHAIN/sysroot
export ANDROID_BIN=$TOOLCHAIN/bin
export CROSS_COMPILE=${ANDROID_BIN}/arm-linux-androideabi-
basepath=$(cd `dirname $0`; pwd)
echo "$basepath"
CPU=arm
PREFIX=${basepath}/android/$CPU
CFLAGS=""
FLAGS="--enable-static --host=arm-linux-androideabi --target=android --disable-asm "
export CXX="${CROSS_COMPILE}g++ --sysroot=${SYSROOT}"
export LDFLAGS=" -L$SYSROOT/usr/lib $CFLAGS "
export CXXFLAGS=$CFLAGS
export CFLAGS=$CFLAGS
export CC="${CROSS_COMPILE}gcc --sysroot=${SYSROOT}"
export AR="${CROSS_COMPILE}ar"
export LD="${CROSS_COMPILE}ld"
export AS="${CROSS_COMPILE}gcc"
./configure $FLAGS \
--enable-pic \
--enable-strip \
--prefix=$PREFIX
$ADDITIONAL_CONFIGURE_FLAG
make clean
make -j16
make install
这里要修改m4目录下的libtool.m4文件,让其生成的是.so格式的文件,而不是.so.版本
全局搜索 so.1,替换为 so
全局搜索 $versuffix ,替换为空字符,也就是删除它
全局搜索 $major ,,替换为空字符,也就是删除它
增加my_build_libfdkaac_arm.sh 777权限,执行编译
chmod 777 my_build_libfdkaac_arm.sh
sh my_build_libfdkaac_arm.sh
5> 编译ffmpeg
修改/home/likai/workspace/my_toolchain/sysroot/usr/include/asm-generic/termbits.h:118:#define B0 0000000
将#define B0 0000000屏蔽掉,如果不屏蔽会冲突。
在ffmpeg目录下创建配置编译脚本my_build_ffmpeg_with_x264_fdkaac_for_arm-v7a.sh
#!/bin/bash
basepath=$(cd `dirname $0`; pwd)
export TOOLCHAIN=/home/likai/workspace/my_toolchain
export PLATFORM=$TOOLCHAIN/sysroot
export LIBPATH=$PLATFORM/usr/lib
CPU=arm-v7a
PREFIX=$basepath/android/$CPU
echo $basepath
FDK_INCLUDE=$basepath/libfdkaac/android/arm/include
FDK_LIB=$basepath/libfdkaac/android/arm/lib
X264_INCLUDE=$basepath/libx264/android/arm/include
X264_LIB=$basepath/libx264/android/arm/lib
FF_EXTRA_CFLAGS="-DANDROID -fPIC -ffunction-sections -funwind-tables -fstack-protector -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fomit-frame-pointer -fstrict-aliasing "
FF_CFLAGS="-O3 -Wall -pipe \
-ffast-math \
-fstrict-aliasing -Werror=strict-aliasing \
-Wa,--noexecstack \
-DANDROID "
#EXTRA_CFLAGS="-marm -I../libx264/android/$CPU/include"
#EXTRA_LDFLAGS="-L../libx264/android/$CPU/lib"
echo " "
echo "please wait..."
echo " "
rm "./compat/strtod.o"
rm ./$PREFIX -rf
make clean
echo " "
echo "preparing to configure..."
echo " "
./configure \
--prefix=$PREFIX \
--enable-cross-compile \
--disable-runtime-cpudetect \
--disable-asm \
--arch=arm \
--target-os=android \
--cc=$TOOLCHAIN/bin/arm-linux-androideabi-gcc \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--disable-stripping \
--nm=$TOOLCHAIN/bin/arm-linux-androideabi-nm \
--sysroot=$PLATFORM \
--extra-cflags="-I$X264_INCLUDE -I$FDK_INCLUDE " \
--extra-ldflags="-L$FDK_LIB -L$X264_LIB" \
--enable-gpl \
--enable-shared \
--disable-static \
--enable-version3 \
--enable-pthreads \
--enable-small \
--disable-iconv \
--disable-encoders \
--enable-libx264 \
--enable-neon \
--enable-yasm \
--enable-libfdk_aac \
--enable-encoder=libx264 \
--enable-encoder=libfdk_aac \
--enable-encoder=mjpeg \
--enable-encoder=png \
--enable-nonfree \
--enable-muxers \
--enable-muxer=mov \
--enable-muxer=mp4 \
--enable-muxer=h264 \
--enable-muxer=avi \
--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 \
--enable-demuxer=avi \
--enable-demuxer=mpc \
--enable-demuxer=mov \
--enable-demuxer=mpegts \
--disable-parsers \
--enable-parser=aac \
--enable-parser=ac3 \
--enable-parser=h264 \
--enable-protocols \
--enable-zlib \
--enable-avfilter \
--disable-outdevs \
--disable-ffprobe \
--disable-ffplay \
--disable-ffmpeg \
--disable-debug \
--disable-ffprobe \
--disable-ffplay \
--disable-ffmpeg \
--disable-postproc \
--disable-avdevice \
--disable-symver \
--disable-stripping \
--extra-cflags="$FF_EXTRA_CFLAGS $FF_CFLAGS" \
--extra-ldflags=" "
echo "sleep 5s ..."
sleep 5s
echo "make"
make clean
make -j16
echo "sleep 3s ..."
sleep 3s
echo "make install"
make install
cp $FDK_LIB/libfdk-aac.so $PREFIX/lib
然后执行配置脚本
chmod 777 my_build_ffmpeg_with_x264_fdkaac_for_arm-v7a.sh
sh my_build_ffmpeg_with_x264_fdkaac_for_arm-v7a.sh