zoukankan      html  css  js  c++  java
  • ffmpeg各结构体之间关联 ---- AVPacket

    FFMPEG中结构体很多。最关键的结构体可以分成以下几类:

    a)        解协议(http,rtsp,rtmp,mms)

    AVIOContext,URLProtocol,URLContext主要存储视音频使用的协议的类型以及状态。URLProtocol存储输入视音频使用的封装格式。每种协议都对应一个URLProtocol结构。(注意:FFMPEG中文件也被当做一种协议“file”)

    b)        解封装(flv,avi,rmvb,mp4)

    AVFormatContext主要存储视音频封装格式中包含的信息;AVInputFormat存储输入视音频使用的封装格式。每种视音频封装格式都对应一个AVInputFormat 结构。

    c)        解码(h264,mpeg2,aac,mp3)

    每个AVStream存储一个视频/音频流的相关数据;每个AVStream对应一个AVCodecContext,存储该视频/音频流使用解码方式的相关数据;每个AVCodecContext中对应一个AVCodec,包含该视频/音频对应的解码器。每种解码器都对应一个AVCodec结构。

    d) 存数据

    视频的话,每个结构一般是存一帧;音频可能有好几帧

    解码前数据:AVPacket

    解码后数据:AVFrame

    他们之间的对应关系如下所示:

    AVPacket是存储压缩编码数据相关信息的结构体。本文将会详细分析一下该结构体里重要变量的含义和作用。

    首先看一下结构体的定义(位于avcodec.h文件中):

    typedef struct AVPacket {
    /**
    * 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.
    */
    struct {
    uint8_t *data;
    int size;
    enum AVPacketSideDataType type;
    } *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.
    */
    int duration;
    void (*destruct)(struct AVPacket *);
    void *priv;
    int64_t pos; ///< byte position in stream, -1 if unknown

    /**
    * Time difference in AVStream->time_base units from the pts of this
    * packet to the point at which the output from the decoder has converged
    * independent from the availability of previous frames. That is, the
    * frames are virtually identical no matter if decoding started from
    * the very first frame or from this keyframe.
    * Is AV_NOPTS_VALUE if unknown.
    * This field is not the display duration of the current packet.
    * This field has no meaning if the packet does not have AV_PKT_FLAG_KEY
    * set.
    *
    * The purpose of this field is to allow seeking in streams that have no
    * keyframes in the conventional sense. It corresponds to the
    * recovery point SEI in H.264 and match_time_delta in NUT. It is also
    * essential for some types of subtitle streams to ensure that all
    * subtitles are correctly displayed after seeking.
    */
    int64_t convergence_duration;
    } AVPacket;

    uint8_t *data:压缩编码的数据。

    例如对于H.264来说。1个AVPacket的data通常对应一个NAL。

    注意:在这里只是对应,而不是一模一样。他们之间有微小的差别:使用FFMPEG类库分离出多媒体文件中的H.264码流

    因此在使用FFMPEG进行视音频处理的时候,常常可以将得到的AVPacket的data数据直接写成文件,从而得到视音频的码流文件。

    int   size:data的大小

    int64_t pts:显示时间戳

    int64_t dts:解码时间戳

    int   stream_index:标识该AVPacket所属的视频/音频流。

    这个结构体虽然比较简单,但是非常的常用。

    提高技能如同提升自信心。
  • 相关阅读:
    【如何入门ACM】
    HDU
    HDU 6107 Typesetting
    bzoj 3223: Tyvj 1729 文艺平衡树
    51Nod 1781 跑的比谁都快
    51Nod 1331 狭窄的通道
    51Nod 1555 布丁怪
    hihocoder 1035 : 自驾旅行 III
    51Nod 1196 字符串的数量
    51Nod 1530 稳定方块
  • 原文地址:https://www.cnblogs.com/chims-liu-touch/p/14493338.html
Copyright © 2011-2022 走看看