Libav libavformat HOWTO: Difference between revisions

From MultimediaWiki
Jump to navigation Jump to search
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
: ''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''
: ''please make this page more complete if you can, thanks''


== Introducing a new demuxer ==
Libavformat provides means to retrieve codec data and stream metadata from container formats and network streams.


In order to make available the new demuxer you have to edit libavformat/allformats.c and libavformat/Makefile.
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
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.
variables for it, the latter contains the actual build directives.


=== libavformat/Makefile ===
=== libavformat/Makefile ===
==== Demuxer specific ====


The convention regarding the file structure is to use, for a format named '''name''', '''name'''enc.c for muxer code and '''name'''dec.c for demuxer code, common code should go in '''name'''.c
The convention regarding the file structure is to use, for a format named '''name''', '''name'''enc.c for muxer code and '''name'''dec.c for demuxer code, common code should go in '''name'''.c
Line 15: Line 36:
  OBJS-$(CONFIG_NAME_DEMUXER)    += namedec.o name.o
  OBJS-$(CONFIG_NAME_DEMUXER)    += namedec.o name.o


to the Makefile in order to build the additional code.
to the Makefile in order to build.


=== libavformat/allformats.c ===
==== Protocol specific ====


In order to add a demuxer:
The convention regarding the file structure is to use use directly the protocol name, so for a protocol named '''name''', '''name'''.c.
REGISTER_DEMUXER(NAME, '''name''')
If the protocol is tightly bound to a specific demuxer or could be mismatched is advised to use '''name'''proto.c (e.g. rtmpproto.c)


In order to add a muxer:
Add
  REGISTER_MUXER(NAME, '''name''')
  OBJS-$(CONFIG_NAME_PROTOCOL)       += nameproto.o


In order to add muxer and demuxer in a single line:
to the Makefile in order to build.
REGISTER_MUXDEMU(NAME, '''name''')


The macro will register ff_'''name'''_demuxer or/and ff_'''name'''_muxer to the available formats.
=== libavformat/allformats.c ===


Modifying allformats.c will trigger a build system warning:
Modifying allformats.c will trigger a build system warning:
Line 41: Line 61:


In order to build the new code. Make sure you properly edited Makefile and allformats.c .
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 ==
== Example code ==
Line 52: Line 92:
[[Category:Libav Tutorials]]
[[Category:Libav Tutorials]]
[[Category:Tutorials]]
[[Category:Tutorials]]
[[Category:Work In Progress]]

Latest revision as of 19:43, 15 November 2011

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