使用NDK编译ffmpeg4.1+fdk-aac2.0

基本配置
ubuntu18
ffmpeg4.1.3
fdk-aac2.0.0
NDK r20b

编译fdkaac静态库脚本

#!/bin/bash

NDK=/系统ndk路径/android-ndk-r20b
HOST_TAG=linux-x86_64
TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$HOST_TAG

ANDROID_LIB_PATH="$(pwd)/android"

API=21

function build_android_arm
{
echo "build for android $CPU"
./configure \
--host=$HOST \
--disable-shared \
--enable-static \
--prefix="$ANDROID_LIB_PATH/$CPU" \
 CPPFLAGS="-fPIC"

make clean
make -j8
make install
echo "building for android $CPU completed"
}

# armv7
CPU=armv7
HOST=arm-linux-android
export AR=$TOOLCHAIN/bin/arm-linux-androideabi-ar
export AS=$TOOLCHAIN/bin/arm-linux-androideabi-as
export LD=$TOOLCHAIN/bin/arm-linux-androideabi-ld
export RANLIB=$TOOLCHAIN/bin/arm-linux-androideabi-ranlib
export STRIP=$TOOLCHAIN/bin/arm-linux-androideabi-strip
export CC=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang
export CXX=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang++
build_android_arm

# armv8
CPU=armv8
HOST=aarch64-linux-android
export AR=$TOOLCHAIN/bin/aarch64-linux-android-ar
export AS=$TOOLCHAIN/bin/aarch64-linux-android-as
export LD=$TOOLCHAIN/bin/aarch64-linux-android-ld
export RANLIB=$TOOLCHAIN/bin/aarch64-linux-android-ranlib
export STRIP=$TOOLCHAIN/bin/aarch64-linux-android-strip
export CC=$TOOLCHAIN/bin/aarch64-linux-android$API-clang
export CXX=$TOOLCHAIN/bin/aarch64-linux-android$API-clang++
build_android_arm

编译ffmpeg静态库脚本

NDK=/home/kyun/work/ndk/android-ndk-r20b
HOST_TAG=linux-x86_64
TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$HOST_TAG

ANDROID_LIB_PATH="$(pwd)/android"

SYSROOT=$NDK/toolchains/llvm/prebuilt/$HOST_TAG/sysroot

API=21

function build_android_arm
{
echo "Compiling FFmpeg for $CPU"
./configure \
--disable-stripping \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-avdevice \
--disable-devices \
--disable-indevs \
--disable-outdevs \
--disable-asm \
--disable-doc \
--enable-gpl \
--enable-nonfree \
--enable-version3 \
--enable-static \
--disable-shared \
--enable-small \
--enable-dct \
--enable-dwt \
--enable-lsp \
--enable-mdct \
--enable-rdft \
--enable-fft \
--disable-filters \
--disable-postproc \
--disable-bsfs \
--enable-bsf=h264_mp4toannexb \
--enable-bsf=aac_adtstoasc \
--disable-encoders \
--enable-encoder=pcm_s16le \
--disable-decoders \
--enable-decoder=h264 \
--enable-decoder=mp3 \
--enable-decoder=pcm_s16le \
--disable-parsers \
--enable-parser=aac \
--enable-parser=mpegaudio \
--disable-muxers \
--enable-muxer=flv \
--enable-muxer=wav \
--enable-muxer=adts \
--enable-muxer=mp3 \
--disable-demuxers \
--enable-demuxer=flv \
--enable-demuxer=wav \
--enable-demuxer=aac \
--enable-demuxer=mp3 \
--disable-protocols \
--enable-protocol=rtmp \
--enable-protocol=file \
--disable-runtime-cpudetect \
--enable-libfdk-aac \
--enable-encoder=libfdk_aac \
 --enable-decoder=libfdk_aac \
--prefix="$PREFIX" \
--cross-prefix="$CROSS_PREFIX" \
--target-os=android \
--arch="$ARCH" \
--cpu="$CPU" \
--cc="$CC" \
--cxx="$CXX" \
--enable-cross-compile \
--sysroot="$SYSROOT" \
--extra-cflags="-Os -fpic $OPTIMIZE_CFLAGS" \
--extra-ldflags="-Lexternal-lib/fdk-aac/$CPU/"
make clean
make -j8
make install
echo "The Compilation of FFmpeg for $CPU is completed"
}

#armv8-a
ARCH=arm64
CPU=armv8-a
CC=$TOOLCHAIN/bin/aarch64-linux-android$API-clang
CXX=$TOOLCHAIN/bin/aarch64-linux-android$API-clang++
CROSS_PREFIX=$TOOLCHAIN/bin/aarch64-linux-android-
PREFIX=$ANDROID_LIB_PATH/$CPU
OPTIMIZE_CFLAGS="-march=$CPU -Iexternal-lib/fdk-aac/include"
build_android_arm

Tips:集成到Android工程里时,由于是静态库,除引入ffmpeg静态库外,还需引入libfdk-aac.a
本文参考
最新FFMPEG移植Android

你可能感兴趣的:(ffmpeg)