FFmpeg結構體:AVPacket

1.描述

AVPacket用于存儲壓縮數據,位于avcodec.h文件中。
通常由demuxer導出,然后作為輸入傳遞給解碼器;或者作為編碼器的輸出,然后傳遞給muxer。
對于視頻,它通常應包含一個壓縮幀。 對于音頻,它可能包含幾個壓縮幀。 允許編碼器輸出空分組,沒有壓縮數據,僅包含輔助數據(例如,在編碼結束時更新一些參數)。

2.結構體定義

typedef struct AVPacket {
    /**
     * A reference to the reference-counted buffer where the packet data is
     * stored.
     * May be NULL, then the packet data is not reference-counted.
     */
    AVBufferRef *buf;
    /**
     * 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.
     */
    AVPacketSideData *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.
     */
    int64_t duration;

    int64_t pos;                            ///< byte position in stream, -1 if unknown

#if FF_API_CONVERGENCE_DURATION
    /**
     * @deprecated Same as the duration field, but as int64_t. This was required
     * for Matroska subtitles, whose duration values could overflow when the
     * duration field was still an int.
     */
    attribute_deprecated
    int64_t convergence_duration;
#endif
} AVPacket;

3.常見變量及其作用

AVPacket這個結構體變量分析:

AVBufferRef *buf; //緩沖包數據存儲位置。
int64_t pts;           //顯示時間戳,以AVStream->time_base為單位。
int64_t dts;        //解碼時間戳,以AVStream->time_base為單位。
uint8_t *data;     //壓縮編碼的數據。
int   size;//data的大小。
int   stream_index;//給出所屬媒體流的索引。
int   flags;//標識域,其中,最低位置1表示該數據是一個關鍵幀。
AVPacketSideData *side_data;//容器提供的額外數據包。
int64_t duration;//Packet持續的時間,以AVStream->time_base為單位。
int64_t pos;//表示該數據在媒體流中的字節偏移量。

AVPacket結構本身只是一個容器,它使用data成員引用實際的數據緩沖區。這個緩沖區通常是由av_new_packet創建的,但也可能由FFmpeg的API創建(如av_read_frame)。當某個AVPacket結構的數據緩沖區不再被使用時,要需要通過調用av_free_packet釋放。
這個結構體在FFmpeg中非常常見,需要重點掌握。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 教程一:視頻截圖(Tutorial 01: Making Screencaps) 首先我們需要了解視頻文件的一些基...
    90后的思維閱讀 4,794評論 0 3
  • ffmpeg是一個非常有用的命令行程序,它可以用來轉碼媒體文件。它是領先的多媒體框架FFmpeg的一部分,其有很多...
    城市之光閱讀 6,883評論 3 6
  • 本篇博客在雷神的結構體介紹基礎上按自己的喜好整理的 后面根據自己工作中所需有所增改 AVStream 存儲每一個視...
    石丘閱讀 2,500評論 1 10
  • 文字的美好有時候真的會讓你難以想象,其實很久沒有系統的去讀書了。畢業以后把大量的時間都放到了工作上,讀的書也全部是...
    哼哼細語閱讀 537評論 0 0
  • 一些練習手繪的方法 先練【直線】,畫一根直線,然后再畫一根,要求和第一根重合,然后畫第三根,也要和前面的重合,直到...
    又一個冬季閱讀 1,024評論 0 2