Home

avformatwriteheader

avformat_write_header is a function in FFmpeg’s libavformat that writes the header for an output format associated with a given AVFormatContext. It initializes the container file’s header based on the configured streams and metadata and is typically called after opening the output and configuring streams, but before writing any packet data.

Prototype and parameters:

int avformat_write_header(AVFormatContext *s, AVDictionary **options);

The first argument, s, is a pointer to an initialized AVFormatContext with an open IO context and

Return value:

0 on success, or a negative error code on failure. The error codes follow FFmpeg’s conventional negative

Usage notes:

Call avformat_write_header after setting up the output context (including avio_open) and creating or configuring streams, and

Remarks:

Some muxers may write necessary header information automatically during the first packet write, in which case

configured
streams.
The
second
argument,
options,
is
an
optional
dictionary
of
muxer-specific
options
that
may
influence
how
the
header
is
written;
pass
NULL
if
no
options
are
needed.
values
and
can
indicate
IO
errors,
unsupported
features,
or
invalid
configuration.
before
writing
packet
data
with
av_write_frame
or
av_interleaved_write_frame.
If
the
function
fails,
handle
cleanup
and
free
resources
accordingly.
The
header
may
contain
format-specific
data
such
as
file
signatures,
track
metadata,
and
codec
parameters
serialized
into
the
container’s
header.
the
function
could
be
a
no-op.
Always
check
the
return
value
and
use
an
options
dictionary
if
you
need
to
customize
muxer
behavior.
This
function
is
part
of
the
typical
FFmpeg
muxing
workflow
that
also
includes
avformat_write_trailer
for
finalization.