ffmpeg重要结构体之AVStream_面海烹鲜的博客-程序员ITS304

技术标签: 视频  ffmpeg  解码  

ffmpeg重要结构体之AVFrame

ffmpeg重要结构体之AVFormatContext

ffmpeg重要结构体之AVCodecContext

ffmpeg重要结构体之AVCodec

ffmpeg重要结构体之AVIOContext

ffmpeg重要结构体之AVStream

ffmpeg重要结构体之AVPacket


AVStream结构体存储有关流(视频流或者音频流)的信息。此定义位于libavformat/avformat.h中。

typedef struct AVStream {
    int index;    /**< stream index in AVFormatContext */
    /**
     * Format-specific stream ID.
     * decoding: set by libavformat
     * encoding: set by the user, replaced by libavformat if left unset
     */
    int id;
    /**
     * Codec context associated with this stream. Allocated and freed by
     * libavformat.
     *
     * - decoding: The demuxer exports codec information stored in the headers
     *             here.
     * - encoding: The user sets codec information, the muxer writes it to the
     *             output. Mandatory fields as specified in AVCodecContext
     *             documentation must be set even if this AVCodecContext is
     *             not actually used for encoding.
     */
    AVCodecContext *codec;
    void *priv_data;

#if FF_API_LAVF_FRAC
    /**
     * @deprecated this field is unused
     */
    attribute_deprecated
    struct AVFrac pts;
#endif

    /**
     * This is the fundamental unit of time (in seconds) in terms
     * of which frame timestamps are represented.
     *
     * decoding: set by libavformat
     * encoding: May be set by the caller before avformat_write_header() to
     *           provide a hint to the muxer about the desired timebase. In
     *           avformat_write_header(), the muxer will overwrite this field
     *           with the timebase that will actually be used for the timestamps
     *           written into the file (which may or may not be related to the
     *           user-provided one, depending on the format).
     */
    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
     *
     * - demuxing: May be set by libavformat when creating the stream or in
     *             avformat_find_stream_info().
     * - muxing: May be set by the caller before avformat_write_header().
     */
    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;

    /**
     * An array of side data that applies to the whole stream (i.e. the
     * container does not allow it to change between packets).
     *
     * There may be no overlap between the side data in this array and side data
     * in the packets. I.e. a given side data is either exported by the muxer
     * (demuxing) / set by the caller (muxing) in this array, then it never
     * appears in the packets, or the side data is exported / sent through
     * the packets (always in the first packet where the value becomes known or
     * changes), then it does not appear in this array.
     *
     * - demuxing: Set by libavformat when the stream is created.
     * - muxing: May be set by the caller before avformat_write_header().
     *
     * Freed by libavformat in avformat_free_context().
     *
     * @see av_format_inject_global_side_data()
     */
    AVPacketSideData *side_data;
    /**
     * The number of elements in the AVStream.side_data array.
     */
    int            nb_side_data;

    /**
     * Flags for the user to detect events happening on the stream. Flags must
     * be cleared by the user once the event has been handled.
     * A combination of AVSTREAM_EVENT_FLAG_*.
     */
    int event_flags;
#define AVSTREAM_EVENT_FLAG_METADATA_UPDATED 0x0001 ///< The call resulted in updated metadata.

    /*****************************************************************
     * 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 (30*12+7+6)
    struct {
        int64_t last_dts;
        int64_t duration_gcd;
        int duration_count;
        int64_t rfps_duration_sum;
        double (*duration_error)[2][MAX_STD_TIMEBASES];
        int64_t codec_info_duration;
        int64_t codec_info_duration_fields;

        /**
         * 0  -> decoder has not been searched for yet.
         * >0 -> decoder found
         * <0 -> decoder with codec_id == -found_decoder has not been found
         */
        int found_decoder;

        int64_t last_duration;

        /**
         * Those are used for average framerate estimation.
         */
        int64_t fps_first_dts;
        int     fps_first_dts_idx;
        int64_t fps_last_dts;
        int     fps_last_dts_idx;

    } *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 first_dts;
    int64_t cur_dts;
    int64_t last_IP_pts;
    int last_IP_duration;

    /**
     * Number of packets to buffer for codec probing
     */
    int probe_packets;

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

    /* 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;

    /**
     * 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.
     *
     * Code outside avformat should access this field using:
     * av_stream_get/set_r_frame_rate(stream)
     */
    AVRational r_frame_rate;

    /**
     * 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;

    /**
     * stream probing state
     * -1   -> probing finished
     *  0   -> no probing requested
     * rest -> perform probing with request_probe being the minimum score to accept.
     * NOT PART OF PUBLIC API
     */
    int request_probe;
    /**
     * Indicates that everything up to the next keyframe
     * should be discarded.
     */
    int skip_to_keyframe;

    /**
     * Number of samples to skip at the start of the frame decoded from the next packet.
     */
    int skip_samples;

    /**
     * If not 0, the number of samples that should be skipped from the start of
     * the stream (the samples are removed from packets with pts==0, which also
     * assumes negative timestamps do not happen).
     * Intended for use with formats such as mp3 with ad-hoc gapless audio
     * support.
     */
    int64_t start_skip_samples;

    /**
     * If not 0, the first audio sample that should be discarded from the stream.
     * This is broken by design (needs global sample count), but can't be
     * avoided for broken by design formats such as mp3 with ad-hoc gapless
     * audio support.
     */
    int64_t first_discard_sample;

    /**
     * The sample after last sample that is intended to be discarded after
     * first_discard_sample. Works on frame boundaries only. Used to prevent
     * early EOF if the gapless info is broken (considered concatenated mp3s).
     */
    int64_t last_discard_sample;

    /**
     * Number of internally decoded frames, used internally in libavformat, do not access
     * its lifetime differs from info which is why it is not in that structure.
     */
    int nb_decoded_frames;

    /**
     * Timestamp offset added to timestamps before muxing
     * NOT PART OF PUBLIC API
     */
    int64_t mux_ts_offset;

    /**
     * Internal data to check for wrapping of the time stamp
     */
    int64_t pts_wrap_reference;

    /**
     * Options for behavior, when a wrap is detected.
     *
     * Defined by AV_PTS_WRAP_ values.
     *
     * If correction is enabled, there are two possibilities:
     * If the first time stamp is near the wrap point, the wrap offset
     * will be subtracted, which will create negative time stamps.
     * Otherwise the offset will be added.
     */
    int pts_wrap_behavior;

    /**
     * Internal data to prevent doing update_initial_durations() twice
     */
    int update_initial_durations_done;

    /**
     * Internal data to generate dts from pts
     */
    int64_t pts_reorder_error[MAX_REORDER_DELAY+1];
    uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1];

    /**
     * Internal data to analyze DTS and detect faulty mpeg streams
     */
    int64_t last_dts_for_order_check;
    uint8_t dts_ordered;
    uint8_t dts_misordered;

    /**
     * Internal data to inject global side data
     */
    int inject_global_side_data;

    /**
     * String containing paris of key and values describing recommended encoder configuration.
     * Paris are separated by ','.
     * Keys are separated from values by '='.
     */
    char *recommended_encoder_configuration;

    /**
     * display aspect ratio (0 if unknown)
     * - encoding: unused
     * - decoding: Set by libavformat to calculate sample_aspect_ratio internally
     */
    AVRational display_aspect_ratio;

    struct FFFrac *priv_pts;
} AVStream;
有关视频解码的主要成员:

