ffmpeg常用数据结构2

AVStream

该结构体描述一个媒体流,定义如下:

typedefstructAVStream {

int index;    /**< stream index in AVFormatContext */

int id;       /**< format-specific stream ID */

AVCodecContext *codec; /**< codec context */

    /**

     * Real base framerate of the stream.

     * This is the lowest framerate with which all timestamps can be

     * represented accurately (it is the least common multiple of all

     * framerates in the stream). Note, this value is just a guess!

     * For example, if the time base is 1/90000 and all frames have either

     * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.

     */

AVRationalr_frame_rate;

    ......

    /**

     * This is the fundamental unit of time (in seconds) in terms

     * of which frame timestamps are represented. For fixed-fps content,

     * time base should be 1/framerate and timestamp increments should be 1.

     */

AVRationaltime_base;

    ......

    /**

     * Decoding: pts of the first frame of the stream, in stream time base.

     * Only set this if you are absolutely 100% sure that the value you set

     * it to really is the pts of the first frame.

     * This may be undefined (AV_NOPTS_VALUE).

     * @note The ASF header does NOT contain a correct start_time the ASF

     * demuxer must NOT set this.

     */

    int64_t start_time;

    /**

     * Decoding: duration of the stream, in stream time base.

     * If a source file does not specify a duration, but does specify

     * a bitrate, this value will be estimated from bitrate and file size.

     */

    int64_t duration;

#if LIBAVFORMAT_VERSION_INT < (53<<16)

    char language[4]; /** ISO 639-2/B 3-letter language code (empty string if undefined) */

#endif

    /* av_read_frame() support */

enumAVStreamParseTypeneed_parsing;

structAVCodecParserContext *parser;

    ......

    /* av_seek_frame() support */

AVIndexEntry *index_entries; /**< Only used if the format does not

                                    support seeking natively. */

intnb_index_entries;

    unsigned intindex_entries_allocated_size;

    int64_t nb_frames;                 ///< number of frames in this stream if known or 0

    ......

    /**

     * Average framerate

     */

AVRationalavg_frame_rate;

    ......

} AVStream;

主要域的释义如下,其中大部分域的值可以avformat_open_input根据文件头的信息确定,缺少的信息需要通过调用avformat_find_stream_info读帧及软解码进一步获取:

    index/idindex对应流的索引,这个数字是自动生成的,根据index可以从AVFormatContext::streams表中索引到该流;而id则是流的标识,依赖于具体的容器格式。比如对于MPEG TS格式,id就是pid

time_base:流的时间基准,是一个实数,该流中媒体数据的ptsdts都将以这个时间基准为粒度。通常,使用av_rescale/av_rescale_q可以实现不同时间基准的转换

start_time流的起始时间,以流的时间基准为单位,通常是该流中第一个帧的pts

    duration:流的总时间,以流的时间基准为单位。

need_parsing:对该流parsing过程的控制域。

nb_frames流内的帧数目

r_frame_rate/framerate/avg_frame_rate:帧率相关。

    codec:指向该流对应的AVCodecContext结构,调用avformat_open_input时生成。

    parser指向该流对应的AVCodecParserContext结构,调用avformat_find_stream_info时生成。
原文地址:https://www.cnblogs.com/elesos/p/2990584.html