AVFormatContext Struct Reference

Format I/O context. More...

#include <avformat.h>

Data Fields

const AVClassav_class
 A class for logging and AVOptions. More...
 
struct AVInputFormatiformat
 The input container format. More...
 
struct AVOutputFormatoformat
 The output container format. More...
 
void * priv_data
 Format private data. More...
 
AVIOContextpb
 I/O context. More...
 
int ctx_flags
 Flags signalling stream properties. More...
 
unsigned int nb_streams
 Number of elements in AVFormatContext.streams. More...
 
AVStream ** streams
 A list of all streams in the file. More...
 
char filename [1024]
 input or output filename More...
 
int64_t start_time
 Position of the first frame of the component, in AV_TIME_BASE fractional seconds. More...
 
int64_t duration
 Duration of the stream, in AV_TIME_BASE fractional seconds. More...
 
int bit_rate
 Total stream bitrate in bit/s, 0 if not available. More...
 
unsigned int packet_size
 
int max_delay
 
int flags
 Flags modifying the (de)muxer behaviour. More...
 
unsigned int probesize
 Maximum size of the data read from input for determining the input container format. More...
 
int max_analyze_duration
 Maximum duration (in AV_TIME_BASE units) of the data read from input in avformat_find_stream_info(). More...
 
const uint8_t * key
 
int keylen
 
unsigned int nb_programs
 
AVProgram ** programs
 
enum AVCodecID video_codec_id
 Forced video codec_id. More...
 
enum AVCodecID audio_codec_id
 Forced audio codec_id. More...
 
enum AVCodecID subtitle_codec_id
 Forced subtitle codec_id. More...
 
unsigned int max_index_size
 Maximum amount of memory in bytes to use for the index of each stream. More...
 
unsigned int max_picture_buffer
 Maximum amount of memory in bytes to use for buffering frames obtained from realtime capture devices. More...
 
unsigned int nb_chapters
 Number of chapters in AVChapter array. More...
 
AVChapter ** chapters
 
AVDictionarymetadata
 Metadata that applies to the whole file. More...
 
int64_t start_time_realtime
 Start time of the stream in real world time, in microseconds since the Unix epoch (00:00 1st January 1970). More...
 
int fps_probe_size
 The number of frames used for determining the framerate in avformat_find_stream_info(). More...
 
int error_recognition
 Error recognition; higher values will detect more errors but may misdetect some more or less valid parts as errors. More...
 
AVIOInterruptCB interrupt_callback
 Custom interrupt callbacks for the I/O layer. More...
 
int debug
 Flags to enable debugging. More...
 
int64_t max_interleave_delta
 Maximum buffering duration for interleaving. More...
 
int strict_std_compliance
 Allow non-standard and experimental extension. More...
 
int event_flags
 Flags for the user to detect events happening on the file. More...
 
int max_ts_probe
 Maximum number of packets to read while waiting for the first timestamp. More...
 
int avoid_negative_ts
 Avoid negative timestamps during muxing. More...
 
AVFormatInternalinternal
 An opaque field for libavformat internal usage. More...
 
void * opaque
 Arbitrary user data set by the caller. More...
 