AVRational time_base:时间基本单位的分数表示。如图:


time_base = 1/90000(单位:秒).

time_base的用法:举个例子,在AVFrame中有成员pkt_pts  // PTS copied from the AVPacket that was decoded to produce this frame.即从packet包中解出的pts。(见ffmpeg重要结构体之AVFrame

某一帧图像的pkt_pts为2965399930,下一帧图像的pkt_pts为2965403530,两者之差为3600,其单位就是time_base。

3600*(1/90000) = 0.04秒,正好是一个帧率为25的视频的两帧间的时间间隔。

AVRational avg_frame_rate:帧率的分数表示。比如24000/1001.

其他相关的成员仍需要进一步研究

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_32430349/article/details/49818095

智能推荐

IDEA报错:log4j:WARN No appenders could be found for logger (org.mybatis.generator.internal.db.Databas)_cici未完成的拼图的博客-程序员ITS304

报错信息:log4j:WARN No appenders could be found for logger (org.mybatis.generator.internal.db.DatabaseIntrospector).log4j:WARN Please initialize the log4j system properly.log4j:WARN See http://logging...

Vue 模板是如何编译的_前端同学的博客-程序员ITS304_vue模板编译

认识模板编译我们知道 &lt;template&gt;&lt;/template&gt; 这个是模板,不是真实的 HTML,浏览器是不认识模板的,所以我们需要把它编译成浏览器认识的原生的 HTML这一块的主要流程就是提取出模板中的原生 HTML 和非原生 HTML,比如绑定的属性、事件、指令等等经过一些处理生成 render 函数render 函数再将模板内容生成对应的 vnode再经过 patch 过程( Diff )得到要渲染到视图中的 vnode最后根据 vnode 创建真实的 DOM

sota结果是什么意思_只有达到SOTA的方法才能发文章吗_weixin_39743369的博客-程序员ITS304

最近关注了一个问题:只有达到 state of the art 精度的方法才能发文章吗?得赞同最多的回答分享了ICML审稿人的话,说的非常好:The academic is not an army race. It does not really matter how fancy the model is. It does not really matter whether the model c...

浙江工商大学和杭电计算机哪个好,浙江工业大学、杭电、浙江理工大学、浙江工商大学哪所值得报考?..._Clarlie的博客-程序员ITS304

