美文网首页
FFmpeg结构体-AVPacket

FFmpeg结构体-AVPacket

作者: 张俊峰0613 | 来源:发表于2019-01-02 15:52 被阅读0次

    简介

    AVPacket是FFmpeg中很重要的一个数据结构,在<libavcodec/avcodec.h>中定义,它保存了解复用(demuxer)之后,解码(decode)之前的数据(仍然是压缩后的数据)和关于这些数据的一些附加的信息,如显示时间戳(pts),解码时间戳(dts),数据时长(duration),所在流媒体的索引(stream_index)等等。

    对于视频(Video)来说,AVPacket通常包含一个压缩的Frame;而音频(Audio)则有可能包含多个压缩的Frame。并且,一个packet也有可能是空的,不包含任何压缩数据data,只含有边缘数据side data(side data,容器提供的关于packet的一些附加信息,例如,在编码结束的时候更新一些流的参数,在另外一篇av_read_frame会介绍)

    AVPacket的大小是公共的ABI(Public ABI)一部分,这样的结构体在FFmpeg很少,由此也可见AVPacket的重要性,它可以被分配在栈空间上(可以使用语句AVPacket pkt;在栈空间定义一个Packet),并且除非libavcodec 和libavformat有很大的改动,不然不会在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;       //用来管理data指针引用的数据缓存
        /**
         * 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;    //(int64_t)显示时间,结合AVStream->time_base转换成时间戳
        /**
         * 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;        //(int64_t)解码时间,结合AVStream->time_base转换成时间戳
        uint8_t *data;          //指向保存压缩数据的指针,这就是AVPacket的实际数据。
        int   size;         //(int)data的大小
        int   stream_index;     //(int)packet在stream的index位置
        /**
         * A combination of AV_PKT_FLAG values
         */
        int   flags;        //(int)标示,结合AV_PKT_FLAG使用,其中最低为1表示该数据是一个关键帧。
        /**
         * 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;        //(int)边缘数据元数个数
    
        /**
         * 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)数据的时长,以所属媒体流的时间基准为单位,未知则值为默认值0
    
        int64_t pos;        //(int64_t )数据在流媒体中的位置,未知则值为默认值-1              
        
    #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;
    

    相关文章

      网友评论

          本文标题:FFmpeg结构体-AVPacket

          本文链接:https://www.haomeiwen.com/subject/vcvzlqtx.html