int(* io_open )(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
 A callback for opening new IO streams. More...
 
void(* io_close )(struct AVFormatContext *s, AVIOContext *pb)
 A callback for closing the streams opened with AVFormatContext.io_open(). More...
 
char * protocol_blacklist
 A comma-separated list of protocol names that will not be used internally by libavformat. More...
 
char * protocol_whitelist
 A comma-separated list of protocol names that can be used internally by libavformat. More...
 

Detailed Description

Format I/O context.

New fields can be added to the end with minor version bumps. Removal, reordering and changes to existing fields require a major version bump. sizeof(AVFormatContext) must not be used outside libav*, use avformat_alloc_context() to create an AVFormatContext.

Examples:
metadata.c, output.c, and transcode_aac.c.

Definition at line 920 of file avformat.h.

Field Documentation

◆ av_class

const AVClass* AVFormatContext::av_class

A class for logging and AVOptions.

Set by avformat_alloc_context(). Exports (de)muxer private options if they exist.

Definition at line 925 of file avformat.h.

◆ iformat

struct AVInputFormat* AVFormatContext::iformat

The input container format.

Demuxing only, set by avformat_open_input().

Definition at line 932 of file avformat.h.

◆ oformat

struct AVOutputFormat* AVFormatContext::oformat

The output container format.

Muxing only, must be set by the caller before avformat_write_header().

Examples:
output.c.

Definition at line 939 of file avformat.h.

Referenced by add_audio_stream(), add_video_stream(), and main().

◆ priv_data

void* AVFormatContext::priv_data

Format private data.

This is an AVOptions-enabled struct if and only if iformat/oformat.priv_class is not NULL.

Definition at line 948 of file avformat.h.

◆ pb

AVIOContext* AVFormatContext::pb

I/O context.

Do NOT set this field if AVFMT_NOFILE flag is set in iformat/oformat.flags. In such a case, the (de)muxer will handle I/O in some other way and this field will be NULL.

Examples:
output.c.

Definition at line 962 of file avformat.h.

Referenced by main().

◆ ctx_flags

int AVFormatContext::ctx_flags

Flags signalling stream properties.

A combination of AVFMTCTX_*. Set by libavformat.

Definition at line 969 of file avformat.h.

◆ nb_streams

unsigned int AVFormatContext::nb_streams

Number of elements in AVFormatContext.streams.

Set by avformat_new_stream(), must not be modified by any other code.

Definition at line 976 of file avformat.h.

◆ streams

AVStream** AVFormatContext::streams

A list of all streams in the file.

New streams are created with avformat_new_stream().

Freed by libavformat in avformat_free_context().

Definition at line 988 of file avformat.h.

◆ filename

char AVFormatContext::filename[1024]

input or output filename

Examples:
output.c.

Definition at line 996 of file avformat.h.

Referenced by main().

◆ start_time

int64_t AVFormatContext::start_time

Position of the first frame of the component, in AV_TIME_BASE fractional seconds.

NEVER set this value directly: It is deduced from the AVStream values.

Demuxing only, set by libavformat.

Definition at line 1005 of file avformat.h.

◆ duration

int64_t AVFormatContext::duration

Duration of the stream, in AV_TIME_BASE fractional seconds.

Only set this value if you know none of the individual stream durations and also do not set any of them. This is deduced from the AVStream values if not set.

Demuxing only, set by libavformat.

Definition at line 1015 of file avformat.h.

◆ bit_rate

int AVFormatContext::bit_rate

Total stream bitrate in bit/s, 0 if not available.

Never set it directly if the file_size and the duration are known as Libav can compute it automatically.

Definition at line 1022 of file avformat.h.

◆ packet_size

unsigned int AVFormatContext::packet_size

Definition at line 1024 of file avformat.h.

◆ max_delay

int AVFormatContext::max_delay

Definition at line 1025 of file avformat.h.

◆ flags

int AVFormatContext::flags

Flags modifying the (de)muxer behaviour.

A combination of AVFMT_FLAG_*. Set by the user before avformat_open_input() / avformat_write_header().

Definition at line 1031 of file avformat.h.

◆ probesize

unsigned int AVFormatContext::probesize

Maximum size of the data read from input for determining the input container format.

Demuxing only, set by the caller before avformat_open_input().

Definition at line 1055 of file avformat.h.

◆ max_analyze_duration

int AVFormatContext::max_analyze_duration

Maximum duration (in AV_TIME_BASE units) of the data read from input in avformat_find_stream_info().

Demuxing only, set by the caller before avformat_find_stream_info().

Definition at line 1062 of file avformat.h.

◆ key

const uint8_t* AVFormatContext::key

Definition at line 1064 of file avformat.h.

◆ keylen

int AVFormatContext::keylen

Definition at line 1065 of file avformat.h.

◆ nb_programs

unsigned int AVFormatContext::nb_programs

Definition at line 1067 of file avformat.h.

◆ programs

AVProgram** AVFormatContext::programs

Definition at line 1068 of file avformat.h.

◆ video_codec_id

enum AVCodecID AVFormatContext::video_codec_id

Forced video codec_id.

Demuxing: Set by user.

Definition at line 1074 of file avformat.h.

◆ audio_codec_id

enum AVCodecID AVFormatContext::audio_codec_id

Forced audio codec_id.

Demuxing: Set by user.

Definition at line 1080 of file avformat.h.

◆ subtitle_codec_id

enum AVCodecID AVFormatContext::subtitle_codec_id

Forced subtitle codec_id.

Demuxing: Set by user.

Definition at line 1086 of file avformat.h.

◆ max_index_size

unsigned int AVFormatContext::max_index_size

Maximum amount of memory in bytes to use for the index of each stream.

If the index exceeds this size, entries will be discarded as needed to maintain a smaller size. This can lead to slower or less accurate seeking (depends on demuxer). Demuxers for which a full in-memory index is mandatory will ignore this.

  • muxing: unused
  • demuxing: set by user

Definition at line 1098 of file avformat.h.

◆ max_picture_buffer

unsigned int AVFormatContext::max_picture_buffer

Maximum amount of memory in bytes to use for buffering frames obtained from realtime capture devices.

Definition at line 1104 of file avformat.h.

◆ nb_chapters

unsigned int AVFormatContext::nb_chapters

Number of chapters in AVChapter array.

When muxing, chapters are normally written in the file header, so nb_chapters should normally be initialized before write_header is called. Some muxers (e.g. mov and mkv) can also write chapters in the trailer. To write chapters in the trailer, nb_chapters must be zero when write_header is called and non-zero when write_trailer is called.

  • muxing: set by user
  • demuxing: set by libavformat

Definition at line 1117 of file avformat.h.

◆ chapters

AVChapter** AVFormatContext::chapters

Definition at line 1118 of file avformat.h.

◆ metadata

AVDictionary* AVFormatContext::metadata

Metadata that applies to the whole file.

Freed by libavformat in avformat_free_context().

Examples:
metadata.c.

Definition at line 1128 of file avformat.h.

Referenced by main().

◆ start_time_realtime

int64_t AVFormatContext::start_time_realtime

Start time of the stream in real world time, in microseconds since the Unix epoch (00:00 1st January 1970).

That is, pts=0 in the stream was captured at this real world time. Muxing only, set by the caller before avformat_write_header().

Definition at line 1136 of file avformat.h.

◆ fps_probe_size

int AVFormatContext::fps_probe_size

The number of frames used for determining the framerate in avformat_find_stream_info().

Demuxing only, set by the caller before avformat_find_stream_info().

Definition at line 1143 of file avformat.h.

◆ error_recognition

int AVFormatContext::error_recognition

Error recognition; higher values will detect more errors but may misdetect some more or less valid parts as errors.

Demuxing only, set by the caller before avformat_open_input().

Definition at line 1150 of file avformat.h.

◆ interrupt_callback

AVIOInterruptCB AVFormatContext::interrupt_callback

Custom interrupt callbacks for the I/O layer.

demuxing: set by the user before avformat_open_input(). muxing: set by the user before avformat_write_header() (mainly useful for AVFMT_NOFILE formats). The callback should also be passed to avio_open2() if it's used to open the file.

Definition at line 1161 of file avformat.h.

◆ debug

int AVFormatContext::debug

Flags to enable debugging.

Definition at line 1166 of file avformat.h.

◆ max_interleave_delta

int64_t AVFormatContext::max_interleave_delta

Maximum buffering duration for interleaving.

To ensure all the streams are interleaved correctly, av_interleaved_write_frame() will wait until it has at least one packet for each stream before actually writing any packets to the output file. When some streams are "sparse" (i.e. there are large gaps between successive packets), this can result in excessive buffering.

This field specifies the maximum difference between the timestamps of the first and the last packet in the muxing queue, above which libavformat will output a packet regardless of whether it has queued a packet for all the streams.

Muxing only, set by the caller before avformat_write_header().

Definition at line 1185 of file avformat.h.

◆ strict_std_compliance

int AVFormatContext::strict_std_compliance

Allow non-standard and experimental extension.

See also
AVCodecContext.strict_std_compliance

Definition at line 1191 of file avformat.h.

◆ event_flags

int AVFormatContext::event_flags

Flags for the user to detect events happening on the file.

Flags must be cleared by the user once the event has been handled. A combination of AVFMT_EVENT_FLAG_*.

Definition at line 1198 of file avformat.h.

◆ max_ts_probe

int AVFormatContext::max_ts_probe

Maximum number of packets to read while waiting for the first timestamp.

Decoding only.

Definition at line 1205 of file avformat.h.

◆ avoid_negative_ts

int AVFormatContext::avoid_negative_ts

Avoid negative timestamps during muxing.

Any value of the AVFMT_AVOID_NEG_TS_* constants. Note, this only works when using av_interleaved_write_frame.

  • muxing: Set by user
  • demuxing: unused

Definition at line 1214 of file avformat.h.

◆ internal

AVFormatInternal* AVFormatContext::internal

An opaque field for libavformat internal usage.

Must not be accessed in any way by callers.

Definition at line 1223 of file avformat.h.

◆ opaque

void* AVFormatContext::opaque

Arbitrary user data set by the caller.

Definition at line 1228 of file avformat.h.

◆ io_open

int(* AVFormatContext::io_open) (struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)

A callback for opening new IO streams.

Whenever a muxer or a demuxer needs to open an IO stream (typically from avformat_open_input() for demuxers, but for certain formats can happen at other times as well), it will call this callback to obtain an IO context.

Parameters
sthe format context
pbon success, the newly opened IO context should be returned here
urlthe url to open
flagsa combination of AVIO_FLAG_*
optionsa dictionary of additional options, with the same semantics as in avio_open2()
Returns
0 on success, a negative AVERROR code on failure
Note
Certain muxers and demuxers do nesting, i.e. they open one or more additional internal format contexts. Thus the AVFormatContext pointer passed to this callback may be different from the one facing the caller. It will, however, have the same 'opaque' field.

Definition at line 1250 of file avformat.h.

◆ io_close

void(* AVFormatContext::io_close) (struct AVFormatContext *s, AVIOContext *pb)

A callback for closing the streams opened with AVFormatContext.io_open().

Definition at line 1256 of file avformat.h.

◆ protocol_blacklist

char* AVFormatContext::protocol_blacklist

A comma-separated list of protocol names that will not be used internally by libavformat.

If this field is a non-empty string, then protocols listed here will be forbidden.

This field should be set using AVOptions.

Definition at line 1265 of file avformat.h.

◆ protocol_whitelist

char* AVFormatContext::protocol_whitelist

A comma-separated list of protocol names that can be used internally by libavformat.

If this field is a non-empty string, all protocols not listed here will be forbidden.

This field should be set using AVOptions.

Definition at line 1274 of file avformat.h.


The documentation for this struct was generated from the following file: