AVPacket是ffmpeg中有关格式信息的结构体,在文件libavcodec/avcodec.h中。
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;
#define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe
#define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted
enum AVSideDataParamChangeFlags {
AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT = 0x0001,
AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002,
AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE = 0x0004,
AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = 0x0008,
};
其中有关视频解码的主要成员:
AVBufferRef *buf:提供给其他参考本packet的地址。
uint8_t *data:一个packet的数据,通常为一个完整的结构,比如对于AVC,就是一个nal(可以是pps或sps或一帧图像)
int size:packet的大小。
int64_t duration:此packet的持续时间,对于一帧数据就是这帧图像的播放时长。
int dts:解码时间戳
int pts:显示时间戳
举个例子,解码某AVC码流,time_base = 1/1000(time_base见ffmpeg重要结构体之AVStream),duration = 42
换算成秒就是42*(1/1000)=0.042秒,相当于24帧每秒。
AVPacket是ffmpeg用于处理格式信息的关键结构体,包括数据指针"data"、大小"size"、解码时间戳"dts"、显示时间戳"pts"等属性。在解码AVC码流中,例如time_base为1/1000,duration为42,对应的播放时长是0.042秒,相当于24fps的2帧。
577

被折叠的 条评论
为什么被折叠?



