ffmpeg之AVPacket

1200阅读 0评论2017-09-20 leiminchn
分类:C/C++

1. AVPacket简介

   
AVPacket用于存放压缩后的数据。
    
通常是解复用的输出,解码的输入;或者是编码的输出,复用的输入。
    
对于视频数据,AVPacket通常包含一帧视频压缩数据;对于音频数据数据,AVPacket则通常包含了数帧的音频压缩数据。
    
其大小是public ABI的一部分,因此可以在栈上分配。
    
其数据有效期取决于“buf”或“destruct”,如果字段设置了,数据包的管理由ffmpeg负责,数据包在avt_free_packet(内部调用avt_buffer_unref)调用前都有效;如果字段未设置,数据包由调用者管理。

2. AVPacket定义

点击(此处)折叠或打开

  1. typedef struct AVPacket {
  2.     /**
  3.      * A reference to the reference-counted buffer where the packet data is
  4.      * stored.
  5.      * May be NULL, then the packet data is not reference-counted.
  6.      */
  7.     AVBufferRef* buf;
  8.     /**
  9.      * Presentation timestamp in AVStream->time_base units; the time at which
  10.      * the decompressed packet will be presented to the user.
  11.      * Can be AV_NOPTS_VALUE if it is not stored in the file.
  12.      * pts MUST be larger or equal to dts as presentation cannot happen before
  13.      * decompression, unless one wants to view hex dumps. Some formats misuse
  14.      * the terms dts and pts/cts to mean something different. Such timestamps
  15.      * must be converted to true pts/dts before they are stored in AVPacket.
  16.      */
  17.     int64_t pts;
  18.     /**
  19.      * Decompression timestamp in AVStream->time_base units; the time at which
  20.      * the packet is decompressed.
  21.      * Can be AV_NOPTS_VALUE if it is not stored in the file.
  22.      */
  23.     int64_t dts;
  24.     uint8_t* data;
  25.     int size;
  26.     int stream_index;
  27.     /**
  28.      * A combination of AV_PKT_FLAG values
  29.      */
  30.     int flags;
  31.     /**
  32.      * Additional packet data that can be provided by the container.
  33.      * Packet can contain several types of side information.
  34.      */
  35.     AVPacketSideData* side_data;
  36.     int side_data_elems;

  37.     /**
  38.      * Duration of this packet in AVStream->time_base units, 0 if unknown.
  39.      * Equals next_pts - this_pts in presentation order.
  40.      */
  41.     int duration;
  42. #if FF_API_DESTRUCT_PACKET
  43.     attribute_deprecated
  44.     void (*destruct)(struct AVPacket *);
  45.     attribute_deprecated
  46.     voidpriv;
  47. #endif
  48.     int64_t pos; ///< byte position in stream, -1 if unknown

  49.     /**
  50.      * Time difference in AVStream->time_base units from the pts of this
  51.      * packet to the point at which the output from the decoder has converged
  52.      * independent from the availability of previous frames. That is, the
  53.      * frames are virtually identical no matter if decoding started from
  54.      * the very first frame or from this keyframe.
  55.      * Is AV_NOPTS_VALUE if unknown.
  56.      * This field is not the display duration of the current packet.
  57.      * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
  58.      * set.
  59.      *
  60.      * The purpose of this field is to allow seeking in streams that have no
  61.      * keyframes in the conventional sense. It corresponds to the
  62.      * recovery point SEI in H.264 and match_time_delta in NUT. It is also
  63.      * essential for some types of subtitle streams to ensure that all
  64.      * subtitles are correctly displayed after seeking.
  65.      */
  66.     int64_t convergence_duration;
  67. } AVPacket;

3. AVPacket字段说明

    AVBufferRef* buf : data的引用计数结构体,可能为NULL。不为NULL时,数据管理由ffmpeg负责,为NULL时由调用者自己负责。
    int64_t pts : 压缩数据显示时间戳。比较关键的数据,在做seek和播放进度的时候都要用到它,pts只是一个数量,对应于AVStream->time_base,要根据time_base才能转换为具体的时间,音频和视频一般有不同的time_base,所以在做音视频同步一定要做转换,不能直接拿pts做。
    int64_t dts : 压缩数据解码时间戳。
    uint8_t* data :压缩数据。
    int   size :压缩数据大小。
    int   stream_index :所属媒体流的索引。用来区分音频,视频,和字幕数据。
    int   flags : 标识域。其中为1表示该数据是一个关键帧,AV_PKT_FLAG_KEY 0x0001 关键帧
    AVPacketSideData* side_data :附加数据。
    int side_data_elems :附加数据大小。
    int   duration :压缩数据时长。
    void  (*destruct)(struct AVPacket *) :压缩数据释放函数指针。
    
void* priv  
    
int64_t pos :压缩数据在媒体流中的偏移量,未知为-1。
    
int64_t convergence_duration : 


上一篇:MPEG-2简介及MPEG-2编解码-(1)
下一篇:ffmpeg之AVPicture、AVFrame