FFMPEG结构体分析:AVStream

来源:互联网 发布:sql课程设计说明书模板 编辑:程序博客网 时间:2024/06/05 02:16

注:写了一系列的结构体的分析的文章,在这里列一个列表:

FFMPEG结构体分析:AVFrame
FFMPEG结构体分析:AVFormatContext
FFMPEG结构体分析:AVCodecContext
FFMPEG结构体分析:AVIOContext
FFMPEG结构体分析:AVCodec
FFMPEG结构体分析:AVStream
FFMPEG结构体分析:AVPacket


FFMPEG有几个最重要的结构体,包含了解协议,解封装,解码操作,此前已经进行过分析:

FFMPEG中最关键的结构体之间的关系

在此不再详述,其中AVStream是存储每一个视频/音频流信息的结构体。本文将会分析一下该结构体里重要变量的含义和作用。

首先看一下结构体的定义(位于avformat.h文件中):

[cpp] view plain copy

  1. /** 
  2.  * Stream structure. 
  3.  * New fields can be added to the end with minor version bumps. 
  4.  * Removal, reordering and changes to existing fields require a major 
  5.  * version bump. 
  6.  * sizeof(AVStream) must not be used outside libav*. 
  7.  */  
  8. typedef struct AVStream {  
  9.     int index;    /**< stream index in AVFormatContext */  
  10.     /** 
  11.      * Format-specific stream ID. 
  12.      * decoding: set by libavformat 
  13.      * encoding: set by the user 
  14.      */  
  15.     int id;  
  16.     AVCodecContext *codec; /**< codec context */  
  17.     /** 
  18.      * Real base framerate of the stream. 
  19.      * This is the lowest framerate with which all timestamps can be 
  20.      * represented accurately (it is the least common multiple of all 
  21.      * framerates in the stream). Note, this value is just a guess! 
  22.      * For example, if the time base is 1/90000 and all frames have either 
  23.      * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1. 
  24.      */  
  25.     AVRational r_frame_rate;  
  26.     void *priv_data;  
  27.   
  28.     /** 
  29.      * encoding: pts generation when outputting stream 
  30.      */  
  31.     struct AVFrac pts;  
  32.   
  33.     /** 
  34.      * This is the fundamental unit of time (in seconds) in terms 
  35.      * of which frame timestamps are represented. For fixed-fps content, 
  36.      * time base should be 1/framerate and timestamp increments should be 1. 
  37.      * decoding: set by libavformat 
  38.      * encoding: set by libavformat in av_write_header 
  39.      */  
  40.     AVRational time_base;  
  41.   
  42.     /** 
  43.      * Decoding: pts of the first frame of the stream in presentation order, in stream time base. 
  44.      * Only set this if you are absolutely 100% sure that the value you set 
  45.      * it to really is the pts of the first frame. 
  46.      * This may be undefined (AV_NOPTS_VALUE). 
  47.      * @note The ASF header does NOT contain a correct start_time the ASF 
  48.      * demuxer must NOT set this. 
  49.      */  
  50.     int64_t start_time;  
  51.   
  52.     /** 
  53.      * Decoding: duration of the stream, in stream time base. 
  54.      * If a source file does not specify a duration, but does specify 
  55.      * a bitrate, this value will be estimated from bitrate and file size. 
  56.      */  
  57.     int64_t duration;  
  58.   
  59.     int64_t nb_frames;                 ///< number of frames in this stream if known or 0  
  60.   
  61.     int disposition; /**< AV_DISPOSITION_* bit field */  
  62.   
  63.     enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.  
  64.   
  65.     /** 
  66.      * sample aspect ratio (0 if unknown) 
  67.      * - encoding: Set by user. 
  68.      * - decoding: Set by libavformat. 
  69.      */  
  70.     AVRational sample_aspect_ratio;  
  71.   
  72.     AVDictionary *metadata;  
  73.   
  74.     /** 
  75.      * Average framerate 
  76.      */  
  77.     AVRational avg_frame_rate;  
  78.   
  79.     /** 
  80.      * For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet 
  81.      * will contain the attached picture. 
  82.      * 
  83.      * decoding: set by libavformat, must not be modified by the caller. 
  84.      * encoding: unused 
  85.      */  
  86.     AVPacket attached_pic;  
  87.   
  88.     /***************************************************************** 
  89.      * All fields below this line are not part of the public API. They 
  90.      * may not be used outside of libavformat and can be changed and 
  91.      * removed at will. 
  92.      * New public fields should be added right above. 
  93.      ***************************************************************** 
  94.      */  
  95.   
  96.     /** 
  97.      * Stream information used internally by av_find_stream_info() 
  98.      */  
  99. #define MAX_STD_TIMEBASES (60*12+5)  
  100.     struct {  
  101.         int64_t last_dts;  
  102.         int64_t duration_gcd;  
  103.         int duration_count;  
  104.         double duration_error[2][2][MAX_STD_TIMEBASES];  
  105.         int64_t codec_info_duration;  
  106.         int nb_decoded_frames;  
  107.         int found_decoder;  
  108.     } *info;  
  109.   
  110.     int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */  
  111.   
  112.     // Timestamp generation support:  
  113.     /** 
  114.      * Timestamp corresponding to the last dts sync point. 
  115.      * 
  116.      * Initialized when AVCodecParserContext.dts_sync_point >= 0 and 
  117.      * a DTS is received from the underlying container. Otherwise set to 
  118.      * AV_NOPTS_VALUE by default. 
  119.      */  
  120.     int64_t reference_dts;  
  121.     int64_t first_dts;  
  122.     int64_t cur_dts;  
  123.     int64_t last_IP_pts;  
  124.     int last_IP_duration;  
  125.   
  126.     /** 
  127.      * Number of packets to buffer for codec probing 
  128.      */  
  129. #define MAX_PROBE_PACKETS 2500  
  130.     int probe_packets;  
  131.   
  132.     /** 
  133.      * Number of frames that have been demuxed during av_find_stream_info() 
  134.      */  
  135.     int codec_info_nb_frames;  
  136.   
  137.     /** 
  138.      * Stream Identifier 
  139.      * This is the MPEG-TS stream identifier +1 
  140.      * 0 means unknown 
  141.      */  
  142.     int stream_identifier;  
  143.   
  144.     int64_t interleaver_chunk_size;  
  145.     int64_t interleaver_chunk_duration;  
  146.   
  147.     /* av_read_frame() support */  
  148.     enum AVStreamParseType need_parsing;  
  149.     struct AVCodecParserContext *parser;  
  150.   
  151.     /** 
  152.      * last packet in packet_buffer for this stream when muxing. 
  153.      */  
  154.     struct AVPacketList *last_in_packet_buffer;  
  155.     AVProbeData probe_data;  
  156. #define MAX_REORDER_DELAY 16  
  157.     int64_t pts_buffer[MAX_REORDER_DELAY+1];  
  158.   
  159.     AVIndexEntry *index_entries; /**< Only used if the format does not 
  160.                                     support seeking natively. */  
  161.     int nb_index_entries;  
  162.     unsigned int index_entries_allocated_size;  
  163.   
  164.     /** 
  165.      * flag to indicate that probing is requested 
  166.      * NOT PART OF PUBLIC API 
  167.      */  
  168.     int request_probe;  
  169. } AVStream;  

AVStream重要的变量如下所示:

int index:标识该视频/音频流

AVCodecContext *codec:指向该视频/音频流的AVCodecContext(它们是一一对应的关系)

AVRational time_base:时基。通过该值可以把PTS,DTS转化为真正的时间。FFMPEG其他结构体中也有这个字段,但是根据我的经验,只有AVStream中的time_base是可用的。PTS*time_base=真正的时间

int64_t duration:该视频/音频流长度

AVDictionary *metadata:元数据信息

AVRational avg_frame_rate:帧率(注:对视频来说,这个挺重要的)

AVPacket attached_pic:附带的图片。比如说一些MP3,AAC音频文件附带的专辑封面。

该结构体其他字段的作用目前还有待于探索。


原创粉丝点击