FFmpeg 结构体学习(二): AVStream 分析

在上文FFmpeg 结构体学习(一): AVFormatContext 分析我们学习了AVFormatContext结构体的相关内容。本文,我们将讲述一下AVStream。

AVStream是存储每一个视频/音频流信息的结构体。下面我们来分析一下该结构体里重要变量的含义和作用。

一、源码整理

首先我们先看一下结构体AVStream的定义的结构体源码(位于libavformat/avformat.h):

/**
 * Stream structure.
 * New fields can be added to the end with minor version bumps.
 * Removal, reordering and changes to existing fields require a major
 * version bump.
 * sizeof(AVStream) must not be used outside libav*.
 */
typedef struct AVStream {
    int index;    /**< stream index in AVFormatContext */
    /**
     * Format-specific stream ID.
     * decoding: set by libavformat
     * encoding: set by the user
     */
    int id;
    AVCodecContext *codec; /**< codec context */
    /**
     * Real base framerate of the stream.
     * This is the lowest framerate with which all timestamps can be
     * represented accurately (it is the least common multiple of all
     * framerates in the stream). Note, this value is just a guess!
     * For example, if the time base is 1/90000 and all frames have either
     * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
     */
    AVRational r_frame_rate;
    void *priv_data;

    /**
     * encoding: pts generation when outputting stream
     */
    struct AVFrac pts;

    /**
     * This is the fundamental unit of time (in seconds) in terms
     * of which frame timestamps are represented. For fixed-fps content,
     * time base should be 1/framerate and timestamp increments should be 1.
     * decoding: set by libavformat
     * encoding: set by libavformat in av_write_header
     */
    AVRational time_base;

    /**
     * Decoding: pts of the first frame of the stream in presentation order, in stream time base.
     * Only set this if you are absolutely 100% sure that the value you set
     * it to really is the pts of the first frame.
     * This may be undefined (AV_NOPTS_VALUE).
     * @note The ASF header does NOT contain a correct start_time the ASF
     * demuxer must NOT set this.
     */
    int64_t start_time;

    /**
     * Decoding: duration of the stream, in stream time base.
     * If a source file does not specify a duration, but does specify
     * a bitrate, this value will be estimated from bitrate and file size.
     */
    int64_t duration;

    int64_t nb_frames;                 ///< number of frames in this stream if known or 0

    int disposition; /**< AV_DISPOSITION_* bit field */

    enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.

    /**
     * sample aspect ratio (0 if unknown)
     * - encoding: Set by user.
     * - decoding: Set by libavformat.
     */
    AVRational sample_aspect_ratio;

    AVDictionary *metadata;

    /**
     * Average framerate
     */
    AVRational avg_frame_rate;

    /**
     * For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet
     * will contain the attached picture.
     *
     * decoding: set by libavformat, must not be modified by the caller.
     * encoding: unused
     */
    AVPacket attached_pic;

    /*****************************************************************
     * All fields below this line are not part of the public API. They
     * may not be used outside of libavformat and can be changed and
     * removed at will.
     * New public fields should be added right above.
     *****************************************************************
     */

    /**
     * Stream information used internally by av_find_stream_info()
     */
#define MAX_STD_TIMEBASES (60*12+5)
    struct {
        int64_t last_dts;
        int64_t duration_gcd;
        int duration_count;
        double duration_error[2][2][MAX_STD_TIMEBASES];
        int64_t codec_info_duration;
        int nb_decoded_frames;
        int found_decoder;
    } *info;

    int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */

    // Timestamp generation support:
    /**
     * Timestamp corresponding to the last dts sync point.
     *
     * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
     * a DTS is received from the underlying container. Otherwise set to
     * AV_NOPTS_VALUE by default.
     */
    int64_t reference_dts;
    int64_t first_dts;
    int64_t cur_dts;
    int64_t last_IP_pts;
    int last_IP_duration;

    /**
     * Number of packets to buffer for codec probing
     */
#define MAX_PROBE_PACKETS 2500
    int probe_packets;

    /**
     * Number of frames that have been demuxed during av_find_stream_info()
     */
    int codec_info_nb_frames;

    /**
     * Stream Identifier
     * This is the MPEG-TS stream identifier +1
     * 0 means unknown
     */
    int stream_identifier;

    int64_t interleaver_chunk_size;
    int64_t interleaver_chunk_duration;

    /* av_read_frame() support */
    enum AVStreamParseType need_parsing;
    struct AVCodecParserContext *parser;

    /**
     * last packet in packet_buffer for this stream when muxing.
     */
    struct AVPacketList *last_in_packet_buffer;
    AVProbeData probe_data;
#define MAX_REORDER_DELAY 16
    int64_t pts_buffer[MAX_REORDER_DELAY+1];

    AVIndexEntry *index_entries; /**< Only used if the format does not
                                    support seeking natively. */
    int nb_index_entries;
    unsigned int index_entries_allocated_size;

    /**
     * flag to indicate that probing is requested
     * NOT PART OF PUBLIC API
     */
    int request_probe;
} AVStream;

