ffmpeg常用数据结构3

AVFormatContext

这个结构体描述了一个媒体文件或媒体流的构成和基本信息,定义如下:

typedefstructAVFormatContext {

constAVClass *av_class; /**< Set by avformat_alloc_context. */

    /* Can only be iformat or oformat, not both at the same time. */

structAVInputFormat *iformat;

structAVOutputFormat *oformat;

    void *priv_data;

ByteIOContext *pb;

    unsigned intnb_streams;

AVStream *streams[MAX_STREAMS];

    char filename[1024]; /**< input or output filename */

    /* stream info */

    int64_t timestamp;

#if LIBAVFORMAT_VERSION_INT < (53<<16)

    char title[512];

    char author[512];

    char copyright[512];

    char comment[512];

    char album[512];

int year;  /**< ID3 year, 0 if none */

int track; /**< track number, 0 if none */

    char genre[32]; /**< ID3 genre */

#endif

intctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */

    /* private data for pts handling (do not modify directly). */

    /** This buffer is only needed when packets were already buffered but

       not decoded, for example to get the codec parameters in MPEG

       streams. */

structAVPacketList *packet_buffer;

    /** Decoding: 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.  */

    int64_t start_time;

    /** Decoding: 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 dont set any of them. This is deduced from the

AVStream values if not set.  */

    int64_t duration;

    /** decoding: total file size, 0 if unknown */

    int64_t file_size;

    /** Decoding: total stream bitrate in bit/s, 0 if not

       available. Never set it directly if the file_size and the

       duration are known as FFmpeg can compute it automatically. */

intbit_rate;

    /* av_read_frame() support */

AVStream *cur_st;

#if LIBAVFORMAT_VERSION_INT < (53<<16)

const uint8_t *cur_ptr_deprecated;

intcur_len_deprecated;

AVPacketcur_pkt_deprecated;

#endif

    /* av_seek_frame() support */

    int64_t data_offset; /** offset of the first packet */

intindex_built;

intmux_rate;

    unsigned intpacket_size;

int preload;

intmax_delay;

#define AVFMT_NOOUTPUTLOOP -1

#define AVFMT_INFINITEOUTPUTLOOP 0

    /** number of times to loop output in formats that support it */

intloop_output;

int flags;

#define AVFMT_FLAG_GENPTS       0x0001 ///< Generate missing pts even if it requires parsing future frames.

#define AVFMT_FLAG_IGNIDX       0x0002 ///< Ignore index.

#define AVFMT_FLAG_NONBLOCK     0x0004 ///< Do not block when reading packets from input.

#define AVFMT_FLAG_IGNDTS       0x0008 ///< Ignore DTS on frames that contain both DTS & PTS

#define AVFMT_FLAG_NOFILLIN     0x0010 ///< Do not infer any values from other values, just return what is stored in the container

#define AVFMT_FLAG_NOPARSE      0x0020 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled

#define AVFMT_FLAG_RTP_HINT     0x0040 ///< Add RTP hinting to the output file

intloop_input;

    /** decoding: size of data to probe; encoding: unused. */

    unsigned intprobesize;

    /**

     * Maximum time (in AV_TIME_BASE units) during which the input should

     * be analyzed in avformat_find_stream_info().

     */

intmax_analyze_duration;

const uint8_t *key;

intkeylen;

    unsigned intnb_programs;

AVProgram **programs;

    /**

     * Forced video codec_id.

     * Demuxing: Set by user.

     */

enumCodecIDvideo_codec_id;

    /**

     * Forced audio codec_id.

     * Demuxing: Set by user.

     */

enumCodecIDaudio_codec_id;

    /**

     * Forced subtitle codec_id.

     * Demuxing: Set by user.

     */

enumCodecIDsubtitle_codec_id;

    /**

     * 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

     */

    unsigned intmax_index_size;

    /**

     * Maximum amount of memory in bytes to use for buffering frames

     * obtained from realtime capture devices.

     */

    unsigned intmax_picture_buffer;

    unsigned intnb_chapters;

AVChapter **chapters;

    /**

     * Flags to enable debugging.

     */

int debug;

#define FF_FDEBUG_TS        0x0001

    /**

     * Raw packets from the demuxer, prior to parsing and decoding.

     * This buffer is used for buffering packets until the codec can

     * be identified, as parsing cannot be done without knowing the

     * codec.

     */

structAVPacketList *raw_packet_buffer;

structAVPacketList *raw_packet_buffer_end;

structAVPacketList *packet_buffer_end;

AVMetadata *metadata;

    /**

     * Remaining size available for raw_packet_buffer, in bytes.

     * NOT PART OF PUBLIC API

     */

#define RAW_PACKET_BUFFER_SIZE 2500000

intraw_packet_buffer_remaining_size;

    /**

     * 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.

     * - encoding: Set by user.

     * - decoding: Unused.

     */

    int64_t start_time_realtime;

} AVFormatContext;

这是FFMpeg中为基本的一个结构,是其他所有结构的根,是一个多媒体文件或流的根本抽象。其中:

·         nb_streamsstreams所表示的AVStream结构指针数组包含了所有内嵌媒体流的描述;

·         iformat和oformat指向对应的demuxer和muxer指针;

·         pb则指向一个控制底层数据读写的ByteIOContext结构。

·         start_time和duration是从streams数组的各个AVStream中推断出的多媒体文件的起始时间和长度,以微妙为单位。

通常,这个结构由avformat_open_input在内部创建并以缺省值初始化部分成员。但是,如果调用者希望自己创建该结构,则需要显式为该结构的一些成员置缺省值——如果没有缺省值的话,会导致之后的动作产生异常。以下成员需要被关注:

·         probesize

·         mux_rate

·         packet_size

·         flags

·         max_analyze_duration

·         key

·         max_index_size

·         max_picture_buffer

·         max_delay

原文地址:https://www.cnblogs.com/elesos/p/2990585.html