AVPacket

来源:互联网 发布:怎么删除淘宝评论记录 编辑:程序博客网 时间:2024/06/05 14:52

在此不再详述,其中AVPacket是存储压缩编码数据相关信息的结构体。本文将会详细分析一下该结构体里重要变量的含义和作用。

  1. typedef struct AVPacket {  
  2.     /** 
  3.      * Presentation timestamp in AVStream->time_base units; the time at which 
  4.      * the decompressed packet will be presented to the user. 
  5.      * Can be AV_NOPTS_VALUE if it is not stored in the file. 
  6.      * pts MUST be larger or equal to dts as presentation cannot happen before 
  7.      * decompression, unless one wants to view hex dumps. Some formats misuse 
  8.      * the terms dts and pts/cts to mean something different. Such timestamps 
  9.      * must be converted to true pts/dts before they are stored in AVPacket. 
  10.      */  
  11.     int64_t pts;  
  12.     /** 
  13.      * Decompression timestamp in AVStream->time_base units; the time at which 
  14.      * the packet is decompressed. 
  15.      * Can be AV_NOPTS_VALUE if it is not stored in the file. 
  16.      */  
  17.     int64_t dts;  
  18.     uint8_t *data;  
  19.     int   size;  
  20.     int   stream_index;  
  21.     /** 
  22.      * A combination of AV_PKT_FLAG values 
  23.      */  
  24.     int   flags;  
  25.     /** 
  26.      * Additional packet data that can be provided by the container. 
  27.      * Packet can contain several types of side information. 
  28.      */  
  29.     struct {  
  30.         uint8_t *data;  
  31.         int      size;  
  32.         enum AVPacketSideDataType type;  
  33.     } *side_data;  
  34.     int side_data_elems;  
  35.   
  36.     /** 
  37.      * Duration of this packet in AVStream->time_base units, 0 if unknown. 
  38.      * Equals next_pts - this_pts in presentation order. 
  39.      */  
  40.     int   duration;  
  41.     void  (*destruct)(struct AVPacket *);  
  42.     void  *priv;  
  43.     int64_t pos;                            ///< byte position in stream, -1 if unknown  
  44.   
  45.     /** 
  46.      * Time difference in AVStream->time_base units from the pts of this 
  47.      * packet to the point at which the output from the decoder has converged 
  48.      * independent from the availability of previous frames. That is, the 
  49.      * frames are virtually identical no matter if decoding started from 
  50.      * the very first frame or from this keyframe. 
  51.      * Is AV_NOPTS_VALUE if unknown. 
  52.      * This field is not the display duration of the current packet. 
  53.      * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY 
  54.      * set. 
  55.      * 
  56.      * The purpose of this field is to allow seeking in streams that have no 
  57.      * keyframes in the conventional sense. It corresponds to the 
  58.      * recovery point SEI in H.264 and match_time_delta in NUT. It is also 
  59.      * essential for some types of subtitle streams to ensure that all 
  60.      * subtitles are correctly displayed after seeking. 
  61.      */  
  62.     int64_t convergence_duration;  
  63. } AVPacket;  

在AVPacket结构体中,重要的变量有以下几个:

uint8_t *data:压缩编码的数据。

例如对于H.264来说。1个AVPacket的data通常对应一个NAL。

注意:在这里只是对应,而不是一模一样。他们之间有微小的差别:使用FFMPEG类库分离出多媒体文件中的H.264码流

因此在使用FFMPEG进行视音频处理的时候,常常可以将得到的AVPacket的data数据直接写成文件,从而得到视音频的码流文件。

int   size:data的大小

int64_t pts:显示时间戳

int64_t dts:解码时间戳

int   stream_index:标识该AVPacket所属的视频/音频流。

这个结构体虽然比较简单,但是非常的常用

0 0
原创粉丝点击