ffmpeg(2.6) rockplayer android 下编译 小记.

最近因为一些需求,开始学习 ffmgeg 在android 上使用.

使用的环境:

1,VMware V8 虚似机 安装的 FedoraV18 系统.(下载地址,请baidu),虚似机,最好有20-30G的空间,ndk解压占用,1.5G android-ndk-r10b

2,android-ndk32-r10b-linux-x86.tar.tar 下载地址(目前 天C 的力量,所以 http://developer.android.com/sdk/index.html 无法打开 ):

http://wear.techbrood.com/tools/sdk/ndk/index.html (据说 sdk是同步的.)

3,ffmpeg-2.6.tar.bz2

下载地址:http://ffmpeg.org/download.html#releases

4,rockplayer_ffmpeg_git_20100418.zip  

rockplayer 是什么?

  

Rockplayer受益于开源项目,也回报开源社区。

    • 1.7.0开始使用的FFmpeg库

      包含了取自git master repository的FFmpeg源码、RockPlayer使用的脚本。脚本内含详细的文档。

    • 1.7.0之前使用的FFmpeg库

      包含了FFmpeg源码,NDK需要的android.mk。请根据需要注释或放出所需要的变量组,更多说明见zip包里的readme.rockplayer。

    • ...

下载地址:http://www.rockplayer.com/download/rockplayer_ffmpeg_git_20100418.zip

  

  5,SSH Secure Shell Client 连接linux .(baidu SSH Secure Shell Client 下载).

感谢:

褐色狸花猫 的文章 <FFmpeg在Android上的移植之第一步>:http://blog.sina.com.cn/s/blog_69a04cf40100x1fr.html

 的文章 <How to Build FFmpeg for Android> :http://www.roman10.net/how-to-build-ffmpeg-for-android/

http://stackoverflow.com/questions/24853599/compiling-ffmpeg-2-3-with-android-ndk-r10

   http://www.roman10.net/how-to-build-android-applications-based-on-ffmpeg-by-an-example/

开始:

  1,解压 ndk.使用 tar 命令解压 android-ndk32-r10b-linux-x86.tar.tar 包 (tar --help 查看帮助) 解压到指定位置,

  本例中是:/home/android-ndk-r10b   .

  2,解压 ffmpge,或 rockplayer . (unzip --help)

  本例中是:/home/test

  

  3,build ffmpeg 或rockplayer .

  3.1 ffmpeg 的 build_andriod_ffmpeg_right.sh 是:

正确sh

#!/bin/bash

######################################################
# FFmpeg builds script for Android+ARM platform
#
# This script is released under term of 
#   CDDL (http://www.opensource.org/licenses/cddl1) 
# Wrote by pinxue (~@gmail.com) from RockPlayer.com
#                                   2010-8 ~ 2011-4
######################################################

######################################################
# Usage:
#   put this script in top of FFmpeg source tree
#   ./build_android
#
# It generates binary for following architectures:
#     ARMv6 
#     ARMv6+VFP 
#     ARMv7+VFPv3-d16 (Tegra2) 
#     ARMv7+Neon (Cortex-A8)
#
# Customizing:
# 1. Feel free to change ./configure parameters for more features
# 2. To adapt other ARM variants
#       set $CPU and $OPTIMIZE_CFLAGS 
#       call build_one
######################################################

NDK=/home/android-ndk-r10b
PLATFORM=$NDK/platforms/android-18/arch-arm/
PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86


function build_one
{
./configure --target-os=linux 
    --prefix=$PREFIX 
    --enable-cross-compile 
    --extra-libs="-lgcc" 
    --arch=arm 
    --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 " 
    --disable-shared 
    --enable-static 
    --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" 
    --disable-everything 
    --enable-demuxer=mov 
    --enable-demuxer=h264 
    --disable-ffplay 
    --enable-protocol=file 
    --enable-avformat 
    --enable-avcodec 
    --enable-decoder=rawvideo 
    --enable-decoder=mjpeg 
    --enable-decoder=h263 
    --enable-decoder=mpeg4 
    --enable-decoder=h264 
    --enable-parser=h264 
    --disable-network 
    --enable-zlib 
    --disable-avfilter 
    --disable-avdevice 
    $ADDITIONAL_CONFIGURE_FLAG

make clean
make  -j4 install
$PREBUILT/bin/arm-linux-androideabi-ar d 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.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog  --warn-common  --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.8/libgcc.a
}

# arm v6
CPU=armv6
OPTIMIZE_CFLAGS="-marm -march=$CPU"
PREFIX=./android/$CPU 
ADDITIONAL_CONFIGURE_FLAG=
build_one

#arm v7vfpv3
CPU=armv7-a
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU "
PREFIX=./android/$CPU
ADDITIONAL_CONFIGURE_FLAG=
build_one

#arm v7vfp
CPU=armv7-a
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "
PREFIX=./android/$CPU-vfp
ADDITIONAL_CONFIGURE_FLAG=
build_one

#arm v7n
CPU=armv7-a
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon -marm -march=$CPU -mtune=cortex-a8"
PREFIX=./android/$CPU-v7n 
ADDITIONAL_CONFIGURE_FLAG=--enable-neon
build_one

#arm v6+vfp
CPU=armv6
OPTIMIZE_CFLAGS="-DCMP_HAVE_VFP -mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU"
PREFIX=./android/${CPU}_vfp 
ADDITIONAL_CONFIGURE_FLAG=
build_one

 rockplayer 的 build_andriod_rockplayer_right.sh 是:

正确sh

#!/bin/bash

######################################################
# FFmpeg builds script for Android+ARM platform
#
# This script is released under term of 
#   CDDL (http://www.opensource.org/licenses/cddl1) 
# Wrote by pinxue (~@gmail.com) from RockPlayer.com
#                                   2010-8 ~ 2011-4
######################################################

######################################################
# Usage:
#   put this script in top of FFmpeg source tree
#   ./build_android
#
# It generates binary for following architectures:
#     ARMv6 
#     ARMv6+VFP 
#     ARMv7+VFPv3-d16 (Tegra2) 
#     ARMv7+Neon (Cortex-A8)
#
# Customizing:
# 1. Feel free to change ./configure parameters for more features
# 2. To adapt other ARM variants
#       set $CPU and $OPTIMIZE_CFLAGS 
#       call build_one
######################################################

NDK=/home/android-ndk-r10b
PLATFORM=$NDK/platforms/android-18/arch-arm/
PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86


function build_one_r6
{
./configure 
    --disable-shared 
    --enable-static 
    --enable-gpl 
    --enable-version3 
    --enable-nonfree 
    --disable-doc 
    --disable-ffmpeg 
    --disable-ffplay 
    --disable-ffprobe 
    --disable-ffserver 
    --disable-avdevice 
    --disable-avfilter 
    --disable-postproc 
    --enable-small 
    --cross-prefix=$PREBUILT/bin/arm-linux-androideabi- 
    --enable-cross-compile 
    --target-os=linux 
    --extra-cflags="-I$PLATFORM/usr/include" 
    --extra-ldflags="-L$PLATFORM/usr/lib -nostdlib" 
    --arch=arm 
    --disable-symver 
    --disable-debug 
    --disable-stripping 
    $ADDITIONAL_CONFIGURE_FLAG
sed -i 's/HAVE_LRINT 0/HAVE_LRINT 1/g' config.h
sed -i 's/HAVE_LRINTF 0/HAVE_LRINTF 1/g' config.h
sed -i 's/HAVE_ROUND 0/HAVE_ROUND 1/g' config.h
sed -i 's/HAVE_ROUNDF 0/HAVE_ROUNDF 1/g' config.h
sed -i 's/HAVE_TRUNC 0/HAVE_TRUNC 1/g' config.h
sed -i 's/HAVE_TRUNCF 0/HAVE_TRUNCF 1/g' config.h
make clean
make  -j4 install
$PREBUILT/bin/arm-linux-androideabi-ar d 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.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog  --warn-common  --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.8/libgcc.a
}
function build_one_r6_2
{
$PREBUILT/bin/arm-linux-androideabi-ar d 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.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog  --warn-common  --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.8/libgcc.a
}

#arm armv6
CPU=armv6-a
OPTIMIZE_CFLAGS="-marm -march=$CPU"
PREFIX=./android/$CPU 
ADDITIONAL_CONFIGURE_FLAG=
build_one_r6

#arm v7vfpv3
CPU=armv7-a
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU "
PREFIX=./android/$CPU-vfpv3 
ADDITIONAL_CONFIGURE_FLAG=
build_one_r6

#arm v7vfp
CPU=armv7-a
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "
PREFIX=./android/$CPU-vfp
ADDITIONAL_CONFIGURE_FLAG=
build_one_r6

#arm v7n
CPU=armv7-a
OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon -marm -march=$CPU -mtune=cortex-a8"
PREFIX=./android/$CPU 
ADDITIONAL_CONFIGURE_FLAG=--enable-neon
build_one_r6

#arm v6+vfp
CPU=armv6
OPTIMIZE_CFLAGS="-DCMP_HAVE_VFP -mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU"
PREFIX=./android/${CPU}_vfp 
ADDITIONAL_CONFIGURE_FLAG=
build_one_r6


#arm v7vfp
#CPU=armv7-a
#OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "
#PREFIX=./android/$CPU-vfp
#ADDITIONAL_CONFIGURE_FLAG=
#build_one
#arm v7n
#CPU=armv7-a
#OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon -marm -march=$CPU -mtune=cortex-a8"
#PREFIX=./android/$CPU 
#ADDITIONAL_CONFIGURE_FLAG=--enable-neon
#build_one
#arm v6+vfp
#CPU=armv6
#OPTIMIZE_CFLAGS="-DCMP_HAVE_VFP -mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU"
#PREFIX=./android/${CPU}_vfp 
#ADDITIONAL_CONFIGURE_FLAG=
#build_one

  将 build_andriod_rockplayer_right.sh 放入 /home/test/rockplayer 目录下.

  将 build_andriod_ffmpeg_right.sh 放入 /home/test/ffmpeg-2.6 目录下.

  

  //给执行的权限

[root@localhost ffmpeg-2.6]# chmod 777 build_andriod_ffmpeg_right.sh

//执行

[root@localhost ffmpeg-2.6]# ./build_andriod_ffmpeg_right.sh 

 

经过等待就可以见结果了.

INSTALL libavutil/libavutil.a
INSTALL doc/ffprobe.1
INSTALL doc/ffprobe-all.1
INSTALL doc/ffmpeg-utils.1
INSTALL doc/ffmpeg-scaler.1
INSTALL doc/ffmpeg-resampler.1
INSTALL doc/ffmpeg-codecs.1
INSTALL doc/ffmpeg-bitstream-filters.1
INSTALL doc/ffmpeg-formats.1
INSTALL doc/ffmpeg-protocols.1
INSTALL doc/libavutil.3
INSTALL doc/libswscale.3
INSTALL doc/libswresample.3
INSTALL doc/libavcodec.3
INSTALL doc/libavformat.3
INSTALL doc/ffprobe.1
INSTALL doc/ffprobe-all.1
INSTALL doc/ffmpeg-utils.1
INSTALL doc/ffmpeg-scaler.1
INSTALL doc/ffmpeg-resampler.1
INSTALL doc/ffmpeg-codecs.1
INSTALL doc/ffmpeg-bitstream-filters.1
INSTALL doc/ffmpeg-formats.1
INSTALL doc/ffmpeg-protocols.1
INSTALL doc/libavutil.3
INSTALL doc/libswscale.3
INSTALL doc/libswresample.3
INSTALL doc/libavcodec.3
INSTALL doc/libavformat.3
CP      ffprobe
STRIP   ffprobe
INSTALL install-progs-yes
INSTALL ffprobe
[root@localhost ffmpeg-2.6]# 

编译结果:

  在这个目录中"PREFIX=./android/$CPU ".

  

  

rockplayer 的so文件,比ffmpeg的so文件小了一半.

  可以开始在android 中开整了.....-_-......

说明可能出现的错误:

Q1:PLATFORM=$NDK/platforms/android-18/arch-arm/

选择不同android对应的平台:


Q2:PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86

选择可执行的文件:

arm-linux-androideabi-4.8 这个版本要与

function build_one 中或 function build_one_r6 中

最后:

make clean
make -j4 install
$PREBUILT/bin/arm-linux-androideabi-ar d 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.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog --warn-common --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.8/libgcc.a
}

