[Ffmpeg-devel] How to incorporate a subset of FFMPEG source in other projects?

Colin Ward lists
Fri Dec 2 04:48:06 CET 2005

Sven Over wrote:


> My question is, how to achieve this technically. I only need a small subset of 
> libavcodec/libavformat, namely the mpeg2video decoder and encoder, the mp2 
> audio decoder (maybe AC3 in the future), and the mpeg2 and mpeg2ts muxers. Is 
> there a good starting point to find out, what files I need include and to 
> modify? Maybe someone even has written some shell scripts to do the job.
> If not, that's no problem, I will find out myself. But maybe someone has 
> already put some effort into this and has some good tips (or even scripts) 
> for me. (Or you can just point me to posts to this list in the mailing list 
> archive which covers this issue... like "RTFM" -> read the fine 
> mailinglist ;)

   I have put some effort into this.  I ported libav* to the PPC Amiga 
and it was *huge* - like about 7 or 8 MB!  So I cut it down to only 
support a few really popular formats such as MPEG, AVI, MOV and OGG and 
it was only 1.5 MB, which is much more acceptable.

   I did it the tedious way - I wrote a makefile that contained just the 
decoders that I needed for these formats and then tried to link my 
program.  When I got undefined symbols I added the extra .c files that 
were required and tried again.  I repeated this process for what seemed 
like hours until I got an executable.  It was tedious but it was better 
than linking in files that weren't needed - I am not sure of the 
granularity of the GNU linker but from some of the bloated files that it 
is generating on the Amiga I am fairly certain that if you link with a 
library then it will pull in the entire library rather than just the 
object files that it requires that are in the library.

   Anyway, two problems problem that I encountered that I would like to 
address and send in patches for are as follows:

   1) It is actually difficult to include a subset of containers and 
codecs because some functions are placed in incorrect files.  For 
example, let us say that codec "a" and codec "b" use a certain IDCT 
function and that you want to only include codec "a" in your project. 
You compile and link a.c but get an undefined reference to _idct.  So 
you have to include b.c as well, even though you are not using codec "b" 
because that is where the _idct function is defined.  So all of the 
functions in b.c get included in your executable because GNU ld doesn't 
do function level linking, and not only that, but one of the functions 
in b.c (that you are not even calling) now calls some file in codec "c" 
so you have to include c.c as well!  Then c.c wants d.c and so on!  Now 
if this hypothetical _idct funciton were moved into idct.c instead of 
being in b.c then the problem would be avoided.  A good example of this 
is an IDCT function that is in h264.c which I have to include even 
though I am not including h.264 support in my project.

   IIRC I have to include at least a dozen files in my project that 
shouldn't be included, just to access functions that should be elsewhere.

   2) You can't compile without USE_ENCODERS without having to hack 
certain files because certain encode() functions do not have #ifdef 
USE_ENCODERS around them.

   I have been meaning to look into these problems and submit some 
patches but have been too busy.  The FFMPEG maintainers can also be 
scary in their treatment of patches too.  ;-)  I should try to look into 
it soon.

[Hitman/Code HQ - 6502/z80/68000/604e/80x86/ARM coder - Amiga rulez!]
[VZ-200/VIC-20/MZ-700/c16/c64*10/c128*8/Plus-4/CPC464/CD32/500*2    ]
[600/1000/1200*2/A4000/SNES/N64/Dreamcast/Athlon 1100/AmigaOne      ]
[Assembly Language: The most fun you can have with your clothes on! ]

More information about the ffmpeg-devel mailing list