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中非常常见,需要重点掌握。
网友评论