首页 > 其他分享 >FFmpeg结构体:AVStream

FFmpeg结构体:AVStream

时间:2024-06-13 11:13:26浏览次数:21  
标签:FFmpeg stream int data int64 dts pts AVStream 结构

1.描述

AVStream是存储每一个视频/音频流信息的结构体,位于avformat.h文件中。

2.结构体定义

  1 typedef struct AVStream {
  2     int index;    /**< stream index in AVFormatContext */
  3     /**
  4      * Format-specific stream ID.
  5      * decoding: set by libavformat
  6      * encoding: set by the user, replaced by libavformat if left unset
  7      */
  8     int id;
  9 #if FF_API_LAVF_AVCTX
 10     /**
 11      * @deprecated use the codecpar struct instead
 12      */
 13     attribute_deprecated
 14     AVCodecContext *codec;
 15 #endif
 16     void *priv_data;
 17 
 18 #if FF_API_LAVF_FRAC
 19     /**
 20      * @deprecated this field is unused
 21      */
 22     attribute_deprecated
 23     struct AVFrac pts;
 24 #endif
 25 
 26     /**
 27      * This is the fundamental unit of time (in seconds) in terms
 28      * of which frame timestamps are represented.
 29      *
 30      * decoding: set by libavformat
 31      * encoding: May be set by the caller before avformat_write_header() to
 32      *           provide a hint to the muxer about the desired timebase. In
 33      *           avformat_write_header(), the muxer will overwrite this field
 34      *           with the timebase that will actually be used for the timestamps
 35      *           written into the file (which may or may not be related to the
 36      *           user-provided one, depending on the format).
 37      */
 38     AVRational time_base;
 39 
 40     /**
 41      * Decoding: pts of the first frame of the stream in presentation order, in stream time base.
 42      * Only set this if you are absolutely 100% sure that the value you set
 43      * it to really is the pts of the first frame.
 44      * This may be undefined (AV_NOPTS_VALUE).
 45      * @note The ASF header does NOT contain a correct start_time the ASF
 46      * demuxer must NOT set this.
 47      */
 48     int64_t start_time;
 49 
 50     /**
 51      * Decoding: duration of the stream, in stream time base.
 52      * If a source file does not specify a duration, but does specify
 53      * a bitrate, this value will be estimated from bitrate and file size.
 54      */
 55     int64_t duration;
 56 
 57     int64_t nb_frames;                 ///< number of frames in this stream if known or 0
 58 
 59     int disposition; /**< AV_DISPOSITION_* bit field */
 60 
 61     enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
 62 
 63     /**
 64      * sample aspect ratio (0 if unknown)
 65      * - encoding: Set by user.
 66      * - decoding: Set by libavformat.
 67      */
 68     AVRational sample_aspect_ratio;
 69 
 70     AVDictionary *metadata;
 71 
 72     /**
 73      * Average framerate
 74      *
 75      * - demuxing: May be set by libavformat when creating the stream or in
 76      *             avformat_find_stream_info().
 77      * - muxing: May be set by the caller before avformat_write_header().
 78      */
 79     AVRational avg_frame_rate;
 80 
 81     /**
 82      * For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet
 83      * will contain the attached picture.
 84      *
 85      * decoding: set by libavformat, must not be modified by the caller.
 86      * encoding: unused
 87      */
 88     AVPacket attached_pic;
 89 
 90     /**
 91      * An array of side data that applies to the whole stream (i.e. the
 92      * container does not allow it to change between packets).
 93      *
 94      * There may be no overlap between the side data in this array and side data
 95      * in the packets. I.e. a given side data is either exported by the muxer
 96      * (demuxing) / set by the caller (muxing) in this array, then it never
 97      * appears in the packets, or the side data is exported / sent through
 98      * the packets (always in the first packet where the value becomes known or
 99      * changes), then it does not appear in this array.
100      *
101      * - demuxing: Set by libavformat when the stream is created.
102      * - muxing: May be set by the caller before avformat_write_header().
103      *
104      * Freed by libavformat in avformat_free_context().
105      *
106      * @see av_format_inject_global_side_data()
107      */
108     AVPacketSideData *side_data;
109     /**
110      * The number of elements in the AVStream.side_data array.
111      */
112     int            nb_side_data;
113 
114     /**
115      * Flags for the user to detect events happening on the stream. Flags must
116      * be cleared by the user once the event has been handled.
117      * A combination of AVSTREAM_EVENT_FLAG_*.
118      */
119     int event_flags;
120 #define AVSTREAM_EVENT_FLAG_METADATA_UPDATED 0x0001 ///< The call resulted in updated metadata.
121 
122     /*
123      * Codec parameters associated with this stream. Allocated and freed by
124      * libavformat in avformat_new_stream() and avformat_free_context()
125      * respectively.
126      *
127      * - demuxing: filled by libavformat on stream creation or in
128      *             avformat_find_stream_info()
129      * - muxing: filled by the caller before avformat_write_header()
130      */
131     AVCodecParameters *codecpar;
132 
133     /*****************************************************************
134      * All fields below this line are not part of the public API. They
135      * may not be used outside of libavformat and can be changed and
136      * removed at will.
137      * New public fields should be added right above.
138      *****************************************************************
139      */
140 
141     /**
142      * Stream information used internally by av_find_stream_info()
143      */
144 #define MAX_STD_TIMEBASES (30*12+30+3+6)
145     struct {
146         int64_t last_dts;
147         int64_t duration_gcd;
148         int duration_count;
149         int64_t rfps_duration_sum;
150         double (*duration_error)[2][MAX_STD_TIMEBASES];
151         int64_t codec_info_duration;
152         int64_t codec_info_duration_fields;
153 
154         /**
155          * 0  -> decoder has not been searched for yet.
156          * >0 -> decoder found
157          * <0 -> decoder with codec_id == -found_decoder has not been found
158          */
159         int found_decoder;
160 
161         int64_t last_duration;
162 
163         /**
164          * Those are used for average framerate estimation.
165          */
166         int64_t fps_first_dts;
167         int     fps_first_dts_idx;
168         int64_t fps_last_dts;
169         int     fps_last_dts_idx;
170 
171     } *info;
172 
173     int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
174 
175     // Timestamp generation support:
176     /**
177      * Timestamp corresponding to the last dts sync point.
178      *
179      * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
180      * a DTS is received from the underlying container. Otherwise set to
181      * AV_NOPTS_VALUE by default.
182      */
183     int64_t first_dts;
184     int64_t cur_dts;
185     int64_t last_IP_pts;
186     int last_IP_duration;
187 
188     /**
189      * Number of packets to buffer for codec probing
190      */
191     int probe_packets;
192 
193     /**
194      * Number of frames that have been demuxed during av_find_stream_info()
195      */
196     int codec_info_nb_frames;
197 
198     /* av_read_frame() support */
199     enum AVStreamParseType need_parsing;
200     struct AVCodecParserContext *parser;
201 
202     /**
203      * last packet in packet_buffer for this stream when muxing.
204      */
205     struct AVPacketList *last_in_packet_buffer;
206     AVProbeData probe_data;
207 #define MAX_REORDER_DELAY 16
208     int64_t pts_buffer[MAX_REORDER_DELAY+1];
209 
210     AVIndexEntry *index_entries; /**< Only used if the format does not
211                                     support seeking natively. */
212     int nb_index_entries;
213     unsigned int index_entries_allocated_size;
214 
215     /**
216      * Real base framerate of the stream.
217      * This is the lowest framerate with which all timestamps can be
218      * represented accurately (it is the least common multiple of all
219      * framerates in the stream). Note, this value is just a guess!
220      * For example, if the time base is 1/90000 and all frames have either
221      * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
222      *
223      * Code outside avformat should access this field using:
224      * av_stream_get/set_r_frame_rate(stream)
225      */
226     AVRational r_frame_rate;
227 
228     /**
229      * Stream Identifier
230      * This is the MPEG-TS stream identifier +1
231      * 0 means unknown
232      */
233     int stream_identifier;
234 
235     int64_t interleaver_chunk_size;
236     int64_t interleaver_chunk_duration;
237 
238     /**
239      * stream probing state
240      * -1   -> probing finished
241      *  0   -> no probing requested
242      * rest -> perform probing with request_probe being the minimum score to accept.
243      * NOT PART OF PUBLIC API
244      */
245     int request_probe;
246     /**
247      * Indicates that everything up to the next keyframe
248      * should be discarded.
249      */
250     int skip_to_keyframe;
251 
252     /**
253      * Number of samples to skip at the start of the frame decoded from the next packet.
254      */
255     int skip_samples;
256 
257     /**
258      * If not 0, the number of samples that should be skipped from the start of
259      * the stream (the samples are removed from packets with pts==0, which also
260      * assumes negative timestamps do not happen).
261      * Intended for use with formats such as mp3 with ad-hoc gapless audio
262      * support.
263      */
264     int64_t start_skip_samples;
265 
266     /**
267      * If not 0, the first audio sample that should be discarded from the stream.
268      * This is broken by design (needs global sample count), but can't be
269      * avoided for broken by design formats such as mp3 with ad-hoc gapless
270      * audio support.
271      */
272     int64_t first_discard_sample;
273 
274     /**
275      * The sample after last sample that is intended to be discarded after
276      * first_discard_sample. Works on frame boundaries only. Used to prevent
277      * early EOF if the gapless info is broken (considered concatenated mp3s).
278      */
279     int64_t last_discard_sample;
280 
281     /**
282      * Number of internally decoded frames, used internally in libavformat, do not access
283      * its lifetime differs from info which is why it is not in that structure.
284      */
285     int nb_decoded_frames;
286 
287     /**
288      * Timestamp offset added to timestamps before muxing
289      * NOT PART OF PUBLIC API
290      */
291     int64_t mux_ts_offset;
292 
293     /**
294      * Internal data to check for wrapping of the time stamp
295      */
296     int64_t pts_wrap_reference;
297 
298     /**
299      * Options for behavior, when a wrap is detected.
300      *
301      * Defined by AV_PTS_WRAP_ values.
302      *
303      * If correction is enabled, there are two possibilities:
304      * If the first time stamp is near the wrap point, the wrap offset
305      * will be subtracted, which will create negative time stamps.
306      * Otherwise the offset will be added.
307      */
308     int pts_wrap_behavior;
309 
310     /**
311      * Internal data to prevent doing update_initial_durations() twice
312      */
313     int update_initial_durations_done;
314 
315     /**
316      * Internal data to generate dts from pts
317      */
318     int64_t pts_reorder_error[MAX_REORDER_DELAY+1];
319     uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1];
320 
321     /**
322      * Internal data to analyze DTS and detect faulty mpeg streams
323      */
324     int64_t last_dts_for_order_check;
325     uint8_t dts_ordered;
326     uint8_t dts_misordered;
327 
328     /**
329      * Internal data to inject global side data
330      */
331     int inject_global_side_data;
332 
333     /**
334      * String containing paris of key and values describing recommended encoder configuration.
335      * Paris are separated by ','.
336      * Keys are separated from values by '='.
337      */
338     char *recommended_encoder_configuration;
339 
340     /**
341      * display aspect ratio (0 if unknown)
342      * - encoding: unused
343      * - decoding: Set by libavformat to calculate sample_aspect_ratio internally
344      */
345     AVRational display_aspect_ratio;
346 
347     struct FFFrac *priv_pts;
348 
349     /**
350      * An opaque field for libavformat internal usage.
351      * Must not be accessed in any way by callers.
352      */
353     AVStreamInternal *internal;
354 } AVStream;

