FFmpeg结构体: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;//显示宽高比。

 

posted on 2024-06-13 11:03  粒子少爷  阅读(19)  评论(0编辑  收藏  举报