这个版本相对应.

不然会报

/home/android-ndk-r10b/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-ld: error: cannot open /home/android-ndk-r10b/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.1/libgcc.a: No such file or directory
/home/android-ndk-r10b/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-ld: error: cannot open /home/android-ndk-r10b/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.1/libgcc.a: No such file or directory
libavcodec/error_resilience.c:725: error: undefined reference to '__aeabi_idivmod'
libavcodec/error_resilience.c:1177: error: undefined reference to '__aeabi_idiv'
libavcodec/error_resilience.c:1178: error: undefined reference to '__aeabi_idiv'
libavcodec/error_resilience.c:1179: error: undefined reference to '__aeabi_idiv'
libavcodec/error_resilience.c:1180: error: undefined reference to '__aeabi_idiv'
libavcodec/error_resilience.c:403: error: undefined reference to '__aeabi_idivmod'
./libavutil/mem.h:95: error: undefined reference to '__aeabi_uidiv'
./libavutil/mem.h:95: error: undefined reference to '__aeabi_uidiv'
libavcodec/error_resilience.c:220: error: undefined reference to '__aeabi_uidiv'
libavcodec/error_resilience.c:224: error: undefined reference to '__aeabi_ldivmod'
libavcodec/h263dec.c:634: error: undefined reference to '__aeabi_idivmod'
libavcodec/h264.c:466: error: undefined reference to '__aeabi_idivmod'
libavcodec/h264_ps.c:495: error: undefined reference to '__aeabi_uidiv'
libavcodec/h264_slice.c:1754: error: undefined reference to '__aeabi_uidivmod'
libavcodec/mpeg4videodec.c:2320: error: undefined reference to '__aeabi_ldivmod'
libavcodec/mpeg4videodec.c:2307: error: undefined reference to '__aeabi_ldivmod'
libavcodec/mpeg4videodec.c:2308: error: undefined reference to '__aeabi_ldivmod'
libavformat/dump.c:121: error: undefined reference to '__aeabi_uldivmod'
libavformat/dump.c:123: error: undefined reference to '__aeabi_uldivmod'
libavformat/dump.c:121: error: undefined reference to '__aeabi_uldivmod'
libavformat/dump.c:123: error: undefined reference to '__aeabi_uldivmod'
libavformat/dump.c:93: error: undefined reference to '__aeabi_l2d'
libavformat/dump.c:99: error: undefined reference to '__aeabi_l2d'
libavformat/dump.c:93: error: undefined reference to '__aeabi_l2d'
libavformat/dump.c:99: error: undefined reference to '__aeabi_l2d'
libavformat/mov.c:2517: error: undefined reference to '__aeabi_uidivmod'
libavformat/mov.c:2517: error: undefined reference to '__aeabi_uidivmod'
libavformat/utils.c:2282: error: undefined reference to '__aeabi_l2f'
libavutil/camellia.c:139: error: undefined reference to '__aeabi_llsl'
libavutil/camellia.c:139: error: undefined reference to '__aeabi_llsr'
libavutil/camellia.c:140: error: undefined reference to '__aeabi_llsl'
libavutil/camellia.c:140: error: undefined reference to '__aeabi_llsr'
libavutil/eval.c:211: error: undefined reference to '__aeabi_d2ulz'
libavutil/eval.c:211: error: undefined reference to '__aeabi_ul2d'
libavutil/eval.c:287: error: undefined reference to '__aeabi_d2lz'
libavutil/eval.c:287: error: undefined reference to '__aeabi_d2lz'
libavutil/eval.c:211: error: undefined reference to '__aeabi_d2ulz'
libavutil/eval.c:211: error: undefined reference to '__aeabi_ul2d'
libavutil/eval.c:287: error: undefined reference to '__aeabi_d2lz'
libavutil/eval.c:287: error: undefined reference to '__aeabi_d2lz'
libavutil/timecode.c:64: error: undefined reference to '__aeabi_uidivmod'
libswscale/utils.c:299: error: undefined reference to '__aeabi_llsl'

