Libav libavformat HOWTO

From MultimediaWiki
Revision as of 19:43, 15 November 2011 by Lu zero (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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

Libavformat provides means to retrieve codec data and stream metadata from container formats and network streams.

Demuxers let the application access or store the codec data and metadata within a container format providing at least timing information.

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)

In general (TODO: make a diagram out of it)

Protocol -> Demuxer -> Encoded data with timing information (video frames, audio samples, timed metadata) -> Decoders -> Raw data with timing information -> Output

Input -> Raw data with timing information -> Encoders -> Coded data with timing information -> Muxer -> Protocol

Demuxer structure

Protocol structure

Introducing a new demuxer or a new protocol

In order to make available the new demuxer or the new protocol 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 contains the actual build directives.

libavformat/Makefile

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

Add

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)

Add

OBJS-$(CONFIG_NAME_PROTOCOL)        += nameproto.o

to the Makefile in order to build.

libavformat/allformats.c

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
make

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

Demuxer specific

In order to add a demuxer:

REGISTER_DEMUXER(NAME, name)

In order to add a muxer:

REGISTER_MUXER(NAME, name)

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

REGISTER_MUXDEMU(NAME, name)

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

Protocol specific

In order to add a protoco:

REGISTER_PROTOCOL(NAME, name)

The macro will add ff_name_protocol to the available protocols.

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)

WIP