Why my ffmpeg libs are so large? [closed]
Asked Answered
C

1

14

I compiled ffmpeg libs on my Ubuntu 64-bits using the following script:

   mkdir ~/ffmpeg_sources

#x264

cd ~/ffmpeg_sources
   wget http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
   tar xjvf last_x264.tar.bz2
   cd x264-snapshot*
   ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static --disable-asm
   make
   make install
   make distclean

#FFmpeg

cd ~/ffmpeg_sources
   wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
   tar xjvf ffmpeg-snapshot.tar.bz2
   cd ffmpeg
   PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig"
   export PKG_CONFIG_PATH
   ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" \
   --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --extra-libs="-ldl" --   enable-gpl \
  --enable-libx264 --enable-x11grab --disable-yasm                                                                                                                               
   make
   make install
   make distclean
   hash -r

But the final libs are really large (For example, libavcodec.a > 140 Mb). Anybody know why my libs are so large ?

EDIT

My Solutions:

  • add the option "--disable-debug" to the ./configure. The size of my libavcodec fell from 150Mb to 12Mb!
  • Remove all unnecessary codecs: Add the options -disable-encoders, --disable-decoders and then add only codecs you want with --enable-encoder=NAME and --enable-decoder=NAME. Print the list using ./configure --list-encoders --list-decoders. see ./configure --help for more information. (My final libavcodec has a size of 4Mo)
Cambodia answered 6/4, 2014 at 18:28 Comment(4)
ffmpeg is a very large library with a lot of functionality (many different codecs, etc) so it's not surprising for the output files to be large. Do you think this size is incorrect or ...?Byyourleave
I think because I read so many threads where people has libavcodec with a size < 15 Mo. (e.g. ffmpeg-users.933282.n4.nabble.com/… ). I understand that it contains many codecs... but in fact, I just need one: H.264 (x264). So I'm currently searching for removing other codecs using compilation flags.Cambodia
It also helps to add -s to the linker flags.Burlingame
Hi. Did you resolved your issue? Did you reduced the file size? Please let me how to reduce the file size. I need ti reduce my apk size. Thanks in advance.Riella
A
3

Note that the static libs (such as libavcodec.a) contain all kinds of extra data that will be stripped off by linker.

But even after that you can add --enable-small to ./configure parameters. About a year ago this parameter reduced the size of libavcodec.so from 14 to ~3 MByte.

Apiculture answered 6/4, 2014 at 21:5 Comment(4)
be careful, --enable-small optimizes for size instead of speed, or so the docs say :)Lissalissak
@Lissalissak note that in many real-life cases, smaller binary is paged less, or improves cache hits. Therefore often, optimizing for size pays out better than "speed". But your remark is correct, we must be carefult with such assumptions.Apiculture
I use ffmpeg-5.1 and android-ndk-r21e in ubuntu 20.04.4 LTS system. By using --enable-small and adding -s, the compiled dynamic library libavcodec.so is 7.5M which is still big. Can you give some other advises to reduce the size?Brita
@Brita the size of libavcodec.so depends on the codecs you enable. Also, make sure you have the so file stripped.Apiculture

© 2022 - 2024 — McMap. All rights reserved.