@音视频
下载NDK
从NDK官网下载NDK,并上传到服务器任意目录,本文上传到/home/syq目录中。
当前最新稳定版为r21b。
从NDK导出工具链
cd /home/syq/android-ndk-r21b #NDK的安装目录
./make-standalone-toolchain.sh --platform=android-24 --install-dir=/home/syq/android-toolchain --force #生成工具链
编译脚本
#!/bin/bash
NDK_TOOLCHAIN_DIR=/home/syq/android-toolchain/
INSTALL_DIR=/home/syq/install/ffmpeg
CONFIGURE_FLAGS="--disable-shared --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-avdevice --disable-devices --disable-indevs --disable-outdevs --disable-debug --disable-asm --disable-x86asm --disable-doc --enable-small --enable-dct --enable-dwt --enable-lsp --enable-mdct --enable-rdft --enable-fft --enable-version3 --enable-nonfree --disable-filters --disable-postproc --disable-bsfs --enable-bsf=aac_adtstoasc --enable-bsf=h264_mp4toannexb --disable-decoders --disable-decoders --enable-decoder=mp3 --disable-parsers --disable-muxers --enable-muxer=flv --enable-muxer=wav --disable-demuxers --enable-demuxer=flv --enable-demuxer=wav --disable-protocols --enable-protocol=rtmp --enable-protocol=file --enable-cross-compile --prefix=$INSTALL_DIR"
#--enable-encoder=aac #--enable-decoder=aac #--enable-parser=aac #--enable-libx264 #--enable-libfdk_aac
./configure $CONFIGURE_FLAGS --target-os=linux --arch=arm --cross-prefix=$NDK_TOOLCHAIN_DIR/bin/arm-linux-androideabi-
编译过程中的错误:
libavcodec/aaccoder.c:803:25: error: expected identifier or '('
int B0 = 0, B1 = 0;
^
/home/syq/android-toolchain//bin/../sysroot/usr/include/asm-generic/termbits.h:118:12: note: expanded from macro 'B0'
#define B0 0000000
^
libavcodec/aaccoder.c:865:28: error: expression is not assignable
B0 += b1+b2;
~~ ^
libavcodec/aaccoder.c:866:25: error: use of undeclared identifier 'B1'
B1 += b3+b4;
^
libavcodec/aaccoder.c:870:62: error: use of undeclared identifier 'B1'
cpe->ms_mask[w*16+g] = dist2 <= dist1 && B1 < B0;
^
libavcodec/aaccoder.c:882:32: error: use of undeclared identifier 'B1'
} else if (B1 > B0) {
^
原因:ffmpeg的变量定义与工具链头文件中的宏定义冲突。
解决办法:修改ffmpeg中的变量定义。
附
X86 ffmpeg编译
#!/bin/bash
INSTALL_DIR=/home/syq/install/ffmpeg_x86
CONFIGURE_FLAGS="--prefix=$INSTALL_DIR --disable-shared --enable-gpl \
--disable-asm --disable-x86asm --enable-filter=aresample --enable-bsf=aac_adtstoasc \
--enable-small --enable-dct --enable-dwt --enable-lsp --enable-mdct --enable-rdft --enable-fft --enable-version3 \
--enable-nonfree --enable-decoder=mp3 --disable-decoder=h264_vda --disable-d3d11va --disable-dxva2 --disable-vaapi --disable-vdpau \
--disable-videotoolbox --disable-securetransport \
--enable-muxer=h264 --enable-encoder=libx264 --enable-libx264 --enable-encoder=libfdk_aac --enable-libfdk_aac"
./configure $CONFIGURE_FLAGS --extra-cflags="-Iexternal-libs/x264/include -Iexternal-libs/fdk-aac/include" --extra-ldflags="-Lexternal-libs/x264/lib -Lexternal-libs/fdk-aac/lib"
X86 x264编译
#!/bin/bash
INSTALL_DIR=/home/syq/install/x264-x86
CONFIGURE_FLAGS="--prefix=$INSTALL_DIR --enable-static --enable-shared --disable-asm"
./configure $CONFIGURE_FLAGS
make -j8
make install