最近需要测试HEVC解码的性能,因此需要将ffmpeg编译成可以执行文件,并移植到Android采用adb shell测试,准备工作如下:
- 操作系统Ubuntu 12.04
- 下载android-ndk32-r10e-Linux-x86_64.tar.bz2
- 安装yasm
- 下载源码https://github.com/FFmpeg/FFmpeg
操作流程
- mkdir ffmpeg-android
- cp -R FFmpeg-release-3.2 ffmpeg-android/
- cp ffmpeg_android.sh ffmpeg-android/
- cd ffmpeg-android/
- mv FFmpeg-release-3.2 ffmpeg
- ./ffmpeg_android.sh
注意:此处不能用sh ffmpeg_android.sh,不然会报错,如下:
/home/yangxiaoxiang/tools/android_tools/ndk//build/tools/make-standalone-toolchain.sh: 730: /home/yangxiaoxiang/tools/android_tools/ndk//build/tools/make-standalone-toolchain.sh: Syntax error: redirection unexpected
脚本代码ffmpeg_android.sh
#!/bin/bash
DEST=`pwd`/build/ffmpeg && rm -rf $DEST
SOURCE=`pwd`/ffmpeg
export ANDROID_NDK=/home/yangxiaoxiang/tools/android_tools/ndk/
SYSROOT=$ANDROID_NDK/platforms/android-14/arch-arm
TOOLCHAIN=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
CC=$TOOLCHAIN/bin/arm-linux-androideabi-gcc
NM=$TOOLCHAIN/bin/arm-linux-androideabi-nm
$ANDROID_NDK/build/tools/make-standalone-toolchain.sh --platform=android-14 --install-dir=$DEST/install --toolchain=arm-linux-androideabi-4.9
export PATH=$TOOLCHAIN/bin:$PATH
export LD=arm-linux-androideabi-ld
export AR=arm-linux-androideabi-ar
CFLAGS="-O3 -Wall -mthumb -pipe -fpic -fasm \ -finline-limit=300 -ffast-math \ -fstrict-aliasing -Werror=strict-aliasing \ -fmodulo-sched -fmodulo-sched-allow-regmoves \ -Wno-psabi -Wa,--noexecstack \ -D__ARM_ARCH_5__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5TE__ \ -DANDROID -DNDEBUG"
FFMPEG_FLAGS="--target-os=linux \ --arch=arm \ --cpu=armv7-a \ --enable-cross-compile \ --cross-prefix=arm-linux-androideabi- \ --disable-shared \ --disable-symver \ --disable-doc \ --disable-ffplay \ --disable-filters \ --disable-devices \ --disable-ffprobe \ --disable-ffserver \ --disable-avdevice \ --enable-ffmpeg \ --enable-encoders \ --enable-decoders \ --enable-bsfs \ --enable-neon \ --enable-swscale \ --enable-asm \ --enable-version3"
for version in armv7 ; do
cd $SOURCE
case $version in
armv7)
EXTRA_CFLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -marm -mtune=cortex-a8"
EXTRA_LDFLAGS="-Wl,--fix-cortex-a8"
;;
armv8)
EXTRA_CFLAGS="-march=armv8-a -mfpu=neon -mfloat-abi=softfp -marm -mtune=cortex-a8"
EXTRA_LDFLAGS="-Wl,--fix-cortex-a8"
;;
*)
EXTRA_CFLAGS=""
EXTRA_LDFLAGS=""
;;
esac
PREFIX="$DEST/$version" && mkdir -p $PREFIX
FFMPEG_FLAGS="$FFMPEG_FLAGS --prefix=$PREFIX"
./configure $FFMPEG_FLAGS --extra-cflags="$CFLAGS $EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" | tee $PREFIX/configuration.txt
cp config.* $PREFIX
[ $PIPESTATUS == 0 ] || exit 1
make clean
make -j4 || exit 1
make install || exit 1
done
注意:export ANDROID_NDK=/home/yangxiaoxiang/tools/android_tools/ndk/
为NDK安装位置