FFmpeg AVPacket

AVPacket注解

  • AVPacket
    是二个结构体,存款和储蓄压缩数量。可看成编码器的输出,解码器的输入。
  • 对此 Video 一般包涵1个压缩帧,对于 奥迪(Audi)o 也许包涵多个压缩帧。
  • 编码器允许输出空
    packets,没有包括压缩数量,仅包蕴附加数据,比如在编码结尾更新参数。
  • AVPackets 是 FFmpeg 中为数不多结构体,它的size的国有 ABI
    的一局地,只好被 libavcodec 和 libavformat 在栈上分配。

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 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().

AVPacket注解

  • AVPacket
    是3个结构体,存款和储蓄压缩数量。可用作编码器的输出,解码器的输入。
  • 对此 Video 一般包蕴三个压缩帧,对于 奥迪o 或许包涵两个压缩帧。
  • 编码器允许输出空
    packets,没有包括压缩数量,仅包罗附加数据,比如在编码结尾更新参数。
  • AVPackets 是 FFmpeg 中为数不多结构体,它的size的国有 ABI
    的一片段,只可以被 libavcodec 和 libavformat 在栈上分配。

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 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().

AVPacket字段

  • AVBufferRef *buf
    指向packet数据存款和储蓄buffer的引用计数,为NULL,packet没有引用计数
  • int64_t pts
    压缩数测量身体现时间戳,度量解码后的摄像帧何时被显示出来
  • int64_t dts 压缩数量解码时间戳
  • uint8_t *data 压缩数量
  • int size 压缩数量大小
  • int stream_index 区分媒体流,比如音频,录制,字幕等
  • int flags 表示域,个中1意味该数量是关键帧,AV_PKT_FLAG_KEY 0x0001
    关键帧
  • AVPacketSideData *side_data 附加数据
  • int side_data_elems 附加数据大小
  • int64_t duration 压缩数量时长
  • int64_t pos 压缩数量在传播媒介流中的偏移量

pts:压缩数测量身体现时间戳。相比根本的数额,在做seek和播发进度的时候都要用到它,pts只是一个数目,对应于AVStream->time_base,要根据time_base才能转换为具体的小时,音频和摄像一般有不一样的time_base,所以在做音摄像同步一定要做转换,不能够直接拿pts做

AVPacket字段

  • AVBufferRef *buf
    指向packet数据存款和储蓄buffer的引用计数,为NULL,packet没有引用计数
  • int64_t pts
    压缩数量展现时间戳,衡量解码后的摄像帧哪一天被显示出来
  • int64_t dts 压缩数量解码时间戳
  • uint8_t *data 压缩数量
  • int size 压缩数量大小
  • int stream_index 区分媒体流,比如音频,录像,字幕等
  • int flags 表示域,在那之中1代表该数量是关键帧,AV_PKT_FLAG_KEY 0x0001
    关键帧
  • AVPacketSideData *side_data 附加数据
  • int side_data_elems 附加数据大小
  • int64_t duration 压缩数量时长
  • int64_t pos 压缩数量在媒体流中的偏移量

pts:压缩数量展现时间戳。比较首要的多少,在做seek和播音进程的时候都要用到它,pts只是三个数码,对应于AVStream->time_base,要根据time_base才能更换为切实的岁月,音频和录像一般有两样的time_base,所以在做音录制同步一定要做转换,不可能向来拿pts做

AVPacket定义

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;

AVPacket定义

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;

相关文章