Q3:gcc is unable to create an executable file.
If gcc is a cross-compiler, use the --enable-cross-compile option.
Only do this if you know what cross compiling means.
C compiler test failed.

sh 中 gcc的路径配置出错.

"--cc=$PREBUILT/bin/arm-linux-androideabi-gcc " 

arm-linux-androideabi-gcc 是 gcc for android apk 里的一个linux可执行文件

winhex  arm-linux-androideabi-gcc 这个文件可见:

可参考: hhhbbb 的文章<elf格式分析> :http://blog.csdn.net/hhhbbb/article/details/6855004

Q4:错误error: undefined reference to 'atexit'    ,noexecstack: unknown -z option,

  unknown  --warn-once  

$PREBUILT/bin/arm-eabi-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.a libavformat/libavformat.a libavutil/libavutil.a -lc -lm -lz -ldl -llog --warn-once --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-eabi/4.4.0/libgcc.a

"-z,noexecstack" 语法错误

通过 arm-eabi-ld  --help可知(可能不同的版本,命令参数不同.)

应是  -z noexecstack

--warn-once  改为 --warn-common 

有问题的sh文件:

http://roman10.net/src/build_android_r6.txt

Q5:其它错误信息,怎么查看:

  详细的错误信息: ffmpeg/config.log 可以查看

原文地址:https://www.cnblogs.com/bleachli/p/4330398.html