13

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)
user3504221
  • 131
  • 1
  • 5
  • 1
    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 ...? – nobody Apr 06 '14 at 19:20
  • 1
    I think because I read so many threads where people has libavcodec with a size < 15 Mo. (e.g. http://ffmpeg-users.933282.n4.nabble.com/libavcodec-size-too-large-td4657129.html ). 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. – user3504221 Apr 07 '14 at 10:17
  • It also helps to add `-s` to the linker flags. – Antonio Oct 27 '15 at 16:12
  • 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. – Vijay Jan 29 '16 at 12:59

1 Answers1

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.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • be careful, --enable-small optimizes for size instead of speed, or so the docs say :) – rogerdpack Nov 29 '18 at 07:01
  • 1
    @rogerdpack 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. – Alex Cohn Nov 29 '18 at 09:01
  • 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? – JustinGong Oct 20 '22 at 08:24
  • @JustinGong the size of `libavcodec.so` depends on the codecs you enable. Also, make sure you have the **so** file stripped. – Alex Cohn Oct 20 '22 at 09:23