Difference between revisions of "Libav libavformat HOWTO"

From MultimediaWiki
Jump to navigation Jump to search
Line 1: Line 1:
 
: ''please make this page more complete if you can, thanks''
 
: ''please make this page more complete if you can, thanks''
  
== Introducing a new demuxer ==
+
== Demuxer structure ==
  
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.
+
== 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'''.
 
In order to make available the new demuxer you have to edit '''libavformat/allformats.c''' and '''libavformat/Makefile'''.
Line 10: Line 14:
  
 
=== 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 17: Line 23:
 
  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 43: Line 48:
  
 
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.
  
 
== Introducing a new protocol ==
 
== Introducing a new protocol ==

Revision as of 19:33, 15 November 2011

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.

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.

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)

libavformat/Makefile

libavformat/allformats.c

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