Libav libavformat HOWTO

From MultimediaWiki
Revision as of 19:34, 15 November 2011 by Lu zero (talk | contribs)
Jump to navigation Jump to search
This page will hold information on how libavformat is structured an how to add demuxer and protocols to it
please make this page more complete if you can, thanks

Demuxer structure

Protocol structure

Introducing a new demuxer or a new protocol

A demuxer let the application access the codec data and metadata stored within a container, a muxer let you store codec data and metadata using the container format chosen, a protocol provides an I/O abstraction to network or system storage.

In order to make available the new demuxer you have to edit libavformat/allformats.c and libavformat/Makefile. The former holds a list of available demuxers and protocol and is parsed by configure to generate build system variables for it, the latter keeps the actual build directives.


Demuxer specific

The convention regarding the file structure is to use, for a format named name, nameenc.c for muxer code and namedec.c for demuxer code, common code should go in name.c


OBJS-$(CONFIG_NAME_MUXER)      += nameenc.o name.o
OBJS-$(CONFIG_NAME_DEMUXER)    += namedec.o name.o

to the Makefile in order to build.

Protocol specific

The convention regarding the file structure is to use use directly the protocol name, so for a protocol named name, name.c. If the protocol is tightly bound to a specific demuxer or could be mismatched is advised to use nameproto.c (e.g. rtmpproto.c)


OBJS-$(CONFIG_NAME_PROTOCOL)        += nameproto.o

to the Makefile in order to build.


Modifying allformats.c will trigger a build system warning:

Run configure in the top level directory and make clean, as config.h will be automatically modified.

It is advised to run:

make clean
make configure

In order to build the new code. Make sure you properly edited Makefile and allformats.c .

Demuxer specific

In order to add a demuxer:


In order to add a muxer:


In order to add muxer and demuxer in a single line:


The macro will add ff_name_demuxer or/and ff_name_muxer to the available formats.

Protocol specific

In order to add a protoco:


The macro will add ff_name_protocol to the available protocols.

Introducing a new protocol

Protocols let you access container formats through any kind of storage or delivery system, being that a filesystem access (e.g. pipe, file), a low level network protocol (tcp, udp) or a application level protocol (rtmp, http, tls)



Example code

This section is merely an overview; please look at an actual demuxer for a more in depth and up to date example. libavformat/avformat.h shows the different structure of a muxer (AVOutputFormat) and a demuxer (AVInputFormat)