AVFormatContext结构体分析

typedef struct AVFormatContext {
    /**
         * A class for logging and @ref avoptions. Set by avformat_alloc_context().
    处理视频开始的类,用avformat_alloc_context()分配空间
    *Exports (de)muxer private options if they exist.
    muxer的作用式是将视频文件、音频文件和字幕文件合并为某一个视频格式
    demuxer的作用估计就是相反吧
    如果存在(de)muxer,那么他们就是这个类的私有成员
         */
        const AVClass *av_class;

        /**
         * The input container format.
         *这里说的输入容器格式应该就是我们常见的视频格式吧
         * Demuxing only, set by avformat_open_input().
         *只存在demuxer,那么就只能用avformat_open_input函数打开视频*/
        struct AVInputFormat *iformat;

        /**
         * The output container format.
         *这个和上面说的差不多,一个输入一个输出
         *Muxing only, must be set by the caller before avformat_write_header().
    要输出视频的话,肯定是要吧视频流,音频流,字幕合起来啦         
    */
        struct AVOutputFormat *oformat;

        /**
         * Format private data. This is an AVOptions-enabled struct
    格式化私有数据?不知所云         
    * if and only if iformat/oformat.priv_class is not NULL.
    当且仅当iformat/oformat.priv_class这个东西非空,这是要干嘛      
    *
         * - muxing: set by avformat_write_header()
         * - demuxing: set by avformat_open_input()
         */
        void *priv_data;//这是一个可以指向任何类型数据的指针,不知道用来干嘛

        /**
         * I/O context.
    输入/输出上下文,这是什么东西,还上下文,真搞不懂。         
    *
         * - demuxing: either set by the user before avformat_open_input() (then
         *             the user must close it manually) or set by avformat_open_input().
    demuxing可以用两种方法来初始化,第一种,在调用avformat_open_input()之前初始化,
    这时候就要注意,一定要手动关闭demuxing,第二种就是用avformat_open_input()函数来
    初始化
    * - muxing: set by the user before avformat_write_header(). The caller must
         *           take care of closing / freeing the IO context.
         *
    muxing,要在使用avformat_write_header()之前初始化,并且要记住关闭和释放IO Context
         * Do NOT set this field if AVFMT_NOFILE flag is set in
    如果AVFMT_NOFILE标志处于激活状态的话,就不能初始化这个结构体。
         * iformat/oformat.flags. In such a case, the (de)muxer will handle
    
         * I/O in some other way and this field will be NULL.
    这个IO结构体的使用是有条件的,条件不满足的话,这个结构体指针就指向NULL         
    */
        AVIOContext *pb;

        /* stream info *///这一段是流信息部分
        /**
         * Flags signalling stream properties. A combination of AVFMTCTX_*.
    标记信号传输流的属性
         * Set by libavformat.
         */
        int ctx_flags;

        /**
         * Number of elements in AVFormatContext.streams.
         *
    AVFormatContext.streams中元素的数量,这里的元素应该是视频流和音频流吧
         * Set by avformat_new_stream(), must not be modified by any other code.
    这个成员是用avformat_new_stream()函数初始化,并且不能被其他代码修改
         */
        unsigned int nb_streams;
        /**
         * A list of all streams in the file. New streams are created with
         * avformat_new_stream().
    所有的流都在这个结构体中,新的流也可以通过avformat_new_stream()
    这个函数加入其中
         *
         * - demuxing: streams are created by libavformat in avformat_open_input().
         *             If AVFMTCTX_NOHEADER is set in ctx_flags, then new streams may also
         *             appear in av_read_frame().
    在解复用的时候还可以通过avformat_open_input()函数把新的流加到结构体中,并且
    在使用ac_read_frame()函数的时候还可能得到新加入的流
         * - muxing: streams are created by the user before avformat_write_header().
    在复用打包的时候,新的流也可以利用acformat_write_header()函数写入到结构体中
         *
         * Freed by libavformat in avformat_free_context().
    用avformat_free_context()函数释放内存
         */
        AVStream **streams;

        /**
         * input or output filename
    这是输入输出文件的文件名
         *
         * - demuxing: set by avformat_open_input()
    解复用的时候,用avformat_open_input()函数初始化
         * - muxing: may be set by the caller before avformat_write_header()
    复用打包的时候用avformat_write_header()函数初始化
         */
        char filename[1024];

        /**
         * 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.
    只有在解复用的时候才有用,实现函数在libacformat库中
         */
        int64_t start_time;

        /**
         * 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.
         */
        int64_t duration;

        /**
         * 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.
    这个说的应该说的是视频的传播速度,也就是所谓的比特率
         */
        int bit_rate;

        unsigned int packet_size;
        int max_delay;

        /**
         * Flags modifying the (de)muxer behaviour. A combination of AVFMT_FLAG_*.
         * Set by the user before avformat_open_input() / avformat_write_header().
    修改复用(解复用)行为的标识         
    */
        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_NOBUFFER     0x0040 ///< Do not buffer frames when possible
    #define AVFMT_FLAG_CUSTOM_IO    0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
    #define AVFMT_FLAG_DISCARD_CORRUPT  0x0100 ///< Discard frames marked corrupted
    #define AVFMT_FLAG_FLUSH_PACKETS    0x0200 ///< Flush the AVIOContext every packet.
    /**
     * When muxing, try to avoid writing any random/volatile data to the output.
    * This includes any random IDs, real-time timestamps/dates, muxer version, etc.
     *
    在复用打包的时候尽量避免写入其他的随机数据
     * This flag is mainly intended for testing.
     */
    #define AVFMT_FLAG_BITEXACT         0x0400    
    #define AVFMT_FLAG_MP4A_LATM    0x8000 ///< Enable RTP MP4A-LATM payload
    #define AVFMT_FLAG_SORT_DTS    0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down)
    #define AVFMT_FLAG_PRIV_OPT    0x20000 ///< Enable use of private options by delaying codec open (this could be made default once all code is     converted)
    #define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000 ///< Don't merge side data but keep it separate.

        /**
         * Maximum size of the data read from input for determining
         * the input container format.
    解复用时候从文件中读出数据包的最大大小
         * Demuxing only, set by the caller before avformat_open_input().
         */
        unsigned int probesize;

        /**
         * @deprecated deprecated in favor of max_analyze_duration2
         */
        attribute_deprecated
        int max_analyze_duration;

        const uint8_t *key;
        int keylen;

        unsigned int nb_programs;
        AVProgram **programs;

        /**
         * Forced video codec_id.
         * Demuxing: Set by user.
    视频编解码器的位置
         */
        enum AVCodecID video_codec_id;

        /**
         * Forced audio codec_id.
         * Demuxing: Set by user.
    音频编解码器的位置
         */
        enum AVCodecID audio_codec_id;

        /**
         * Forced subtitle codec_id.
         * Demuxing: Set by user.
    字幕编解码器的位置
         */
        enum AVCodecID subtitle_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 int max_index_size;

        /**
         * Maximum amount of memory in bytes to use for buffering frames
         * obtained from realtime capture devices.
    这个和上面的意思差不多,都是限定上限吧
         */
        unsigned int max_picture_buffer;

        /**
         * 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
    完全没看懂什么意思
         */
        unsigned int nb_chapters;
        AVChapter **chapters;

        /**
         * Metadata that applies to the whole file.
         *
         * - demuxing: set by libavformat in avformat_open_input()
         * - muxing: may be set by the caller before avformat_write_header()
         *
        * Freed by libavformat in avformat_free_context().
    什么元数据,没看懂。
         */
        AVDictionary *metadata;

        /**
         * 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: Set by the caller before avformat_write_header(). If set to
         *           either 0 or AV_NOPTS_VALUE, then the current wall-time will
         *           be used.
         * - demuxing: Set by libavformat. AV_NOPTS_VALUE if unknown. Note that
         *             the value may become known after some number of frames
         *             have been received.
    这个是复用或者解复用开始的时间,计时的标准是unix标准
         */
        int64_t start_time_realtime;

        /**
         * 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().
    这个参数估计是和帧率有关系的。
         */
        int fps_probe_size;

        /**
         * 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().
    这儿应该是打开文件时候报错用的。
         */
        int error_recognition;

        /**
        * 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.
    这个不知道是什么。
         */
        AVIOInterruptCB interrupt_callback;

        /**
         * Flags to enable debugging.
    有能力的debug的标识,布吉岛神马一系。
         */
        int debug;
    #define FF_FDEBUG_TS        0x0001

        /**
         * 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().
    这个估计是为了保证缓冲区内所有的流都被打包到文件中
         */
        int64_t max_interleave_delta;

        /**
         * Allow non-standard and experimental extension
         * @see AVCodecContext.strict_std_compliance
         */
        int strict_std_compliance;

        /**
         * Transport stream id.
         * This will be moved into demuxer private options. Thus no API/ABI compatibility
         */
        int ts_id;

        /**
         * Audio preload in microseconds.
         * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
         * - encoding: Set by user via AVOptions (NO direct access)
         * - decoding: unused
         */
        int audio_preload;

        /**
         * Max chunk time in microseconds.
         * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
         * - encoding: Set by user via AVOptions (NO direct access)
         * - decoding: unused
         */
        int max_chunk_duration;

        /**
         * Max chunk size in bytes
         * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
         * - encoding: Set by user via AVOptions (NO direct access)
         * - decoding: unused
         */
        int max_chunk_size;

        /**
         * forces the use of wallclock timestamps as pts/dts of packets
         * This has undefined results in the presence of B frames.
         * - encoding: unused
         * - decoding: Set by user via AVOptions (NO direct access)
         */
        int use_wallclock_as_timestamps;

        /**
         * Avoid negative timestamps during muxing.
         *  0 -> allow negative timestamps
         *  1 -> avoid negative timestamps
         * -1 -> choose automatically (default)
         * Note, this only works when interleave_packet_per_dts is in use.
         * - encoding: Set by user via AVOptions (NO direct access)
         * - decoding: unused
         */
        int avoid_negative_ts;

        /**
         * avio flags, used to force AVIO_FLAG_DIRECT.
         * - encoding: unused
         * - decoding: Set by user via AVOptions (NO direct access)
         */
        int avio_flags;

        /**
         * The duration field can be estimated through various ways, and this field can be used
         * to know how the duration was estimated.
         * - encoding: unused
         * - decoding: Read by user via AVOptions (NO direct access)
         */
        enum AVDurationEstimationMethod duration_estimation_method;

        /**
         * Skip initial bytes when opening stream
         * - encoding: unused
         * - decoding: Set by user via AVOptions (NO direct access)
         */
        int64_t skip_initial_bytes;

        /**
         * Correct single timestamp overflows
         * - encoding: unused
         * - decoding: Set by user via AVOptions (NO direct access)
         */
        unsigned int correct_ts_overflow;

        /**
         * Force seeking to any (also non key) frames.
         * - encoding: unused
         * - decoding: Set by user via AVOptions (NO direct access)
         */
        int seek2any;

        /**
         * Flush the I/O context after each packet.
         * - encoding: Set by user via AVOptions (NO direct access)
         * - decoding: unused
         */
        int flush_packets;

        /**
         * format probing score.
         * The maximal score is AVPROBE_SCORE_MAX, its set when the demuxer probes
         * the format.
         * - encoding: unused
         * - decoding: set by avformat, read by user via av_format_get_probe_score() (NO direct access)
         */
        int probe_score;

        /**
         * number of bytes to read maximally to identify format.
         * - encoding: unused
         * - decoding: set by user through AVOPtions (NO direct access)
         */
        int format_probesize;

        /*****************************************************************
         * All fields below this line are not part of the public API. They
         * may not be used outside of libavformat and can be changed and
         * removed at will.
         * New public fields should be added right above.
    下面的都是私有的API
         *****************************************************************
         */

        /**
         * This buffer is only needed when packets were already buffered but
         * not decoded, for example to get the codec parameters in MPEG
         * streams.
         */
        struct AVPacketList *packet_buffer;
        struct AVPacketList *packet_buffer_end;

        /* av_seek_frame() support */
        int64_t data_offset; /**< offset of the first packet */

        /**
         * 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.
         */
        struct AVPacketList *raw_packet_buffer;
        struct AVPacketList *raw_packet_buffer_end;
        /**
         * Packets split by the parser get queued here.
         */
        struct AVPacketList *parse_queue;
        struct AVPacketList *parse_queue_end;
        /**
         * Remaining size available for raw_packet_buffer, in bytes.
         */
    #define RAW_PACKET_BUFFER_SIZE 2500000
        int raw_packet_buffer_remaining_size;

        /**
         * Offset to remap timestamps to be non-negative.
         * Expressed in timebase units.
         * @see AVStream.mux_ts_offset
         */
        int64_t offset;

        /**
         * Timebase for the timestamp offset.
         */
        AVRational offset_timebase;

        /**
         * An opaque field for libavformat internal usage.
         * Must not be accessed in any way by callers.
         */
        AVFormatInternal *internal;

        /**
         * IO repositioned flag.
         * This is set by avformat when the underlaying IO context read pointer
         * is repositioned, for example when doing byte based seeking.
         * Demuxers can use the flag to detect such changes.
         */
        int io_repositioned;

        /**
         * Forced video codec.
         * This allows forcing a specific decoder, even when there are multiple with
         * the same codec_id.
         * Demuxing: Set by user via av_format_set_video_codec (NO direct access).
         */
        AVCodec *video_codec;

        /**
         * Forced audio codec.
         * This allows forcing a specific decoder, even when there are multiple with
         * the same codec_id.
         * Demuxing: Set by user via av_format_set_audio_codec (NO direct access).
         */
        AVCodec *audio_codec;

        /**
         * Forced subtitle codec.
         * This allows forcing a specific decoder, even when there are multiple with
         * the same codec_id.
        * Demuxing: Set by user via av_format_set_subtitle_codec (NO direct access).
         */
        AVCodec *subtitle_codec;

        /**
         * Number of bytes to be written as padding in a metadata header.
         * Demuxing: Unused.
         * Muxing: Set by user via av_format_set_metadata_header_padding.
         */
        int metadata_header_padding;

        /**
         * User data.
         * This is a place for some private data of the user.
         * Mostly usable with control_message_cb or any future callbacks in device's context.
         */
        void *opaque;

        /**
         * Callback used by devices to communicate with application.
         */
        av_format_control_message control_message_cb;

        /**
        * Output timestamp offset, in microseconds.
         * Muxing: set by user via AVOptions (NO direct access)
         */
        int64_t output_ts_offset;

        /**
         * 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()
         * via AVOptions (NO direct access).
         * Can be set to 0 to let avformat choose using a heuristic.
         */
        int64_t max_analyze_duration2;
} AVFormatContext;

转载于:https://my.oschina.net/u/1757926/blog/305614

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值