Android FFMPEGFFmpeg移动流媒体

ffmpeg+x264+fdk-aac+lame编译

2019-07-06  本文已影响0人  旁界001
#!/bin/bash
NDK=/mnt/d/IdeSDK/ndk/android-ndk-r14b-linux
SYSROOT=$NDK/platforms/android-14/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64

CPU=armv7-a
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS=""
ADDI_LDFLAGS=""
function build_x264
{
./configure \
    --prefix=$PREFIX \
    --disable-asm \
    --enable-static \
    --enable-shared \
    --enable-pic \
    --enable-strip \
    --host=arm-linux-androideabi \
    --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
    --sysroot=$SYSROOT
    --extra-cflags="-Os -fpic $ADDI_CFLAGS $OPTIMIZE_CFLAGS" \
    --extra-ldflags="$ADDI_LDFLAGS" \
    $ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
}
build_x264

要注意的是,下面两句要加上,因为我要用子模块的静态库编译去编译一个总的ffmepg.so动态库

    --extra-cflags="-Os -fpic $ADDI_CFLAGS $OPTIMIZE_CFLAGS" \
    --extra-ldflags="$ADDI_LDFLAGS" \
#!/bin/bash
NDK=/mnt/d/IdeSDK/ndk/android-ndk-r14b-linux
SYSROOT=$NDK/platforms/android-14/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
CPU=armv7-a
PREFIX=$(pwd)/android/$CPU
PLATFORM=$NDK/platforms/android-14/arch-arm
CROSS_COMPILE=$TOOLCHAIN/bin/arm-linux-androideabi-
CFLAGS=""
FLAGS="--enable-static  --host=$HOST --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"
function build_acc
{
./configure \
    --prefix=$PREFIX \
    --disable-asm \
    --enable-static \
    --enable-shared \
    --target=android \
    --enable-pic \
    --enable-strip \
    --host=arm-linux-androideabi \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
}
build_acc

编译acc的时候,花了好多时间,因为它跟x264的编译方式不是一门路,不用在configure 中配置交叉混编的参数,而是通过设置环境变量的参数来做的,即设置一系列的环境变量

export LDFLAGS=" -L$SYSROOT/usr/lib  $CFLAGS "
export CXXFLAGS=$CFLAGS
export CFLAGS=$CFLAGS
...
#!/bin/bash
NDK=/mnt/d/IdeSDK/ndk/android-ndk-r14b-linux
SYSROOT=$NDK/platforms/android-14/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
HOME=$(dirname "$PWD")
CPU=armv7-a
PREFIX=$(pwd)/android/$CPU

CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-
export CC="${CROSS_PREFIX}gcc --sysroot=${SYSROOT}"
export LD="${CROSS_PREFIX}ld"
export RANLIB="${CROSS_PREFIX}ranlib"
export STRIP="${CROSS_PREFIX}strip"
export READELF="${CROSS_PREFIX}readelf"
export OBJDUMP="${CROSS_PREFIX}objdump"
export ADDR2LINE="${CROSS_PREFIX}addr2line"
export AR="${CROSS_PREFIX}ar"
export AS="${CROSS_PREFIX}as"
export CXX="${CROSS_PREFIX}g++"
export OBJCOPY="${CROSS_PREFIX}objcopy"
export ELFEDIT="${CROSS_PREFIX}elfedit"
export CPP="${CROSS_PREFIX}cpp --sysroot=${SYSROOT}"
export DWP="${CROSS_PREFIX}dwp"
export GCONV="${CROSS_PREFIX}gconv"
export GDP="${CROSS_PREFIX}gdb"
export GPROF="${CROSS_PREFIX}gprof"
export NM="${CROSS_PREFIX}nm"
export SIZE="${CROSS_PREFIX}size"
export STRINGS="${CROSS_PREFIX}strings"
function build_lame
{
./configure \
    --with-pic \
    --prefix=$PREFIX \
    --bindir="$HOME/bin" \
    --enable-nasm \
    --enable-static \
    --enable-shared \
    --host=arm-linux \
    --with-sysroot=$SYSROOT
    $ADDITIONAL_CONFIGURE_FLAG
   #make clean
   #make
   #make install
}
build_lame

