</pre><pre name="code" class="plain">#!/bin/bash # # FFmpeg-Android, a bash script to build FFmpeg for Android. # # Copyright (c) 2012 Cedric Fung <[email protected]> # # FFmpeg-Android will build FFmpeg for Android automatically, # with patches from VPlayer's Android version <https://vplayer.net/>. # # FFmpeg-Android is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 3 of the License, or (at your option) any later version. # FFmpeg-Android is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # You should have received a copy of the GNU Lesser General Public # License along with FFmpeg-Android; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # # Instruction: # # 0. Install git and Android ndk # 1. $ export ANDROID_NDK=/path/to/your/android-ndk # 2. $ ./FFmpeg-Android.sh # 3. libffmpeg.so will be built to build/ffmpeg/{neon,armv7,vfp,armv6}/ # # DEST=`pwd`/build/ffmpeg && rm -rf $DEST SOURCE=`pwd`/ffmpeg ANDROID_NDK=/work/FFMPEG/android-ndk-r10b TOOLCHAIN=/work/FFMPEG/toolchain SYSROOT=$TOOLCHAIN/sysroot/ #$ANDROID_NDK/build/tools/make-standalone-toolchain.sh --platform=android-14 --install-dir=$TOOLCHAIN export PATH=$TOOLCHAIN/bin:$PATH export CC="ccache arm-linux-androideabi-gcc" 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="--prefix=/work/FFMPEG/ffmpeg_android/ \ --target-os=android \ --arch=arm \ --enable-cross-compile \ --cross-prefix=arm-linux-androideabi- \ --enable-shared \ --disable-symver \ --disable-doc \ --disable-ffplay \ --disable-ffmpeg \ --disable-ffprobe \ --disable-ffserver \ --disable-avdevice \ --disable-avfilter \ --disable-encoders \ --disable-muxers \ --disable-bsfs \ --disable-filters \ --disable-devices \ --disable-everything \ --enable-protocols \ --enable-parsers \ --enable-demuxers \ --disable-demuxer=sbg \ --enable-decoders \ --enable-network \ --enable-swscale \ --enable-version3 \ --disable-inline-asm \ --disable-yasm \ --disable-mips32r2 \ --disable-mipsdspr1 \ --disable-mipsdspr2 \ --disable-mipsfpu \ --disable-fast-unaligned \ --disable-debug \ --disable-xmm-clobber-test \ --enable-decoder=h264 \ --enable-decoder=mpeg4 \ --enable-decoder=mjpeg \ --enable-demuxer=h264 \ --enable-demuxer=mpeg4 \ --enable-demuxer=mjpeg \ --enable-parser=h264 \ --enable-memalign-hack \ --disable-asm \ --disable-altivec \ --disable-amd3dnow \ --disable-amd3dnowext \ --enable-mmx \ --enable-mmxext \ --disable-sse \ --disable-sse2 \ --disable-sse3 \ --disable-ssse3 \ --disable-sse4 \ --disable-fma4" for version in neon armv7 vfp armv6; do cd $SOURCE case $version in neon) EXTRA_CFLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -mvectorize-with-neon-quad" EXTRA_LDFLAGS="-Wl,--fix-cortex-a8" ;; armv7) EXTRA_CFLAGS="-march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp" EXTRA_LDFLAGS="-Wl,--fix-cortex-a8" ;; vfp) EXTRA_CFLAGS="-march=armv6 -mfpu=vfp -mfloat-abi=softfp" EXTRA_LDFLAGS="" ;; armv6) EXTRA_CFLAGS="-march=armv6" EXTRA_LDFLAGS="" ;; *) 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 rm libavcodec/inverse.o $CC -lm -lz -shared --sysroot=$SYSROOT -Wl,--no-undefined -Wl,-z,noexecstack $EXTRA_LDFLAGS libavutil/*.o libavutil/arm/*.o libavcodec/*.o libavcodec/arm/*.o libavformat/*.o libswresample/*.o libswscale/*.o -o $PREFIX/libffmpeg.so cp $PREFIX/libffmpeg.so $PREFIX/libffmpeg-debug.so arm-linux-androideabi-strip --strip-unneeded $PREFIX/libffmpeg.so done
3、注意NDK的版本,如果应用代码中使用的是32位系统库,则交叉编译的时候就应该用32位的NDK开发包。