AVPacket(avcodec.h)

不会笑的孩子發表於2024-03-09

AVPacket

AVPacket是儲存壓縮編碼資料相關資訊的結構體。

typedef struct AVPacket {
    /**
     * Presentation timestamp in AVStream->time_base units; the time at which
     * the decompressed packet will be presented to the user.
     * Can be AV_NOPTS_VALUE if it is not stored in the file.
     * pts MUST be larger or equal to dts as presentation cannot happen before
     * decompression, unless one wants to view hex dumps. Some formats misuse
     * the terms dts and pts/cts to mean something different. Such timestamps
     * must be converted to true pts/dts before they are stored in AVPacket.
     */
    int64_t pts;
    /**
     * Decompression timestamp in AVStream->time_base units; the time at which
     * the packet is decompressed.
     * Can be AV_NOPTS_VALUE if it is not stored in the file.
     */
    int64_t dts;
    uint8_t *data;
    int   size;
    int   stream_index;
    /**
     * A combination of AV_PKT_FLAG values
     */
    int   flags;
    /**
     * Additional packet data that can be provided by the container.
     * Packet can contain several types of side information.
     */
    struct {
        uint8_t *data;
        int      size;
        enum AVPacketSideDataType type;
    } *side_data;
    int side_data_elems;
 
    /**
     * Duration of this packet in AVStream->time_base units, 0 if unknown.
     * Equals next_pts - this_pts in presentation order.
     */
    int   duration;
    void  (*destruct)(struct AVPacket *);
    void  *priv;
    int64_t pos;                            ///< byte position in stream, -1 if unknown
 
    /**
     * Time difference in AVStream->time_base units from the pts of this
     * packet to the point at which the output from the decoder has converged
     * independent from the availability of previous frames. That is, the
     * frames are virtually identical no matter if decoding started from
     * the very first frame or from this keyframe.
     * Is AV_NOPTS_VALUE if unknown.
     * This field is not the display duration of the current packet.
     * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
     * set.
     *
     * The purpose of this field is to allow seeking in streams that have no
     * keyframes in the conventional sense. It corresponds to the
     * recovery point SEI in H.264 and match_time_delta in NUT. It is also
     * essential for some types of subtitle streams to ensure that all
     * subtitles are correctly displayed after seeking.
     */
    int64_t convergence_duration;
} AVPacket;

pts 表示該幀的呈現時間戳(Presentation Timestamp),以AVStream->time_base為單位。即解壓後的幀將呈現給使用者的時間。如果不在檔案中儲存,則可以是AV_NOPTS_VALUE。

dts:表示該幀的解壓時間戳(Decompression Timestamp),以AVStream->time_base為單位。即該幀解壓的時間。如果不在檔案中儲存,則可以是AV_NOPTS_VALUE。

data:指向資料緩衝區的指標。

size:資料緩衝區的大小。

stream_index:表示該幀所屬的流在AVFormatContext中的索引。

flags:標誌位的組合,表示AV_pKT_FLAG的值。

side_data:(AVPacketSideData結構體指標陣列):指向可以由容器提供的附加包資料的指標陣列。

duration:以AVStream->time_base為單位的該幀的持續時間。如果未知,則為0。

destruct:指向一個函式的指標,用於銷燬AVPacket。

priv:私有資料指標。

pos:該幀在流中的位元組位置,如果未知則為-1.

convergence_duration:表示從該幀的pts到解碼器輸出收斂的時間差。用AVStream->time_base單位表示。如果未知,則為AV_NOPTS_VALUE。這個欄位在沒有傳統關鍵幀的流中進行定位非常重要。