FFmpeg结构体:AVPacket

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 教程一:视频截图(Tutorial 01: Making Screencaps) 首先我们需要了解视频文件的一些基...
    90后的思维阅读 10,273评论 0 3
  • ffmpeg是一个非常有用的命令行程序,它可以用来转码媒体文件。它是领先的多媒体框架FFmpeg的一部分,其有很多...
    城市之光阅读 11,805评论 3 6
  • 本篇博客在雷神的结构体介绍基础上按自己的喜好整理的 后面根据自己工作中所需有所增改 AVStream 存储每一个视...
    石丘阅读 7,257评论 1 10
  • 文字的美好有时候真的会让你难以想象,其实很久没有系统的去读书了。毕业以后把大量的时间都放到了工作上,读的书也全部是...
    哼哼细语阅读 3,471评论 0 0
  • 一些练习手绘的方法 先练【直线】,画一根直线,然后再画一根,要求和第一根重合,然后画第三根,也要和前面的重合,直到...
    又一个冬季阅读 4,601评论 0 2