zoukankan      html  css  js  c++  java
  • FFmpeg在Android上的移植优化步骤

    http://blog.csdn.net/feixiang_john/article/details/7894188

    从事多媒体软件开发的人几乎没有不知道FFmpeg的,很多视频播放器都是基于FFmpeg开发的。如今最火的智能手机操作系统Android上的很多第三方视频播放器也是基于FFmpeg实现全格式支持。由于Android通常跑在ARM处理器上,而且Android使用了自己的libc库(即bionic),因此要在Android上编译和使用FFmpeg需要做一些移植工作,好在FFmpeg本身用C写成,很好地支持跨平台移植,实现这个目的并不难,事实上已经有很多前辈做过这方面的工作并公开了他们的成果。

    1.     Rockplayer:

    http://rockplayer.freecoder.org/index_cn.html

    http://blog.csdn.net/harry_helei/article/details/6322767

    2.     havlenapetr:

    http://github.com/havlenapetr/FFMpeg

    http://blog.csdn.net/scut1135/article/details/6536157

    http://hi.baidu.com/eefolks/blog/item/e0329e4682859129cefca351.html

    http://ajavn.com/anzhuotuandui/4351.html

    3.     halfninja:

    https://github.com/halfninja/android-ffmpeg-x264

    4.     olvaffe's:

    http://gitorious.org/~olvaffe/ffmpeg/ffmpeg-android

    http://www.nujk.com/ffmpeg-on-android

    5.     流媒体开发论坛 - 罗索工作室:

    http://www.rosoo.net/a/201108/14834.html

    http://bbs.rosoo.net/thread-6252-1-1.html

    当下本人也做这方面的事情,主要是优化ffmpeg编解码的性能,当然首先就是要搭建环境,编译代码,测试代码性能,然后优化模块,编译测试和调试,最终再测试性能:看了很多文章,对于一些新手是有点帮助,但是都不是很全面,下面简单记录下我如何搭建环境,如何编译,测试: 

    可以使用Rockplayer的方案进行实践。Rockplayer是Android上最有名的第三方视频播放器之一,其开发者根据LGPL协议公开了所使用的FFmpeg源码,该方案用Android NDK将FFmpeg源码编译生成一个单独的共享库libffmpeg.so,其中静态链接了libavformat、libavcodec、libavutil等模块,要使用FFmpeg只需要调用这一个.so即可。当然有了这个库还只是第一步,要利用FFmpeg开发一个自己的播放器或者把FFmpeg集成到Android本身的播放引擎stagefright中还需要很多其他工作,包括针对硬件平台进行优化。目前我做的只是编译出libffmpeg.so以及将FFmpeg自带的工具ffmpeg在adb shell中跑起来。我是在Android 3.2(Honeycomb)上编译FFmpeg,所用NDK版本为r7,在Android的其他版本上编译也大同小异。

    题外话:Rockplayer之前也和他们谈过合作的事情,一家几个人搞得小型公司(其实也谈不上公司了),office在上海张江一个不起眼的小区里,也不能说他们没有技术含量,只能说他们找到一个突破口,能挣点小钱,他们的android手机播放器设计原则是支持要全,画质要清晰,性能不是主要,面向中高档手机,配置相对来说就高些。

    下面把具体编译步骤描述如下,假定NDK安装在~/android-ndk-r7:

    1.   首先从FFmpeg官网下载最新的release版本源码ffmpeg-0.11.tar.gz解压缩到Android源码树的ffmpeg/下。

    2   准备一个编译脚本build_android.sh并放在ffmpeg/下面,这个脚本也是Rockplayer提供的,需做一些修改,其内容附在后面。我目前用的也会附在后面。

    3   在ffmpeg目录下运行./build_android.sh开始编译FFmpeg,编译好的libffmpeg.so会放在文件夹android里面,一共有3个版本分别对应3种ARM体系结构,包括armv7-a、armv7-a-vfp、armv6_vfp,根据所运行的硬件平台选取其中一个版本。为了编译使用FFmpeg的程序时可以方便地找到libffmpeg.so,可将它复制到$OUT/system/lib/和$OUT/obj/lib/,当然这一步也可以加在build_android.sh中做。

    4.   接下来就是编译可执行文件ffmpeg了,这个工具可以在命令行下完成FFmpeg提供的几乎所有功能包括编码、解码、转码等,也是用来调试和验证很有用的工具。其实上述编译完后在$ANDROID_BUILD_TOP/external/ffmpeg/下也会生成ffmpeg,但是在设备上无法运行。为了编出能在设备上运行的ffmpeg,可以写一个简单的Android.mk,其内容如下:

    1. LOCAL_PATH:= $(call my-dir)  
    2.   
    3. include $(CLEAR_VARS)  
    4.   
    5.    
    6.   
    7. LOCAL_SRC_FILES:=   
    8.   
    9.        cmdutils.c   
    10.   
    11.        ffmpeg.c  
    12.   
    13.    
    14.   
    15. LOCAL_C_INCLUDES :=  
    16.   
    17.    
    18.   
    19. LOCAL_SHARED_LIBRARIES :=   
    20.   
    21.        libffmpeg  
    22.   
    23.    
    24.   
    25. LOCAL_PRELINK_MODULE := false  
    26.   
    27.    
    28.   
    29. LOCAL_MODULE := ffmpeg  
    30.   
    31.    
    32.   
    33. include $(BUILD_EXECUTABLE)  

    也可以在E:android-ndk-r7-windowsandroid-ndk-r7samples est-libstdc++jni这个目录修改下Android.mk, 修改为:

    1. LOCAL_PATH:= $(call my-dir)  
    2. include $(CLEAR_VARS)  
    3.   
    4. LOCAL_SRC_FILES := ffmpeg.c cmdutils.c  
    5.    
    6. #LOCAL_PREBUILT_LIBS := libffmpeg  
    7. LOCAL_ARM_MODE := arm  
    8. LOCAL_C_INCLUDES +=   
    9.     $(LOCAL_PATH)/include    
    10.     $(LOCAL_PATH)/include/libavcodec   
    11.     $(LOCAL_PATH)/   
    12.     $(LOCAL_PATH)/include/libavfilter   
    13.     $(LOCAL_PATH)/include/libavdevice   
    14.     $(LOCAL_PATH)/include/libavutil  
    15. #LOCAL_LDLIBS := -L$(LOCAL_PATH) -lffmpeg  
    16. LOCAL_LDLIBS := libffmpeg.so  
    17. LOCAL_MODULE := ffmpeg  
    18.   
    19. include $(BUILD_EXECUTABLE)  


    当然要把ffmpeg.c cmdutils.c和libffmpeg.so拷贝到当前目录。

    5.   将上面编好的libffmpeg.so和ffmpeg分别用adb push复制到设备的/system/lib/和/system/bin/,push之前可先对libffmpeg.so做一下strip否则太大。现在就可以在adb shell中运行ffmpeg了,使用方法与在PC上相同。当然如果要用到其他开源库例如x264那么还需要把它们也移植到Android。

    以上是基本的步骤,仅供参考,可以根据具体情况修改build_android.sh里面的配置选项。如前所述,编译FFmpeg只是第一步,后续还有很多工作需要做,今后如果有进展再贴上来。

    最后附上build_android.sh供参考,在此也感谢Rockplayer的开发者:

    1. #!/bin/bash  
    2.   
    3.    
    4.   
    5. ######################################################  
    6.   
    7. # FFmpeg builds script for Android+ARM platform  
    8.   
    9. #  
    10.   
    11. # This script is released under term of  
    12.   
    13. #   CDDL (http://www.opensource.org/licenses/cddl1)  
    14.   
    15. # Wrote by pinxue (~@gmail.com) from RockPlayer.com  
    16.   
    17. #                                   2010-8 ~ 2011-4  
    18.   
    19. ######################################################  
    20.   
    21.    
    22.   
    23. ######################################################  
    24.   
    25. # Usage:  
    26.   
    27. #   put this script in top of FFmpeg source tree  
    28.   
    29. #   ./build_android  
    30.   
    31. #  
    32.   
    33. # It generates binary for following architectures:  
    34.   
    35. #     ARMv6  
    36.   
    37. #     ARMv6+VFP  
    38.   
    39. #     ARMv7+VFPv3-d16 (Tegra2)  
    40.   
    41. #     ARMv7+Neon (Cortex-A8)  
    42.   
    43. #  
    44.   
    45. # Customizing:  
    46.   
    47. # 1. Feel free to change ./configure parameters for more features  
    48.   
    49. # 2. To adapt other ARM variants  
    50.   
    51. #       set $CPU and $OPTIMIZE_CFLAGS  
    52.   
    53. #       call build_one  
    54.   
    55. ######################################################  
    56.   
    57.    
    58.   
    59. NDK=~/android-ndk-r7  
    60.   
    61. PLATFORM=$NDK/platforms/android-8/arch-arm/  
    62.   
    63. PREBUILT=../../prebuilt/linux-x86/toolchain/arm-eabi-4.4.3  
    64.   
    65.    
    66.   
    67. function build_one  
    68.   
    69. {  
    70.   
    71.    
    72.   
    73. # -fasm : required. Android header file uses asm keyword instead of __asm__ , but most of c dialect (like ansi,c99,gnu99) implies -fno-asm.  
    74.   
    75. #   ~/android/android-ndk-r4/build/platforms/android-5/arch-arm//usr/include/asm/byteorder.h: In function '___arch__swab32':  
    76.   
    77. #   ~/android/android-ndk-r4/build/platforms/android-5/arch-arm//usr/include/asm/byteorder.h:25: error: expected ')' before ':' token  
    78.   
    79.    
    80.   
    81. # -fno-short-enums : optimized.  Else FFmpeg obj will generate a huge number of warning for variable-size enums,  
    82.   
    83. #   though we may suppress them by --no-enum-size-warning, it would be better to avoid it.  
    84.   
    85. #   .../ld: warning: cmdutils.o uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail  
    86.   
    87.    
    88.   
    89. # --extra-libs="-lgcc" : required. Else cannot solve some runtime function symbols  
    90.   
    91. #   ... undefined reference to `__aeabi_f2uiz'  
    92.   
    93.    
    94.   
    95. # --enable-protocols : required. Without this option, the file open always fails mysteriously.  
    96.   
    97. #   FFmpeg's av_open_input_file will invoke file format probing functions, but because most of useful demuxers has flag of zero  
    98.   
    99. #   which cause them are ignored during file format probling and fall to url stream parsing,  
    100.   
    101. #   if protocols are disabled, the file:// url cannot be opened as well.  
    102.   
    103.    
    104.   
    105. # $PREBUILT/bin/arm-eabi-ar d libavcodec/libavcodec.a inverse.o : required.  
    106.   
    107. #   FFmpeg includes two copies of inverse.c both in libavutil and libavcodec for performance consideration (not sure the benifit yet)  
    108.   
    109. #   Without this step, final ld of generating libffmpeg.so will fail silently, if invoke ld through gcc, gcc will collect more reasonable error message.  
    110.   
    111.    
    112.   
    113. # -llog: debug only, FFmpeg itself doesn't require it at all.  
    114.   
    115. #   With this option, we may simply includes "utils/Log.h" and use LOGx() to observe FFmpeg's behavior  
    116.   
    117. #   PS, it seems the toolchain implies -DNDEBUG somewhere, it would be safer to use following syntax  
    118.   
    119. #    #ifdef NDEBUG  
    120.   
    121. #        #undef NDEBUG  
    122.   
    123. #        #define HAVE_NDEBUG  
    124.   
    125. #    #endif  
    126.   
    127. #    #include "utils/Log.h"  
    128.   
    129. #    #ifdef HAVE_NDEBUG  
    130.   
    131. #        #define NDEBUG  
    132.   
    133. #        #undef HAVE_NDEBUG  
    134.   
    135. #    #endif  
    136.   
    137.    
    138.   
    139. # --whole-archive : required. Else ld generate a small .so file (about 15k)  
    140.   
    141.    
    142.   
    143. # --no-stdlib : required. Android doesn't use standard c runtime but invited its own wheal (bionic libc) because of license consideration.  
    144.   
    145.    
    146.   
    147. # space before  of configure lines: required for some options. Else next line will be merged into previous lines's content and cause problem.  
    148.   
    149. #   Especially the --extra-cflags, the next line will pass to gcc in this case and configure will say gcc cannot create executable.  
    150.   
    151.    
    152.   
    153. # many options mentioned by articles over internet are implied by -O2 or -O3 already, need not repeat at all.  
    154.   
    155.    
    156.   
    157. # two or three common optimization cflags are omitted because not sure about the trade off yet. invoke NDK build system with V=1 to find them.  
    158.   
    159.    
    160.   
    161. # -Wl,-T,$PREBUILT/arm-eabi/lib/ldscripts/armelf.x mentioned by almost every articles over internet, but it is not required to specify at all.  
    162.   
    163.    
    164.   
    165. # -Dipv6mr_interface=ipv6mr_ifindex : required. Android inet header doesn't use ipv6mr_interface which is required by rfc, seems it generate this user space header file directly from kernel header file, but Linux kernel has decided to keep its own name for ever and ask user space header to use rfc name.  
    166.   
    167.    
    168.   
    169. # HAVE_SYS_UIO_H : required. Else:  
    170.   
    171. # In file included from ~/android/android-ndk-r4/build/platforms/android-5/arch-arm//usr/include/linux/socket.h:29,  
    172.   
    173. #                 from ~/android/android-ndk-r4/build/platforms/android-5/arch-arm//usr/include/sys/socket.h:33,  
    174.   
    175. #                 from libavformat/network.h:35,  
    176.   
    177. #                 from libavformat/utils.c:46:  
    178.   
    179. #~/android/android-ndk-r4/build/platforms/android-5/arch-arm//usr/include/linux/uio.h:19: error: redefinition of 'struct iovec'  
    180.   
    181. #  
    182.   
    183.    
    184.   
    185. # --disable-doc : required because of strange bug of toolchain.  
    186.   
    187.    
    188.   
    189. ./configure --target-os=linux   
    190.   
    191.     --prefix=$PREFIX   
    192.   
    193.     --enable-cross-compile   
    194.   
    195.     --extra-libs="-lgcc"   
    196.   
    197.     --arch=arm   
    198.   
    199.     --cc=$PREBUILT/bin/arm-eabi-gcc   
    200.   
    201.     --cross-prefix=$PREBUILT/bin/arm-eabi-   
    202.   
    203.     --nm=$PREBUILT/bin/arm-eabi-nm   
    204.   
    205.     --sysroot=$PLATFORM   
    206.   
    207.     --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 "   
    208.   
    209.     --disable-shared   
    210.   
    211.     --enable-static   
    212.   
    213.     --extra-ldflags="-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib  -nostdlib -lc -lm -ldl -llog"   
    214.   
    215.     --enable-parsers   
    216.   
    217.     --enable-encoders    
    218.   
    219.     --enable-decoders   
    220.   
    221.     --enable-muxers   
    222.   
    223.     --enable-demuxers   
    224.   
    225.     --enable-swscale    
    226.   
    227.     --enable-swscale-alpha   
    228.   
    229.     --disable-ffplay   
    230.   
    231.     --disable-ffprobe   
    232.   
    233.     --disable-ffserver   
    234.   
    235.     --enable-network   
    236.   
    237.     --enable-indevs   
    238.   
    239.     --disable-bsfs   
    240.   
    241.     --enable-filters   
    242.   
    243.     --enable-avfilter   
    244.   
    245.     --enable-protocols    
    246.   
    247.     --enable-asm   
    248.   
    249.     $ADDITIONAL_CONFIGURE_FLAG  
    250.   
    251.    
    252.   
    253.    
    254.   
    255. #make clean  
    256.   
    257. make  -j4 install  
    258.   
    259.    
    260.   
    261. $PREBUILT/bin/arm-eabi-ar d libavcodec/libavcodec.a inverse.o  
    262.   
    263.    
    264.   
    265. $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 libavfilter/libavfilter.a libswscale/libswscale.a libavdevice/libavdevice.a libswresample/libswresample.a -lc -lm -lz -ldl -llog  --warn-once  --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-eabi/4.4.3/libgcc.a  
    266.   
    267.    
    268.   
    269. }  
    270.   
    271.    
    272.   
    273. #arm v6  
    274.   
    275. CPU=armv6  
    276.   
    277. OPTIMIZE_CFLAGS="-marm -march=$CPU"  
    278.   
    279. PREFIX=./android/$CPU  
    280.   
    281. ADDITIONAL_CONFIGURE_FLAG=  
    282.   
    283. #build_one  
    284.   
    285.    
    286.   
    287. #arm v7vfpv3  
    288.   
    289. CPU=armv7-a  
    290.   
    291. OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU "  
    292.   
    293. PREFIX=./android/$CPU  
    294.   
    295. ADDITIONAL_CONFIGURE_FLAG=  
    296.   
    297. build_one  
    298.   
    299.    
    300.   
    301. #arm v7vfp  
    302.   
    303. CPU=armv7-a  
    304.   
    305. OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "  
    306.   
    307. PREFIX=./android/$CPU-vfp  
    308.   
    309. ADDITIONAL_CONFIGURE_FLAG=  
    310.   
    311. build_one  
    312.   
    313.    
    314.   
    315. #arm v7n  
    316.   
    317. CPU=armv7-a  
    318.   
    319. OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon -marm -march=$CPU -mtune=cortex-a8"  
    320.   
    321. PREFIX=./android/$CPU  
    322.   
    323. ADDITIONAL_CONFIGURE_FLAG=--enable-neon  
    324.   
    325. build_one  
    326.   
    327.    
    328.   
    329. #arm v6+vfp  
    330.   
    331. CPU=armv6  
    332.   
    333. OPTIMIZE_CFLAGS="-DCMP_HAVE_VFP -mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU"  
    334.   
    335. PREFIX=./android/${CPU}_vfp  
    336.   
    337. ADDITIONAL_CONFIGURE_FLAG=  
    338.   
    339. build_one  


    下面是我使用的 build_android.sh文件:

    1. #!/bin/bash  
    2.   
    3. ######################################################  
    4. # FFmpeg builds script for Android+ARM platform  
    5. #  
    6. # This script is released under term of   
    7. #   CDDL (http://www.opensource.org/licenses/cddl1)   
    8. ######################################################  
    9. # Usage:  
    10. #   put this script in top of FFmpeg source tree  
    11. #   ./build_android  
    12. #  
    13. # It generates binary for following architectures:  
    14. #     ARMv6   
    15. #     ARMv6+VFP   
    16. #     ARMv7+VFPv3-d16 (Tegra2)   
    17. #     ARMv7+Neon (Cortex-A8)  
    18. #  
    19. # Customizing:  
    20. # 1. Feel free to change ./configure parameters for more features  
    21. # 2. To adapt other ARM variants  
    22. #       set $CPU and $OPTIMIZE_CFLAGS   
    23. #       call build_one  
    24. ######################################################  
    25.   
    26. NDK=E:/android-ndk-r7-windows/android-ndk-r7  
    27. PLATFORM=$NDK/platforms/android-8/arch-arm/  
    28. PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows  
    29.   
    30.   
    31. function build_one  
    32. {  
    33.   
    34. # -fasm : required. Android header file uses asm keyword instead of __asm__ , but most of c dialect (like ansi,c99,gnu99) implies -fno-asm.  
    35. #   ~/android/android-ndk-r4/build/platforms/android-5/arch-arm//usr/include/asm/byteorder.h: In function '___arch__swab32':  
    36. #   ~/android/android-ndk-r4/build/platforms/android-5/arch-arm//usr/include/asm/byteorder.h:25: error: expected ')' before ':' token  
    37.   
    38. # -fno-short-enums : optimized.  Else FFmpeg obj will generate a huge number of warning for variable-size enums,   
    39. #   though we may suppress them by --no-enum-size-warning, it would be better to avoid it.  
    40. #   .../ld: warning: cmdutils.o uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail  
    41.   
    42. # --extra-libs="-lgcc" : required. Else cannot solve some runtime function symbols  
    43. #   ... undefined reference to `__aeabi_f2uiz'  
    44.   
    45. # --enable-protocols : required. Without this option, the file open always fails mysteriously.  
    46. #   FFmpeg's av_open_input_file will invoke file format probing functions, but because most of useful demuxers has flag of zero   
    47. #   which cause them are ignored during file format probling and fall to url stream parsing,  
    48. #   if protocols are disabled, the file:// url cannot be opened as well.  
    49.   
    50. # $PREBUILT/bin/arm-linux-androideabi-ar d libavcodec/libavcodec.a inverse.o : required.  
    51. #   FFmpeg includes two copies of inverse.c both in libavutil and libavcodec for performance consideration (not sure the benifit yet)  
    52. #   Without this step, final ld of generating libffmpeg.so will fail silently, if invoke ld through gcc, gcc will collect more reasonable error message.  
    53.   
    54. # -llog: debug only, FFmpeg itself doesn't require it at all.  
    55. #   With this option, we may simply includes "utils/Log.h" and use LOGx() to observe FFmpeg's behavior  
    56. #   PS, it seems the toolchain implies -DNDEBUG somewhere, it would be safer to use following syntax  
    57. #    #ifdef NDEBUG  
    58. #        #undef NDEBUG  
    59. #        #define HAVE_NDEBUG  
    60. #    #endif  
    61. #    #include "utils/Log.h"  
    62. #    #ifdef HAVE_NDEBUG  
    63. #        #define NDEBUG  
    64. #        #undef HAVE_NDEBUG  
    65. #    #endif  
    66.   
    67. # --whole-archive : required. Else ld generate a small .so file (about 15k)  
    68.   
    69. # --no-stdlib : required. Android doesn't use standard c runtime but invited its own wheal (bionic libc) because of license consideration.  
    70.   
    71. # space before  of configure lines: required for some options. Else next line will be merged into previous lines's content and cause problem.  
    72. #   Especially the --extra-cflags, the next line will pass to gcc in this case and configure will say gcc cannot create executable.  
    73.   
    74. # many options mentioned by articles over internet are implied by -O2 or -O3 already, need not repeat at all.  
    75.   
    76. # two or three common optimization cflags are omitted because not sure about the trade off yet. invoke NDK build system with V=1 to find them.  
    77.   
    78. # -Wl,-T,$PREBUILT/arm-eabi/lib/ldscripts/armelf.x mentioned by almost every articles over internet, but it is not required to specify at all.  
    79.   
    80. # -Dipv6mr_interface=ipv6mr_ifindex : required. Android inet header doesn't use ipv6mr_interface which is required by rfc, seems it generate this user space header file directly from kernel header file, but Linux kernel has decided to keep its own name for ever and ask user space header to use rfc name.  
    81.   
    82. # HAVE_SYS_UIO_H : required. Else:  
    83. # In file included from ~/android/android-ndk-r4/build/platforms/android-5/arch-arm//usr/include/linux/socket.h:29,  
    84. #                 from ~/android/android-ndk-r4/build/platforms/android-5/arch-arm//usr/include/sys/socket.h:33,  
    85. #                 from libavformat/network.h:35,  
    86. #                 from libavformat/utils.c:46:  
    87. #~/android/android-ndk-r4/build/platforms/android-5/arch-arm//usr/include/linux/uio.h:19: error: redefinition of 'struct iovec'  
    88. #  
    89.   
    90. # --disable-doc : required because of strange bug of toolchain.  
    91.   
    92. ./configure --target-os=linux   
    93.     --prefix=$PREFIX   
    94.     --enable-cross-compile   
    95.     --extra-libs="-lgcc"   
    96.     --arch=arm   
    97.     --enable-memalign-hack   
    98.     --enable-gpl   
    99.     --cc=$PREBUILT/bin/arm-linux-androideabi-gcc   
    100.     --cross-prefix=$PREBUILT/bin/arm-linux-androideabi-   
    101.     --nm=$PREBUILT/bin/arm-linux-androideabi-nm   
    102.     --sysroot=$PLATFORM   
    103.     --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 "   
    104.     --disable-shared   
    105.     --enable-static   
    106.     --extra-ldflags="-Wl,-T,$PREBUILT/arm-linux-androideabi/lib/ldscripts/armelf_linux_eabi.x -Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/crtbegin.o $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/crtend.o -L$PLATFORM/usr/lib -lc -lm -ldl -llog"   
    107.     --enable-parsers   
    108.     --enable-decoders   
    109.     --enable-swscale    
    110.     --disable-ffplay   
    111.     --disable-ffprobe   
    112.     --disable-ffserver   
    113.     --enable-network   
    114.     --enable-indevs   
    115.     --enable-optimizations   
    116.     --enable-asm   
    117.     --enable-swresample   
    118.     --disable-debug  
    119.     $ADDITIONAL_CONFIGURE_FLAG  
    120.   
    121. #make clean  
    122. make -j4 install   
    123.   
    124. $PREBUILT/bin/arm-linux-androideabi-ar d libavcodec/libavcodec.a inverse.o  
    125.   
    126. $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 libavfilter/libavfilter.a libswscale/libswscale.a libswresample/libswresample.a libavresample/libavresample.a libpostproc/libpostproc.a -lc -lm -lz -ldl -llog  --warn-once  --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a  
    127.   
    128. }  
    129.   
    130. ##arm v6  
    131. #CPU=armv6  
    132. #OPTIMIZE_CFLAGS="-marm -march=$CPU"  
    133. #PREFIX=./android/$CPU   
    134. #ADDITIONAL_CONFIGURE_FLAG=  
    135. ##build_one  
    136. #  
    137. ##arm v7vfpv3  
    138. #CPU=armv7-a  
    139. #OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=$CPU "  
    140. #PREFIX=./android/$CPU   
    141. #ADDITIONAL_CONFIGURE_FLAG=  
    142. #build_one  
    143. #  
    144. ##arm v7vfp  
    145. #CPU=armv7-a  
    146. #OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "  
    147. #PREFIX=./android/$CPU-vfp  
    148. #ADDITIONAL_CONFIGURE_FLAG=  
    149. #build_one  
    150.   
    151. #arm v7n  
    152. CPU=armv7-a  
    153. OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=neon -marm -march=$CPU -mtune=cortex-a8"  
    154. PREFIX=./android/$CPU   
    155. ADDITIONAL_CONFIGURE_FLAG=--enable-neon  
    156. build_one  
    157.   
    158. ##arm v6+vfp  
    159. #CPU=armv6  
    160. #OPTIMIZE_CFLAGS="-DCMP_HAVE_VFP -mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU"  
    161. #PREFIX=./android/${CPU}_vfp   
    162. #ADDITIONAL_CONFIGURE_FLAG=  
    163. #build_one  


    6. 把编译好的libffmpeg.so 和 可执行文件 ffmpeg 文件push到 手机里面运行测试! 下面是操作步骤:

    a: 拷贝文件到手机sdcard

    E:android-ndk-r7-windowsandroid-ndk-r7samples est-libstdc++libsarmeabi>

    拷贝可执行文件
    adb push ffmpeg /sdcard/ttt
    4507 KB/s (144248 bytes in 0.031s)

    拷贝库

    adb push liffmpeg.so /sdcard/ttt
    3756 KB/s (8233079 bytes in 2.140s)

    b: 从手机sdcard 拷贝到系统bin目录和系统lib目录

    E:android-ndk-r7-windowsandroid-ndk-r7samples est-libstdc++libsarmeabi>adb
     shell
    $ su
    su
    # cd /system/bin
    cd /system/bin

    # rm ffmpeg
    rm ffmpeg
    # cat /sdcard/ttt/ffmpeg > ffmpeg
    cat /sdcard/ttt/ffmpeg > ffmpeg

    # chmod 777 ffmpeg
    chmod 777 ffmpeg

    # cd ../lib
    cd /system/lib

    # rm libffmpeg.so
    rm libffmpeg.so
    # cat /sdcard/ttt/libffmpeg.so >libffmpeg.so
    cat /sdcard/ttt/libffmpeg.so >libffmpeg.so

    # chmod 777 libffmpeg.so
    chmod 777 libffmpeg.so

    # cd ../bin
    cd /system/bin


    运行可执行文件:
    ./ffmpeg -i /sdcard/ttt/test.264  /sdcard/ttt/output.yuv

  • 相关阅读:
    POJ 1330 Nearest Common Ancestors (LCA)
    POJ 3264 Balanced Lineup (RMQ | 线段树 | ST )
    .Net开发笔记(七)使用组件编程
    .Net开发笔记(六)关于事件(续)
    .Net开发笔记(十一) 设计时(DesignTime)和运行时(RunTime)的区别
    .Net开发笔记(十) “容器组件服务”模型
    .Net开发笔记(九)自定义窗体设计器
    .Net开发笔记(五) 关于事件
    .Net开发笔记(八) 动态编译
    10 款最新的 jQuery 内容滑块插件
  • 原文地址:https://www.cnblogs.com/pengkunfan/p/3515523.html
Copyright © 2011-2022 走看看