概述
AVPacket是一个存储压缩数据的结构体。
在雷神的文章中已经比较清楚的描述了AVPacket,贴上雷神AVPacket的地址:FFMPEG结构体分析:AVPacket
相比于雷神的文章,本文会增加一些AVPacket的函数,下面来看下AVPacket的声明代码:
/**
* This structure stores compressed data. It is typically exported by demuxers
* and then passed as input to decoders, or received as output from encoders and
* then passed to muxers.
*
* For video, it should typically contain one compressed frame. For audio it may
* contain several compressed frames. Encoders are allowed to output empty
* packets, with no compressed data, containing only side data
* (e.g. to update some stream parameters at the end of encoding).
*
* AVPacket is one of the few structs in FFmpeg, whose size is a part of public
* ABI. Thus it may be allocated on stack and no new fields can be added to it
* without libavcodec and libavformat major bump.
*
* The semantics of data ownership depends on the buf field.
* If it is set, the packet data is dynamically allocated and is
* valid indefinitely until a call to av_packet_unref() reduces the
* reference count to 0.
*
* If the buf field is not set av_packet_ref() would make a copy instead
* of increasing the reference count.
*
* The side data is always allocated with av_malloc(), copied by
* av_packet_ref() and freed by av_packet_unref().
*
* @see av_packet_ref
* @see av_packet_unref
*/
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;
这里有一个AVBufferRef *buf;当引用的时候他的计数器会加。
int64_t pts;显示时间戳 一般是用pts * (num/den)
int64_t dts;解码时间戳
uint8_t *data;这里就是存储压缩编码的数据
int size;表示上面data的大小
int stream_index; 存储的音视频索引,一般0是视频1是音频
雷神的博客到这里就结束了,其中我在上面加了一个AVBufferRef *buf;
接下来,关于AVPacket有几个函数介绍一下:
AVPacket *av_packet_alloc(void);//创建并初始化
AVPacket *av_packet_clone(const AVPacket *src);//创建并用计数
int av_packet_ref(AVPacket *dst,const AVPacket *src);
av_packet_unref(AVPacket *pkt);//一个是加引用,一个是解除引用
void av_packet_free(AVPacket **pkt);//清空对象并减引用计数
void av_init_packet(AVPacket *pkt);//初始化
int av_packet_from_data(AVPacket *pkt,uint8_t *data,int size);//如果要分配实际空间
//还有一个之前的函数,现在已经不使用了
int av_copy_packet(AVPacket *dst,const AVPacket *src);
本文内容就到这里,有需要交流的欢迎留言。
最后
以上就是怕孤单水壶为你收集整理的FFmpeg结构体:AVPacket的全部内容,希望文章能够帮你解决FFmpeg结构体:AVPacket所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复