FFMPEG結構體分析:AVPacket

注:寫了一系列的結構體的分析的文章,在這裏列一個列表:

FFMPEG結構體分析:AVFrame
FFMPEG結構體分析:AVFormatContext
FFMPEG結構體分析:AVCodecContext
FFMPEG結構體分析:AVIOContext
FFMPEG結構體分析:AVCodec
FFMPEG結構體分析:AVStream
FFMPEG結構體分析:AVPacket


FFMPEG有幾個最重要的結構體,包含了解協議,解封裝,解碼操作,此前已經進行過分析:

FFMPEG中最關鍵的結構體之間的關係


在此不再詳述,其中AVPacket是存儲壓縮編碼數據相關信息的結構體。本文將會詳細分析一下該結構體裏重要變量的含義和作用。

首先看一下結構體的定義(位於avcodec.h文件中):

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

這個結構體雖然比較簡單,但是非常的常用。


原文地址:http://blog.csdn.net/leixiaohua1020/article/details/14215755

發佈了4 篇原創文章 · 獲贊 1 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章