二、AVStream 重点字段

nt index:标识该视频/音频流

AVCodecContext *codec:指向该视频/音频流的AVCodecContext(它们是一一对应的关系)

AVRational time_base:时基。通过该值可以把PTS,DTS转化为真正的时间。FFMPEG其他结构体中也有这个字段,但是根据我的经验,只有AVStream中的time_base是可用的。PTS*time_base=真正的时间

int64_t duration:该视频/音频流长度

AVDictionary *metadata:元数据信息

AVRational avg_frame_rate:帧率(注:对视频来说,这个挺重要的)

AVPacket attached_pic:附带的图片。比如说一些MP3,AAC音频文件附带的专辑封面。

原文地址:https://www.cnblogs.com/renhui/p/9469856.html

时间: 2024-10-11 10:02:17

FFmpeg 结构体学习(二): AVStream 分析的相关文章

FFmpeg 结构体学习(五): AVCodec 分析

在上文FFmpeg 结构体学习(四): AVFrame 分析我们学习了AVStream结构体的相关内容.本文,我们将讲述一下AVCodec. AVCodec是存储编解码器信息的结构体.下面我们来分析一下该结构体里重要变量的含义和作用. 一.源码整理 首先我们先看一下结构体AVFrame的定义的结构体源码(位于libavcodec/avcodec.h): /* 雷霄骅 * 中国传媒大学/数字电视技术 * [email protected] * */ /** * AVCodec. */ typede

FFmpeg 结构体学习(七): AVIOContext 分析

在上文FFmpeg 结构体学习(六): AVCodecContext 分析我们学习了AVCodec结构体的相关内容.本文,我们将讲述一下AVIOContext. AVIOContext是FFMPEG管理输入输出数据的结构体.下面我们来分析一下该结构体里重要变量的含义和作用. 一.源码整理 首先我们先看一下结构体AVIOContext的定义的结构体源码(位于libavformat/avio.h): /** * Bytestream IO Context. * New fields can be a

结构体学习笔记

以下记载了在初学结构体时犯下的一些错误. 先来一些杂识 struct f { string name; }; struct students { int num; string name; students *next; students friends; // f fri; }; void main() { students boy[40]; students polyy,*li = &polyy; polyy.num; polyy.name; polyy.friends.name; poly

ffmpeg结构体SpecifierOpt说明文档

FFmpeg是一个开源免费跨平台的视频和音频流方案,属于自由软件,采用LGPL或GPL许可证(依据你选择的组件).它提供了录制.转换以及流化音视频的完整解决方案.它包含了非常先进的音频/视频编解码库libavcodec,为了保证高可移植性和编解码质量,libavcodec里很多codec都是从头开发的.FFmpeg具体介绍见:百度百科.FFmpeg官方主页:FFmpeg.org. 这里面涉及到一个重要的结构体:SpecifierOpt.很遗憾,除了官方文档,我没有找到很有价值的分析文章,如果各位

FFmpeg结构体彻底分析——AVCodecContext

/** * main external API structure. * New fields can be added to the end with minor version bumps. * Removal, reordering and changes to existing fields require a major * version bump. * Please use AVOptions (av_opt* / av_set/get*()) to access these fi

FFMPEG结构体分析:AVFrame(解码后的数据)

https://blog.csdn.net/jxcr1984/article/details/52766524 本文转自: http://blog.csdn.net/leixiaohua1020/article/details/14214577 /*   *雷霄骅   *[email protected]   *中国传媒大学/数字电视技术   */   /**   * Audio Video Frame.   * New fields can be added to the end of AVF

关于结构体地址与结构体指针的一些分析

 当我在学习C语言的链表实现时,遇到了一些问题,通常链表的表头是通过结构体创建的,而表头中包含所需要指向的第一个节点与整个链表长度等信息,对于在表头中所存储的地址信息感到一点疑惑.如一下创建的一个单向链表: typedef struct _tag_LinkListNode LinkListNode; //结点取别名 struct _tag_LinkListNode { LinkListNode* next; }; // 结点指针域定义 typedef struct _tag_LinkList {

结构体学习心得

结构体 1.简单认识结构体 #include<stdio.h> /*struct tag(member list)(varible list)*/ 成员列表     变量列表 struct stu { char name[20]; int age; char sex[5]; char tele[12]; char addr[30]; }; int main() { struct stu stu2; struct stu arr[10]; return 0; } 2.结构体的重命名 ①.type

C++/C#结构体转化-二维数组-bytes To Strings

C++结构体 typedef struct VidyoClientRequestGetWindowsAndDesktops_ { /*! The number of application windows currently open */ VidyoSizeT numApplicationWindows; /*! List of open application window names (UTF-8) (Localized) */ char appWindowName[MAX_NUM_APP