有人问,浙江工业大学、杭州电子科技大学、浙江工商大学和浙江理工大学,哪个学校更值得选择?这4所大学都是浙江省的普通高校。不过,这几所大学的实力并不太弱,也许要好于部分211大学。原因是,浙江的高等教育跟它的教育强省地位不符合。浙江只有浙大一所985兼211大学。在双一流名单里,也只有3所学校上榜,除了浙大,还有宁波大学和中国美术学院。中国美院实力很强,但属于艺术类学校,对大部分考生不适合。综合性院...

[SPI]SPI协议详解_weixin_30539625的博客-程序员ITS304

转自:https://my.oschina.net/freeblues/blog/674001.SPI协议简介1.1.SPI协议概括  SPI,是英语Serial Peripheral interface的缩写,顾名思义就是串行外围设备接口。是Motorola首先在其MC68HCXX系列处理器上定义的。SPI接口主要应用在 EEPROM,FLASH,实时时钟,AD转换器,还有数字信...

JDK、JRE和JVM之间的关系_Sun-yz的博客-程序员ITS304_jdk jre jvm三者之间的关系

作为一个Java开发者,只会用Java,却不知什么是JDK、JRE和JVM是什么,以及他们之间有什么联系。本文总结了JDK,JRE,JVM三者的关系与区别。JDK、JRE和JVM之间的关系一、JDK二、JRE三、JVM四、三者的联系五、三者的区别六、总结一、JDKJDK是Java开发工具包,其中包括编译工具(javac.exe)打包工具(jar.exe)等,也包括JRE。在JDK的安装目录下有一个jre目录,里面有两个文件夹bin和lib,在这里可以认为bin里的就是jvm,lib中则是jvm工.

随便推点

Android中级:代码混淆与反编译_AndroidCQC的博客-程序员ITS304

参考: Android Studio混淆模板及常用第三方混淆(看了都说好) 混淆 混淆简介-dontwarn com.baidu. 忽略com.baidu下的所有warning混淆模板混淆就是把module的build.gradle中的minifyEnabled改为true,同时需要修改module的prodeard-rules.pro############################

tensorflow session的关闭问题_ok_kakaka的博客-程序员ITS304_tensorflow 关闭session

在使用tensorflow时,需要在不同的函数中,调用同一个session,所以需要session在第一次使用后保持开启。在网上搜索到的教程中,一般是说:调用tf.Session.close方法,或使用session作为上下文管理器,都可以关闭session。所以我理解的意思是,如果用方法1打开session,那么session就不会自动关闭。但事实并不是这样的,即使使用方法1,session使...

python调用scikit-fuzzy实现简单模糊逻辑控制的说明(一)_sweet_Chanyelo的博客-程序员ITS304_模糊逻辑python实现

一直想要实现用python编写一个模糊控制器,自己尝试了很久发现还(zhu)是(yao)很 (shi) 难(lan),不过终于找到了可以直接调用的现成的模糊控制库scikit-fuzzy,看起来和scikit-learn 很像,也看了几个大佬的博客,发现功能还是比较简单,能处理的问题也十分有限。1.案例说明这里同样采用一个大佬常用来说明的案例进行说明,其中由2个输入,1个输出,每个输入设置3个参考值,因此共9条规则,相应的规则矩阵如下表输入参考值NMPNN`MMM

什么是WAP网关? _iteye_5823的博客-程序员ITS304

1. 什么是WAP网关?WAP网关是一个软件。它连接Internet或者Intranet,使得WAP电话可以来访问其中的资源。有些网关可能具有将HTML文件转换为WML页面的功能。WAP网关在WAP设备与Web服务器之间的连接中有好多功能。这些功能基本上是:将标记语言(WML)从文本转换成可以被WAP设备读懂的编码(二进制/压缩的)格式; 将WAP设备的请求转换成Web中的HT...

SpringBoot接口返回图片_前端的哭的博客-程序员ITS304_springboot 返回图片

使用 ResponseEntity 返回结果,设置HttpHeader中的content-type,如:image/[email protected](method = RequestMethod.GET)public ResponseEntity getFile(@RequestParam long id) { Result result = fileService.getFile(id); if (result.getCode() == 1) { MediaTy..

Stata:聚类标准误的纠结_arlionn的博客-程序员ITS304_聚类标准误

全文阅读:Stata:聚类标准误的纠结| 连享会主页目录1.背景介绍 1.1 聚类还是不聚类,这是一个问题 1.2 如果本应该聚类,但没有聚类会怎样 2.实操准备 2.1 模拟设置 2.2 主要程序 3. 主要结果 3.1 不同情况下的结果对比 3.2 基本结论 4.参考资料 5. 相关推文 本文主要编译自下文:Source:To cluster or not to cluster 1.背景介绍1.1 聚类还是不聚类,这是一个问题.