很困惑,为什么我的构建libffmpeg.so制造> 17M? [英] so Confused, why my build of libffmpeg.so > 17M?

查看:882
本文介绍了很困惑,为什么我的构建libffmpeg.so制造> 17M?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了WINXP和科学Linux构建的ffmpeg为Android,ffmpeg的是海豚的球员 - 一个开源视频播放器上(http://$c$c.google.com/p/dolphin-player/),和我只是建立FFmpeg的,它看起来与在RockPlayer的1.7.0,它们下面的所有使用build_andriod.sh,它的工作在这两个WINXP和linux, 和所有成功拿到斌/ ffmpeg的(小于5MB),但libffmpeg.so(> 17MB),当海豚球员库放libffmpeg.so,播放器不能正常工作,大小17MB太大,原来的libffmpeg。所以在olphin玩家库小于5MB,请给些建议。

 #!/斌/庆典

################################################## ####
#FFmpeg的构建脚本为Android + ARM平台
#
#这个脚本是根据长期发布
#CDDL(http://www.opensource.org/licenses/cddl1)
#从RockPlayer.com写由pinxue(~@gmail.com)
#2010-8〜2011-4
################################################## ####

################################################## ####
# 用法:
#投放的FFmpeg源码树的顶部这个脚本
#./build_android
#
#它生成二进制以下结构:
#的ARMv6
#的ARMv6 + VFP
#的ARMv7 +的VFPv3-D16(Tegra2的)
#的ARMv7 +霓虹灯(的Cortex-A8)
#
#定制:
#1,可以随意更改的./configure参数的更多功能
#2,要适应其他ARM变种
#$集CPU和$ OPTIMIZE_CFLAGS
#调用build_one
################################################## ####

出口TMPDIR = D:/ tmp目录/机器人
出口NDK = D:/ Android的NDK-R4

#平台= $ NDK /编译/平台/ Android为8 /弓臂/
平台= $ NDK /编译/平台/ Android为8 /弓臂
#preBUILT = $ NDK /编译/ prebuilt /达尔文-86 / ARM-EABI-4.4.0
preBUILT = $ NDK /编译/ prebuilt /窗/ ARM-EABI-4.4.0

功能build_one
{

#-fasm:必需的。 Android的头文件使用asm关键字,而不是__asm​​__,但大多数C方言(如ANSI,C99,gnu99)意味着-fno-ASM。
#〜/安卓/ Android的NDK-R4 /编译/平台/ Android的-5 /弓臂// usr / include目录/ ASM / byteorder.h:在函数'___arch__swab32:
#〜/安卓/ Android的NDK-R4 /编译/平台/ Android的-5 /弓臂// usr / include目录/ ASM / byteorder.h:25:错误:预期')'前':'令牌

#使用-fno-short-枚举:优化。否则FFmpeg的OBJ将产生一个巨大的警示可变大小的枚举数,
#虽然我们晚饭preSS他们通过--no-枚举的大小警告,这将是更好地避免它。
#... / LD:警告:cmdutils.o使用可变大小枚举但输出是用32位的枚举;跨对象使用枚举值可能会失败

#--extra  - 库= -  lgcc:必须的。否则无法解决的一些运行时函数符号
#...未定义的参考`__aeabi_f2uiz

#--enable-协议:要求。如果没有这个选项,打开该文件总是神秘地失败。
#FFmpeg的av_open_input_file将调用文件格式探测功能,但由于大多数有用的分流器具有零标志
#这导致他们在过程中文件格式probling忽略掉url可流解析,
#如果协议被禁用,该文件:// URL不能打开为好。

#$preBUILT /箱/ ARM-EABI-ARðlibav codeC / libav codec.a inverse.o:必需的。
#FFmpeg的包括inverse.c无论在libavutil和libav codeC的性能考虑两个副本(不知道benifit尚)
#如果没有这一步,产生libffmpeg.so最终劳工处会默默地消失,如果通过调用gcc的LD,海湾合作委员会将收集更多的合理的错误信息。

#-llog:调试只,FFmpeg的本身并不需要它。
#使用这个选项,我们可以简单地包括utils的/ Log.h,并​​使用LOGX()来观察FFmpeg的行为
#PS,看起来工具链意味着-DNDEBUG的地方,这将是更安全的使用下面的语法
#的#ifdef NDEBUG
#NDEBUG #UNDEF
##定义HAVE_NDEBUG
#    #万一
##包括utils的/ Log.h
#的#ifdef HAVE_NDEBUG
##定义NDEBUG
##UNDEF HAVE_NDEBUG
#    #万一

#--whole归档:必需的。否则LD产生一个小的.so文件(约15K)

#--no-STDLIB:必需的。 Android不使用标准的C运行时,但由于邀请的许可考虑自身的风团(仿生libc中)。

前\的配置行#空间:需要的一些选项。否则下一行,将合并为previous线的内容而引起的问题。
#特别是--extra-CFLAGS,下一行会传递给GCC在这种情况下,配置会说GCC不能创建可执行文件。

由文章在网上提到#许多选项由-O2或-O3已经暗示,无须重复的。

#两个或三个常见的优化CFLAGS被忽略,因为不知道权衡呢。调用NDK编译系统,V = 1来找到它们。

#-Wl,-T,$preBUILT /臂EABI / lib中/由几乎每一个物品通过互联网所提到的,但它不是必需的,以指定在所有ldscripts / armelf.x。

#-Dipv6mr_interface = ipv6mr_ifindex:必需的。 Android的INET头不使用这是需要由RFC ipv6mr_interface,似乎它生成此用户空间的头从内核头文件直接文件,但是Linux内核已经决定将自己的名字永远和询问用户空间的头使用RFC名称。

#HAVE_SYS_UIO_H:必需的。其他:
#在文件中包括来自〜/安卓/ Android的NDK-R4 /编译/平台/ Android的-5 /弓臂// usr / include目录/ Linux的/ socket.h中:29,
#在〜/安卓/ Android的NDK-R4 /编译/平台/ Android的-5 /弓臂// usr / include目录/ SYS / socket.h中:33,
#从了libavformat / network.h:35,
#从了libavformat / utils.c:46:
#〜/安卓/ Android的NDK-R4 /编译/平台/ Android的-5 /弓臂// usr / include目录/ Linux的/ uio.h:19:错误:重新定义结构iovec的
#

# - 禁用DOC:由于工具链奇怪的错误要求。
#

#
# - 超LDFLAGS =轮候册,-T,$preBUILT / ARM-EABI / lib中/ ldscripts / armelf.x -Wl,-rpath链接= $平台/ usr / lib目录-L $平台的/ usr / lib目录-nostdlib $preBUILT / lib中/ GCC / ARM-EABI / 4.4.0 / crtbegin.o $preBUILT / lib中/ GCC / ARM-EABI / 4.4.0 /但crtend.o -lc -lm -ldl
#

的./configure --target-OS = Linux的\
     -  preFIX = $preFIX \
    --enable-交叉编译\
    --extra  - 库= -  lgcc\
    --arch =手臂\
    --cc = $preBUILT /箱/ ARM-EABI-gcc的\
    --cross- preFIX = $preBUILT /斌/臂eabi- \
    --nm = $preBUILT /箱/ ARM-EABI纳米\
    --sysroot = $ PLATFORM \
   --extra-CFLAGS =-O3 -fpic -DANDROID -DHAVE_SYS_UIO_H = 1 -Dipv6mr_interface = ipv6mr_ifindex -fasm -Wno-psabi了-fno-short-枚举-fno严格走样-finline限= $ 300 OPTIMIZE_CFLAGS\
     - 禁用共享\
    --enable-静态\
    --extra-LDFLAGS = -  WL,-rpath链接= $平台/ usr / lib目录-L $平台/ usr / lib目录-nostdlib -lc -lm -ldl -llog\
    --enable-解析器\
    --disable-CN codeRS \
    --enable-DE codeRS \
     - 禁用muxers \
    --enable-分流器\
    --enable-swscale \
     - 禁用ffplay \
     - 禁用ffprobe \
     - 禁用ffserver的\
    --enable-网络\
    --enable-indevs \
     - 禁用BSFS \
     - 禁用滤镜\
    --enable-协议\
    --enable-ASM \
    --disable-DOC \
    $ ADDITIONAL_CONFIGURE_FLAG

##使清洁
让-j4安装


$preBUILT /箱/ ARM-EABI-ARðlibav codeC / libav codec.a inverse.o

$preBUILT /箱/ ARM-EABI-LD -rpath链接= $平台/ usr / lib目录-L $平台/ usr / lib目录-soname libffmpeg.so -shared -nostdlib -z,noexecstack -Bsymbolic --whole -archive --no-不确定-o $preFIX / libffmpeg.so libav codeC / libav codec.a了libavformat / libavformat.a libavutil / libavutil.a -lc -lm -lz -ldl  - llog --warn一次--dynamic链接器= /系统/斌/连接器$preBUILT / lib中/ GCC / ARM-EABI / 4.4.0 / libgcc.a的

}


#arm V6
CPU =的ARMv6
OPTIMIZE_CFLAGS = -  MARM -march = $ CPU
preFIX =。/安卓/ $ CPU
ADDITIONAL_CONFIGURE_FLAG =
build_one

#arm v7vfpv3
CPU =的ARMv7-A
OPTIMIZE_CFLAGS = -  mfloat-ABI = softfp -mfpu =的VFPv3-D16 -marm -march = $ CPU
preFIX =。/安卓/ $ CPU
ADDITIONAL_CONFIGURE_FLAG =
build_one

#arm v7vfp
CPU =的ARMv7-A
OPTIMIZE_CFLAGS = -  mfloat-ABI = softfp -mfpu = VFP -marm -march = $ CPU
preFIX =。/安卓/ $ CPU-VFP
ADDITIONAL_CONFIGURE_FLAG =
build_one

#arm V7N
CPU =的ARMv7-A
OPTIMIZE_CFLAGS = -  mfloat-ABI = softfp -mfpu =霓虹灯-marm -march = $ CPU -mtune = Cortex-A8的
preFIX =。/安卓/ $ CPU氖
ADDITIONAL_CONFIGURE_FLAG =  - 启用 - 氖
build_one

#arm V6 + VFP
CPU =的ARMv6
OPTIMIZE_CFLAGS = -  DCMP_HAVE_VFP -mfloat-ABI = softfp -mfpu = VFP -marm -march = $ CPU
preFIX =。/安卓/ $ {} CPU _VFP
ADDITIONAL_CONFIGURE_FLAG =
build_one
 

解决方案

您应该剥离,剥离。所以,加入这一行

$preBUILT /箱/ ARM-EABI-带-g $preFIX / libffmpeg.so

下面

$preBUILT /箱/ ARM-EABI-LD -rpath链接= $平台/ usr / lib中...

随后的.so的规模将足够小,

但玩家可能仍然无法正常工作, libswscale / libswscale.a 要补充libffmpeg.so,在这一行添加:

$preBUILT /箱/ ARM-EABI-LD -rpath链接= $平台/ usr / lib目录-L $平台/ usr / lib目录-soname libffmpeg.so -shared -nostdlib -z,noexecstack -Bsymbolic --whole归档--no-不确定-o $preFIX / libffmpeg.so libav codeC / libav codec.a了libavformat / libavformat.a libswscale / libswscale.a ...

I did build ffmpeg for Android in winxp and scientific linux , ffmpeg is in dolphin player -- an open source video player (http://code.google.com/p/dolphin-player/), and i just build the ffmpeg, its seems like the same as in rockplayer 1.7.0, they all use build_andriod.sh below, it worked in both winxp and linux, and all successfully got bin/ffmpeg (less than 5MB), but libffmpeg.so ( > 17MB), when put libffmpeg.so in dolphin-player libs , player can't work, the size 17MB is too large, the original libffmpeg.so in olphin-player libs is less than 5MB, please give some advice.

#!/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
######################################################

export TMPDIR=D:/tmp/android
export NDK=D:/android-ndk-r4

#PLATFORM=$NDK/build/platforms/android-8/arch-arm/
PLATFORM=$NDK/build/platforms/android-8/arch-arm
#PREBUILT=$NDK/build/prebuilt/darwin-x86/arm-eabi-4.4.0
PREBUILT=$NDK/build/prebuilt/windows/arm-eabi-4.4.0

function build_one
{

# -fasm : required. Android header file uses asm keyword instead of __asm__ , but most of c dialect (like ansi,c99,gnu99) implies -fno-asm.
#   ~/android/android-ndk-r4/build/platforms/android-5/arch-arm//usr/include/asm/byteorder.h: In function '___arch__swab32':
#   ~/android/android-ndk-r4/build/platforms/android-5/arch-arm//usr/include/asm/byteorder.h:25: error: expected ')' before ':' token

# -fno-short-enums : optimized.  Else FFmpeg obj will generate a huge number of warning for variable-size enums, 
#   though we may suppress them by --no-enum-size-warning, it would be better to avoid it.
#   .../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

# --extra-libs="-lgcc" : required. Else cannot solve some runtime function symbols
#   ... undefined reference to `__aeabi_f2uiz'

# --enable-protocols : required. Without this option, the file open always fails mysteriously.
#   FFmpeg's av_open_input_file will invoke file format probing functions, but because most of useful demuxers has flag of zero 
#   which cause them are ignored during file format probling and fall to url stream parsing,
#   if protocols are disabled, the file:// url cannot be opened as well.

# $PREBUILT/bin/arm-eabi-ar d libavcodec/libavcodec.a inverse.o : required.
#   FFmpeg includes two copies of inverse.c both in libavutil and libavcodec for performance consideration (not sure the benifit yet)
#   Without this step, final ld of generating libffmpeg.so will fail silently, if invoke ld through gcc, gcc will collect more reasonable error message.

# -llog: debug only, FFmpeg itself doesn't require it at all.
#   With this option, we may simply includes "utils/Log.h" and use LOGx() to observe FFmpeg's behavior
#   PS, it seems the toolchain implies -DNDEBUG somewhere, it would be safer to use following syntax
#    #ifdef NDEBUG
#        #undef NDEBUG
#        #define HAVE_NDEBUG
#    #endif
#    #include "utils/Log.h"
#    #ifdef HAVE_NDEBUG
#        #define NDEBUG
#        #undef HAVE_NDEBUG
#    #endif

# --whole-archive : required. Else ld generate a small .so file (about 15k)

# --no-stdlib : required. Android doesn't use standard c runtime but invited its own wheal (bionic libc) because of license consideration.

# space before \ of configure lines: required for some options. Else next line will be merged into previous lines's content and cause problem.
#   Especially the --extra-cflags, the next line will pass to gcc in this case and configure will say gcc cannot create executable.

# many options mentioned by articles over internet are implied by -O2 or -O3 already, need not repeat at all.

# 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.

# -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.

# -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.

# HAVE_SYS_UIO_H : required. Else:
# In file included from ~/android/android-ndk-r4/build/platforms/android-5/arch-arm//usr/include/linux/socket.h:29,
#                 from ~/android/android-ndk-r4/build/platforms/android-5/arch-arm//usr/include/sys/socket.h:33,
#                 from libavformat/network.h:35,
#                 from libavformat/utils.c:46:
#~/android/android-ndk-r4/build/platforms/android-5/arch-arm//usr/include/linux/uio.h:19: error: redefinition of 'struct iovec'
#

# --disable-doc : required because of strange bug of toolchain.
#

#
#--extra-ldflags=-Wl,-T,$PREBUILT/arm-eabi/lib/ldscripts/armelf.x -Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib $PREBUILT/lib/gcc/arm-eabi/4.4.0/crtbegin.o $PREBUILT/lib/gcc/arm-eabi/4.4.0/crtend.o -lc -lm -ldl"
#

./configure --target-os=linux \
    --prefix=$PREFIX \
    --enable-cross-compile \
    --extra-libs="-lgcc" \
    --arch=arm \
    --cc=$PREBUILT/bin/arm-eabi-gcc \
    --cross-prefix=$PREBUILT/bin/arm-eabi- \
    --nm=$PREBUILT/bin/arm-eabi-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" \
    --enable-parsers \
    --disable-encoders  \
    --enable-decoders \
    --disable-muxers \
    --enable-demuxers \
    --enable-swscale  \
    --disable-ffplay \
    --disable-ffprobe \
    --disable-ffserver \
    --enable-network \
    --enable-indevs \
    --disable-bsfs \
    --disable-filters \
    --enable-protocols  \
    --enable-asm \
    --disable-doc \
    $ADDITIONAL_CONFIGURE_FLAG

##make clean
make  -j4 install


$PREBUILT/bin/arm-eabi-ar d libavcodec/libavcodec.a inverse.o

$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

}


#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-neon 
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

解决方案

You should strip, strip the .so, add this line

$PREBUILT/bin/arm-eabi-strip -g $PREFIX/libffmpeg.so

below

$PREBUILT/bin/arm-eabi-ld -rpath-link=$PLATFORM/usr/lib ...

Then the size of .so will be small enough,

but player may still can't work, libswscale/libswscale.a should add to libffmpeg.so, add it in this line :

$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 libswscale/libswscale.a ...

这篇关于很困惑,为什么我的构建libffmpeg.so制造> 17M?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