ffmpeg结构体学习:avstream分析(代码片段)

renhui renhui     2022-12-22     728

关键词:

在上文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;
View Code

二、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音频文件附带的专辑封面。

 


ffmpeg结构体学习:aviocontext分析(代码片段)

在上文FFmpeg结构体学习(六):AVCodecContext分析我们学习了AVCodec结构体的相关内容。本文,我们将讲述一下AVIOContext。AVIOContext是FFMPEG管理输入输出数据的结构体。下面我们来分析一下该结构体里重要变量的含义和作用。一、源码整... 查看详情

ffmpeg结构体学习:avformatcontext分析(代码片段)

前言统领全局的基本结构体,包含码流参数较多。它的源码位于libavformat/avformat.h。源码/***FormatI/Ocontext.I/O格式上下文*sizeof(AVFormatContext)mustnotbeusedoutsidelibav*,use*avformat_alloc_context()tocreateanAVFormatContext.**FieldscanbeaccessedthroughAVOption... 查看详情

音视频开发之旅(61)-分析ffmpeg(解码部分的)常用结构体(代码片段)

上一篇我们分析了解封装部分的常用结构体,这篇我们来学习分析解码部分的常用结构体。目录断点分析ffplay解码流程及关键结构体(解码部分)常用结构体以及之间的关系分析资料收获一、断点分析ffplay解码流程及... 查看详情

ffmpeg结构体分析:avcodeccontext(代码片段)

...列的结构体的分析的文章,在这里列一个列表:FFMPEG结构体分析:AVFrameFFMPEG结构体分析:AVFormatContextFFMPEG结构体分析:AVCodecContextFFMPEG结构体分析:AVIOContextFFMPEG结构体分析:AVCodecFFMPEG结构体分析:... 查看详情

音视频学习一——ffmpeg封装(代码片段)

系列文章目录文章目录系列文章目录前言一、FFmpeg结构体和函数简述1.这里简单表明结构体的作用:2.FFmpeg函数简介二、视视频解码转码流程三、FFmpeg封装(仅针对于普通FFmpeg简单的封装和实现)1.FFmpeg类的封装2.FFmpeg... 查看详情

ffmpeg关键结构体之间的关系

...sp;      解码(h264,mpeg2,aac,mp3)每个AVStream存储一个视频/音频流的相关数据;每个AVStream对应一个AVCodecContext,存储该视频/音频流使用解码方式的相关数据;每个AVCodecContext中对应一个AVCodec,包含该视频/音频... 查看详情

音视频开发之旅(61)-分析ffmpeg(解码部分的)常用结构体(代码片段)

上一篇我们分析了解封装部分的常用结构体,这篇我们来学习分析解码部分的常用结构体。目录断点分析ffplay解码流程及关键结构体(解码部分)常用结构体以及之间的关系分析资料收获一、断点分析ffplay解码流程及... 查看详情

ffmpeg学习代码结构分析

libavformat下的hls.c和mpegts.c实际上是同一个级别的,同属于demuxer。只不过实际使用的hls协议是先解协议(hls.c)后解封装(mpegts.c),这里的协议和封装都是demuxer。 查看详情

ffmpeg源码简单分析:结构体成员管理系统-avoption

=====================================================FFmpeg的库函数源码分析文章列表:【架构图】FFmpeg源码结构图-解码FFmpeg源码结构图-编码【通用】FFmpeg源码简单分析:av_register_all()FFmpeg源码简单分析:avcodec_register_all()FFmpeg源码简单分析... 查看详情

音视频开发之旅(60)-调试分析ffmpeg(解封装部分的)常用结构体(代码片段)

...调试,对我们梳理流程排查问题十分重要,可以ffmpeg的调试可以在XCode、VScode以及QT等ide上进行方便的调试分析。本篇我们以XCode为例来先介绍下ffplay的断点调试,以ffmpe 查看详情

ffmpeg3.3新版本avstream的封装流参数由codec替换codecpar(解码)

ffmpeg新版本中(封装流)AVStream的codec参数要被codecpar参数所替代,这样替代我们要注意什么,为什么要替代,我们先来看下ffmpeg的代码。代码分析和新参数优势typedef struct AVStream {#if FF_API_LAVF_AVCTX/*** @deprecated&nb... 查看详情

ffmpeg:avpacket结构体分析(代码片段)

AVPacket是FFmpeg中很重要的一个数据结构,它保存了解封装之后,解码之前的数据(注意:仍然是压缩后的数据)和关于这些数据的一些附加信息,如显示时间戳(pts)、解码时间戳(dts)、数据时长,所在媒体流的索引等。对于... 查看详情

ffmpeg实战系列——001

...的理解,新增了对每种数据结构的详细剖析! 开始玩ffmpeg之前,先把ffmpeg中常见的数据结构以及他们的之间的关系了解下,这是基础,非常重要!FFMPEG结构体分析:AVFrameFFMPEG结构体分析:AVFormatContextFFMPEG结构体分析:AVCodecC... 查看详情

结构体avformatcontext结构体分析(代码片段)

...频流、视频流、字幕流等。该结构体的使用,贯穿了ffmpeg使用的整个流程AVFormatContext结构表示程序运行的 查看详情

音视频开发之旅(60)-调试分析ffmpeg(解封装部分的)常用结构体(代码片段)

...调试,对我们梳理流程排查问题十分重要,可以ffmpeg的调试可以在XCode、VScode以及QT等ide上进行方便的调试分析。本篇我们以XCode为例来先介绍下ffplay的断点调试,以ffmpeg4.4版本来进行分析。一、ffplay的断点调试首先下... 查看详情

音视频开发之旅(60)-调试分析ffmpeg(解封装部分的)常用结构体(代码片段)

...调试,对我们梳理流程排查问题十分重要,可以ffmpeg的调试可以在XCode、VScode以及QT等ide上进行方便的调试分析。本篇我们以XCode为例来先介绍下ffplay的断点调试,以ffmpeg4.4版本来进行分析。一、ffplay的断点调试首先下... 查看详情

ffmpeg的常见结构体(代码片段)

小程之前介绍过FFmpeg的帧的结构(AVPacket跟AVFrame),帧会在一些流程中使用到。除了帧结构,FFmpeg还有其它一些结构会在流程中使用到。FFmpeg还有哪些常见的结构呢?先来看一下这个截图:这张图中的主角,是AVFormatContext。AVForm... 查看详情

ffmpeg的avcodeccontext结构体详解(代码片段)

        AVCodecContext是FFmpeg使用过程中比较重要的结构体,该结构体位于avcodec.h文件中,AVCodecContext结构表示程序运行的当前Codec使用的上下文,记录了所有Codec共有的属性(并且是在程序运行时才能确定其值)和关联... 查看详情