博客:http://www.weibo.com/xdpan
工程地址:http://code.google.com/p/kudou-player/
----------------------------------------------------
Ffmpeg android编译网上已经写了很多,这里也是参考了网上的一些例子写成,目前有两种方法,一种是写一些Android.mk文件,采用ndk-build套件进行编译,另外一种是采用ffmpeg的原始Makefile文件,指定gcc和链接库。我们采用第二种。为了文章每个章节独立成文,ffmpeg编译也从搭建环境开始。
1. 搭建NDK编译环境
下载NDK
cd/home/xdpan/work
axel -n4 http://dl.google.com/android/ndk/android-ndk-r8d-linux-x86.tar.bz2
tar -xvfandroid-ndk-r8d-linux-x86.tar.bz2
mvandroid-ndk-r8d-linux-x86 /home/xdpan/ndkr8
修改环境变量
echo"xport PATH=$PATH:/home/xdpan/ndkr8" >> /home/xdpan/.bashrc
source /home/xdpan/.bashrc
2. 编译ffmpeg
下载ffmpeg
axel -n4http://www.ffmpeg.org/releases/ffmpeg-0.11.1.tar.gz
tar -xvfffmpeg-0.11.1.tar.gz
cd ffmpeg-0.11.1
mkdir -p broov/v7neon/
mkdir -pandroid/armv7-a/
编写编译脚本,我们这里只编译armv7 neon的包,建立kuplayer_build.sh文件如下:
#!/bin/bash
######################################################
# Usage:
# put thisscript in top of FFmpeg source tree
# ./build_android
# Itgenerates binary for following architectures:
# ARM V5
# ARM v6
# ARM v6+VFP
# ARMv7+VFPv3-d16 (Tegra2)
# ARM v7+Neon(Cortex-A8)
# Intel X86
#
#Customizing:
# 1. Feelfree to change ./configure parameters for more features
# 2. To adaptother ARM variants
# set $CPUand $OPTIMIZE_CFLAGS
# callbuild_one
######################################################
NDK=/home/xdpan/ndkr8
PLATFORM=$NDK/platforms/android-8/arch-arm/
PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
CPU=armv7-a
OPTIMIZE_CFLAGS="-mfloat-abi=softfp-mfpu=neon -march=$CPU -mtune=cortex-a8 -Wno-multichar -fno-exceptions "
PREFIX=./android/$CPU
ADDITIONAL_CONFIGURE_FLAG="--arch=arm--cpu=armv7-a --enable-armv5te --enable-armv6 --enable-armvfp --enable-memalign-hack--enable-neon"
./configure--target-os=linux \
--prefix=$PREFIX\
--enable-cross-compile\
--extra-libs="-lgcc"\
--cc=$PREBUILT/bin/arm-linux-androideabi-gcc\
--cross-prefix=$PREBUILT/bin/arm-linux-androideabi-\
--nm=$PREBUILT/bin/arm-linux-androideabi-nm\
--sysroot=$PLATFORM\
--extra-cflags="-O3 -fpic -DANDROID -DHAVE_SYS_UIO_H=1 -Dipv6mr_interface=ipv6mr_ifindex -fasm-Wno-psabi -fno-short-enums -fno-strict-aliasing -finline-limit=300$OPTIMIZE_CFLAGS " \
--enable-gpl\
--enable-version3\
--disable-shared\
--enable-static\
--extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib-L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog " \
--enable-parsers\
--enable-decoders\
--enable-demuxers\
--enable-network\
--enable-protocols\
--enable-protocol=file\
--enable-swscale \
--enable-swresample\
--enable-avformat\
--enable-avcodec\
--disable-ffmpeg\
--disable-ffplay\
--disable-ffprobe\
--disable-ffserver\
--disable-devices\
--disable-avdevice\
--disable-postproc\
--disable-avfilter\
--disable-swscale-alpha\
--disable-bsfs\
--disable-encoders\
--disable-muxers\
--disable-indevs\
--disable-debug\
--disable-doc\
--disable-demuxer=srt\
--disable-demuxer=microdvd\
--disable-demuxer=jacosub\
--disable-demuxer=dts\
--disable-decoder=ass\
--disable-decoder=srt\
--disable-decoder=microdvd\
--disable-decoder=jacosub\
--enable-zlib\
--enable-pic\
--enable-optimizations\
$ADDITIONAL_CONFIGURE_FLAG
#make clean
make -j4 install
$PREBUILT/bin/arm-linux-androideabi-ard libavcodec/libavcodec.a inverse.o
$PREBUILT/bin/arm-linux-androideabi-ld-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -soname libffmpeg.so -shared -nostdlib -z,noexecstack -Bsymbolic --whole-archive--no-undefined -o $PREFIX/libffmpeg.so libavcodec/libavcodec.alibavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.alibswresample/libswresample.a -lc -lm-lz -ldl -llog --warn-once --dynamic-linker=/system/bin/linker$PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a
$PREBUILT/bin/arm-linux-androideabi-stripandroid/armv7-a/libffmpeg.so
cp config.hbroov/v7neon/.
cp config.logbroov/v7neon/.
执行:
看到 broov/v7neon下的libffmpeg.so说明编译成功
3. 参考:
http://code.google.com/p/dolphin-player/
https://sites.google.com/site/mxvpen/download
编辑脚本源文件(或者在虚拟机对应目录中提取)
kuplayer_bulid.sh