Home

AVFormatContext

AVFormatContext is a central structure in FFmpeg's libavformat that represents a media container context. It is used for both demuxing (reading) and muxing (writing) operations and encapsulates information about the container format, the I/O layer, and the streams it contains.

The context references the format in use (input or output), the I/O context (AVIOContext*) used for data

Typical lifecycle and usage: allocate a context with avformat_alloc_context. For input, call avformat_open_input to open the

Associated utilities include av_dump_format to print a summary of the container, which is helpful for debugging,

Common fields conceptually include the number of streams (nb_streams), the streams[] array, the URL, duration, and

input/output,
the
target
URL
or
file
path,
and
an
array
of
AVStream
pointers
describing
each
stream
inside
the
container
(such
as
video,
audio,
and
subtitles).
It
also
stores
metadata,
duration,
bit
rate,
and
various
format-specific
flags.
Additional
fields
cover
stream
mappings,
disposition,
and
format-specific
data.
file
or
stream,
optionally
supply
a
guessed
format,
then
avformat_find_stream_info
to
read
headers
and
populate
the
streams
array.
For
output,
allocate
the
context
and
use
avformat_alloc_output_context2
to
create
a
context
for
a
given
format
and
URL,
add
streams
with
avformat_new_stream,
then
write
headers
with
avformat_write_header,
write
packets
with
av_write_frame,
and
finally
write
trailer
with
avformat_write_trailer.
and
avformat_seek_file
to
seek
within
the
stream.
metadata.
Cleanup
involves
avformat_close_input
for
inputs
or
avformat_free_context
for
freeing
the
context
when
done.