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持續(xù)的時間饶火,以AVStream->time_base為單位鹏控。
int64_t pos;//表示該數據在媒體流中的字節(jié)偏移量。
AVPacket結構本身只是一個容器肤寝,它使用data成員引用實際的數據緩沖區(qū)当辐。這個緩沖區(qū)通常是由av_new_packet創(chuàng)建的,但也可能由FFmpeg的API創(chuàng)建(如av_read_frame)鲤看。當某個AVPacket結構的數據緩沖區(qū)不再被使用時缘揪,要需要通過調用av_free_packet釋放。
這個結構體在FFmpeg中非常常見刨摩,需要重點掌握寺晌。