这句代码记得加上,--bindir="$HOME/bin" \,另外lame跟acc编译方案类似,采用export配置环境变量的方式去编译脚本

    --extra-cflags="-I$FDK_INCLUDE -I$X264_INCLUDE -I$LAME_INCLUDE" \
    --extra-ldflags="-L$FDK_LIB -L$X264_LIB -L$LAME_LIB" \

这样才能识别到子模块编译的包,打开--enable-gpl \状态
总体脚本如下

#!/bin/bash
# 设置临时文件夹,需要提前手动创建
#export TMPDIR="/home/yangle/ffmpeg/ffmpeg-4.0/ffmpegtemp"
# 设置NDK路径 D:\IdeSDK\ndk\android-ndk-r14b-linux
NDK=/mnt/d/IdeSDK/ndk/android-ndk-r14b-linux
# 设置编译针对的平台,可以根据自己的需求进行设置
# 当前设置为最低支持android-14版本,arm架构
SYSROOT=$NDK/platforms/android-14/arch-arm/
# 设置编译工具链,4.9为版本号
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64

# 设置编译后的文件输出目录
CPU=armv7-a
PREFIX=$(pwd)/android/$CPU
#lix264和libfdk_acc库地址(ffmpeg目录)
LIBS_DIR=$(dirname "$PWD")
#默认路径-L/usr/local/lib
X264_INCLUDE=$LIBS_DIR/x264/android/$CPU/include
X264_LIB=$LIBS_DIR/x264/android/$CPU/lib
FDK_INCLUDE=$LIBS_DIR/fdk-aac-016/android/$CPU/include
FDK_LIB=$LIBS_DIR/fdk-aac-016/android/$CPU/lib
#libmp3lame
LAME_INCLUDE=$LIBS_DIR/lame-3.99.5/android/$CPU/include
LAME_LIB=$LIBS_DIR/lame-3.99.5/android/$CPU/lib
function build_one
{
./configure \
    --arch=arm \
    --enable-small \
    --enable-cross-compile \
    --disable-protocols \
    --enable-protocol=file \
    --enable-protocol=concat \
    --disable-filters \
    --enable-filter=aresample \
    --enable-filter=asetpts \
    --enable-filter=setpts \
    --enable-filter=ass \
    --enable-filter=scale \
    --enable-filter=concat \
    --enable-filter=atempo \
    --enable-filter=movie \
    --enable-filter=overlay \
    --enable-filter=rotate \
    --enable-filter=transpose \
    --enable-filter=hflip \
    --enable-filter=amix \
    --enable-filter=fade \
    --enable-filter=afade \
    --enable-filter=areverse \
    --enable-filter=volume \
    --enable-filter=aevalsrc \
    --enable-filter=adelay \
    --disable-encoders \
    --enable-encoder=libx264 \
    --enable-encoder=libfdk_aac \
    --enable-encoder=aac \
    --enable-encoder=libmp3lame \
    --enable-encoder=mjpeg \
    --enable-encoder=mpeg4 \
    --enable-encoder=rawvideo \
    --enable-encoder=png \
    --enable-encoder=gif \
    --disable-decoders \
    --enable-decoder=rawvideo \
    --enable-decoder=mjpeg \
    --enable-decoder=mpeg4 \
    --enable-decoder=h264 \
    --enable-decoder=aac \
    --enable-decoder=mp3 \
    --enable-decoder=aac_latm \
    --enable-decoder=gif \
    --enable-decoder=png \
    --enable-decoder=pcm_f16le \
    --enable-decoder=pcm_f24le \
    --enable-decoder=pcm_f32be \
    --enable-decoder=pcm_f32le \
    --enable-decoder=pcm_f64be \
    --enable-decoder=pcm_f64le \
    --enable-decoder=libfdk_aac \
    --disable-muxers \
    --enable-muxer=mov \
    --enable-muxer=mp4 \
    --enable-muxer=mp3 \
    --enable-muxer=h264 \
    --enable-muxer=mpjpeg \
    --enable-muxer=rawvideo \
    --enable-muxer=wav \
    --enable-muxer=mpegts \
    --enable-muxer=dts \
    --enable-muxer=gif \
    --enable-muxer=flv \
    --disable-demuxers \
    --enable-demuxer=mov \
    --enable-demuxer=h264 \
    --enable-demuxer=aac \
    --enable-demuxer=mp3 \
    --enable-demuxer=rawvideo \
    --enable-demuxer=avi \
    --enable-demuxer=wav \
    --enable-demuxer=flv \
    --enable-demuxer=gif \
    --enable-demuxer=ogg \
    --enable-demuxer=dts \
    --enable-demuxer=m4v \
    --enable-demuxer=concat \
    --enable-demuxer=mpegts \
    --enable-demuxer=mjpeg \
    --disable-parsers \
    --enable-parser=aac \
    --enable-parser=h264 \
    --enable-parser=mpeg4video \
    --enable-parser=mjpeg \
    --enable-parser=ac3 \
    --enable-parser=png \
    --enable-parser=mpegaudio \
    --enable-zlib \
    --disable-shared \
    --enable-static \
    --enable-version3 \
    --enable-pthreads \
    --disable-network \
    --enable-nonfree \
    --disable-vda \
    --disable-iconv \
    --disable-outdevs \
    --enable-asm \
    --enable-neon \
    --enable-runtime-cpudetect \
    --enable-gpl \
    --enable-libx264 \
    --enable-libfdk-aac \
    --enable-libmp3lame \
    --enable-nonfree \
    --extra-cflags="-I$FDK_INCLUDE -I$X264_INCLUDE -I$LAME_INCLUDE" \
    --extra-ldflags="-L$FDK_LIB -L$X264_LIB -L$LAME_LIB" \
    --enable-jni \
    --enable-mediacodec \
    --disable-debug \
    --enable-ffmpeg \
    --disable-ffplay \
    --disable-ffprobe \
    --disable-ffserver \
    --disable-postproc \
    --enable-avdevice \
    --disable-stripping \
    --disable-doc \
    --disable-symver \
    --prefix=$PREFIX \
    --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
    --target-os=android \
    --cpu=$CPU \
    --sysroot=$SYSROOT \
    --bindir="$LIBS_DIR/bin" \
    --extra-cflags="-DANDROID -fPIC -ffunction-sections -funwind-tables -fstack-protector -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300 -O3 -Wall -pipe -ffast-math -fstrict-aliasing -Werror=strict-aliasing -Wno-psabi -Wa,--noexecstack -DANDROID " \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
}
build_one

$TOOLCHAIN/bin/arm-linux-androideabi-ld \
-rpath-link=$SYSROOT/usr/lib \
-L$SYSROOT/usr/lib \
-L$PREFIX/lib \
-soname libffmpeg.so -shared -nostdlib -Bsymbolic --whole-archive --no-undefined -o \
$PREFIX/libffmpeg.so \
libavcodec/libavcodec.a \
libavfilter/libavfilter.a \
libswresample/libswresample.a \
libavformat/libavformat.a \
$X264_LIB/libx264.a \
$FDK_LIB/libfdk-aac.a \
$LAME_LIB/libmp3lame.a \
libavutil/libavutil.a \
libswscale/libswscale.a \
libavdevice/libavdevice.a \
libpostproc/libpostproc.a \
-lc -lm -lz -ldl -llog --dynamic-linker=/system/bin/linker \
$TOOLCHAIN/lib/gcc/arm-linux-androideabi/4.9.x/libgcc.a \
上一篇下一篇

猜你喜欢

热点阅读