3.常见变量及其作用

 1 int index; //在AVFormatContext中的索引,这个数字是自动生成的,可以通过这个数字从AVFormatContext::streams表中索引到该流。
 2 int id;//流的标识,依赖于具体的容器格式。解码:由libavformat设置。编码:由用户设置,如果未设置则由libavformat替换。
 3 AVCodecContext *codec;//指向该流对应的AVCodecContext结构,调用avformat_open_input时生成。
 4 AVRational time_base;//这是表示帧时间戳的基本时间单位(以秒为单位)。该流中媒体数据的pts和dts都将以这个时间基准为粒度。
 5 int64_t start_time;//流的起始时间,以流的时间基准为单位。如需设置,100%确保你设置它的值真的是第一帧的pts。
 6 int64_t duration;//解码:流的持续时间。如果源文件未指定持续时间,但指定了比特率,则将根据比特率和文件大小估计该值。
 7 int64_t nb_frames; //此流中的帧数(如果已知)或0。
 8 enum AVDiscard discard;//选择哪些数据包可以随意丢弃,不需要去demux。
 9 AVRational sample_aspect_ratio;//样本长宽比(如果未知,则为0)。
10 AVDictionary *metadata;//元数据信息。
11 AVRational avg_frame_rate;//平均帧速率。解封装:可以在创建流时设置为libavformat,也可以在avformat_find_stream_info()中设置。封装:可以由调用者在avformat_write_header()之前设置。
12 AVPacket attached_pic;//附带的图片。比如说一些MP3,AAC音频文件附带的专辑封面。
13 int probe_packets;//编解码器用于probe的包的个数。
14 int codec_info_nb_frames;//在av_find_stream_info()期间已经解封装的帧数。
15 int request_probe;//流探测状态,1表示探测完成,0表示没有探测请求,rest 执行探测。
16 int skip_to_keyframe;//表示应丢弃直到下一个关键帧的所有内容。
17 int skip_samples;//在从下一个数据包解码的帧开始时要跳过的采样数。
18 int64_t start_skip_samples;//如果不是0,则应该从流的开始跳过的采样的数目。
19 int64_t first_discard_sample;//如果不是0,则应该从流中丢弃第一个音频样本。
20 
21 int64_t pts_reorder_error[MAX_REORDER_DELAY+1];
22 uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1];//内部数据,从pts生成dts。
23 
24 int64_t last_dts_for_order_check;
25 uint8_t dts_ordered;
26 uint8_t dts_misordered;//内部数据,用于分析dts和检测故障mpeg流。
27 AVRational display_aspect_ratio;//显示宽高比。

 

