AVStream

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

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

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

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值