标签:FFmpeg,stream,int,data,int64,dts,pts,AVStream,结构
From: https://www.cnblogs.com/lizishaoye/p/18245493

相关文章

  • 动态选择4种库存更新策略+缓存预热+多级存储结构——应对高并发秒杀情景和其他多种情
    商城整体功能架构图文字分析:活动入口进行风控检测,这个使用独立的服务来实现,风控使用批量提交的形式来实现,直接运用Java线程池来实现,可以提交一个列表来实现批量,可以参考以下的代码创建批量请求并且进行提交:importjava.util.ArrayList;importjava.util.List;publi......
  • 【数据结构】【版本1.0】【线性时代】——顺序表
    快乐的流畅:个人主页个人专栏:《算法神殿》《数据结构世界》《进击的C++》远方有一堆篝火,在为久候之人燃烧!文章目录引言一、顺序表的概念1.1最基础的数据结构:数组1.2数组与顺序表的区别二、静态顺序表三、动态顺序表的模拟实现3.1定义3.2初始化3.3......
  • 数据结构复习笔记5.6:哈夫曼编码树
    1.前导概念1.定义:设有n个权值{w1,w2,…,wn},构造一棵有n个叶子结点的二叉树,每个叶子的权值为wi,则wpl最小的二叉树叫哈夫曼树。例子:2.结点的路径长度:从根结点到该结点的路径上的连接数3.树的路径长度:就是树的每个叶⼦结点的路径⻓度之和4.结点的带权路径⻓度:结点的路径⻓......
  • golang执行语句操作与map结构体变量调用函数
    本文记录利用golang调用exe文件。需要用到包os/exec,本文重点介绍如何利用golang执行带参数的可执行文件以及踩过的坑。首先c:=exec.Command(cmd)语句不会执行cmd命令,而是做好要执行的准备,当接下来调用c.Run()时才会执行cmd命令,注意到此时是会阻塞进程的,等待执行完成才会进行下一......
  • 【文档智能 & RAG】RAG增强之路:增强PDF解析并结构化技术路线方案及思路
    前言现阶段,尽管大模型在生成式问答上取得了很大的成功,但由于大部分的数据都是私有数据,大模型的训练及微调成本非常高,RAG的方式逐渐成为落地应用的一种重要的选择方式。然而,如何准确的对文档进行划分chunks,成为一种挑战,在现实中,大部分的专业文档都是以PDF格式存储,低精度的......
  • 树结构的实现
    树的概念        树是一种非线性的数据结构,它是由n个有限节点组成一个具有层次关系的集合,它看起来像棵树,所以称其为“树”。如下图:     树可以分为根和子树,而子树又可以被分为根和子树,故我们可以用递归对其进行实现。注意:子树之间不能相交树的实现1.顺序......
  • 【FFmpeg】SDL 音视频开发 ② ( SDL 视频显示函数 | 设置渲染器目标纹理 | 设置渲染器
    文章目录一、SDL视频显示函数1、SDL的渲染器和纹理之间的关系2、SDL_SetRenderTarget函数-设置渲染器目标纹理3、SDL_SetRenderDrawColor函数-设置渲染器颜色4、SDL_RenderClear函数-清除渲染器5、SDL_RenderDrawRect函数-渲染器绘制矩形6、SDL_Render......
  • 【Test 66 】 高阶数据结构 二叉搜索树 必会知识点!
    文章目录1.二叉搜索树的概念2.二叉搜索树K模型的代码实现2.1Find()查找的实现2.2Insert()插入的实现2.3InOrder()中序遍历的实现2.4Erase()删除的实现3.二叉搜索树的KV模型4.二叉搜索树的性能分析1.二叉搜索树的概念......
  • 使用Wesky.Net.OpenTools包来快速实现嵌套型结构体数据转换功能
    今天遇到有人提到结构体和byte数组互转的问题,我就顺便拿来水一篇。这是一个冷门的问题,估计使用的人不多。既然有需求,应该就有使用场景,那就顺便整一波。为了达到效果,结构体、复杂结构体嵌套等都能实现转换,我就顺便做了个包更新来提供使用和下面的说明。首先引入nuget包Wesky.Net......
  • 【力扣真题】3.哈希表|算法真题程序设计数据结构考研保研复试机试面试秋招春招蓝桥杯
    242.有效的字母异位词给定两个字符串s和t,编写一个函数来判断t是否是s的字母异位词。示例1:输入:s=“anagram”,t=“nagaram”输出:true示例2:输入:s=“rat”,t=“car”输出:false说明:你可以假设字符串只包含小写字母。力扣题目链接思......