FFmpeg
demux.c
Go to the documentation of this file.
1 /*
2  * Core demuxing component
3  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <stdint.h>
23 
24 #include "config_components.h"
25 
26 #include "libavutil/avassert.h"
27 #include "libavutil/avstring.h"
28 #include "libavutil/dict.h"
29 #include "libavutil/internal.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/mathematics.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/pixfmt.h"
35 #include "libavutil/time.h"
36 #include "libavutil/timestamp.h"
37 
38 #include "libavcodec/avcodec.h"
39 #include "libavcodec/bsf.h"
40 #include "libavcodec/codec_desc.h"
41 #include "libavcodec/internal.h"
43 #include "libavcodec/raw.h"
44 
45 #include "avformat.h"
46 #include "avformat_internal.h"
47 #include "avio_internal.h"
48 #include "demux.h"
49 #include "id3v2.h"
50 #include "internal.h"
51 #include "url.h"
52 
53 static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp)
54 {
55  const FFStream *const sti = cffstream(st);
56  if (sti->pts_wrap_behavior != AV_PTS_WRAP_IGNORE && st->pts_wrap_bits < 64 &&
57  sti->pts_wrap_reference != AV_NOPTS_VALUE && timestamp != AV_NOPTS_VALUE) {
59  timestamp < sti->pts_wrap_reference)
60  return timestamp + (1ULL << st->pts_wrap_bits);
61  else if (sti->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET &&
62  timestamp >= sti->pts_wrap_reference)
63  return timestamp - (1ULL << st->pts_wrap_bits);
64  }
65  return timestamp;
66 }
67 
69 {
70  return wrap_timestamp(st, timestamp);
71 }
72 
74 {
75  const AVCodec *codec;
76 
77 #if CONFIG_H264_DECODER
78  /* Other parts of the code assume this decoder to be used for h264,
79  * so force it if possible. */
81  return avcodec_find_decoder_by_name("h264");
82 #endif
83 
84  codec = ff_find_decoder(s, st, codec_id);
85  if (!codec)
86  return NULL;
87 
89  const AVCodec *probe_codec = NULL;
90  void *iter = NULL;
91  while ((probe_codec = av_codec_iterate(&iter))) {
92  if (probe_codec->id == codec->id &&
95  return probe_codec;
96  }
97  }
98  }
99 
100  return codec;
101 }
102 
104  AVProbeData *pd)
105 {
106  static const struct {
107  const char *name;
108  enum AVCodecID id;
109  enum AVMediaType type;
110  } fmt_id_type[] = {
123  { "mjpeg_2000", AV_CODEC_ID_JPEG2000, AVMEDIA_TYPE_VIDEO },
125  { "mpegvideo", AV_CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO },
126  { "truehd", AV_CODEC_ID_TRUEHD, AVMEDIA_TYPE_AUDIO },
129  { 0 }
130  };
131  int score;
132  const AVInputFormat *fmt = av_probe_input_format3(pd, 1, &score);
133  FFStream *const sti = ffstream(st);
134 
135  if (fmt) {
137  "Probe with size=%d, packets=%d detected %s with score=%d\n",
138  pd->buf_size, s->max_probe_packets - sti->probe_packets,
139  fmt->name, score);
140  for (int i = 0; fmt_id_type[i].name; i++) {
141  if (!strcmp(fmt->name, fmt_id_type[i].name)) {
142  if (fmt_id_type[i].type != AVMEDIA_TYPE_AUDIO &&
143  st->codecpar->sample_rate)
144  continue;
145  if (sti->request_probe > score &&
146  st->codecpar->codec_id != fmt_id_type[i].id)
147  continue;
148  st->codecpar->codec_id = fmt_id_type[i].id;
149  st->codecpar->codec_type = fmt_id_type[i].type;
150  sti->need_context_update = 1;
151  return score;
152  }
153  }
154  }
155  return 0;
156 }
157 
158 static int init_input(AVFormatContext *s, const char *filename,
160 {
161  int ret;
162  AVProbeData pd = { filename, NULL, 0 };
163  int score = AVPROBE_SCORE_RETRY;
164 
165  if (s->pb) {
166  s->flags |= AVFMT_FLAG_CUSTOM_IO;
167  if (!s->iformat)
168  return av_probe_input_buffer2(s->pb, &s->iformat, filename,
169  s, 0, s->format_probesize);
170  else if (s->iformat->flags & AVFMT_NOFILE)
171  av_log(s, AV_LOG_WARNING, "Custom AVIOContext makes no sense and "
172  "will be ignored with AVFMT_NOFILE format.\n");
173  return 0;
174  }
175 
176  if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) ||
177  (!s->iformat && (s->iformat = av_probe_input_format2(&pd, 0, &score))))
178  return score;
179 
180  if ((ret = s->io_open(s, &s->pb, filename, AVIO_FLAG_READ | s->avio_flags, options)) < 0)
181  return ret;
182 
183  if (s->iformat)
184  return 0;
185  return av_probe_input_buffer2(s->pb, &s->iformat, filename,
186  s, 0, s->format_probesize);
187 }
188 
189 static int codec_close(FFStream *sti);
190 
192 {
193  int ret;
194  for (unsigned i = 0; i < s->nb_streams; i++) {
195  AVStream *const st = s->streams[i];
196  FFStream *const sti = ffstream(st);
197 
198  if (!sti->need_context_update)
199  continue;
200 
201  if (avcodec_is_open(sti->avctx)) {
202  av_log(s, AV_LOG_DEBUG, "Demuxer context update while decoder is open, closing and trying to re-open\n");
203  ret = codec_close(sti);
204  sti->info->found_decoder = 0;
205  if (ret < 0)
206  return ret;
207  }
208 
209  /* close parser, because it depends on the codec */
210  if (sti->parser && sti->avctx->codec_id != st->codecpar->codec_id) {
211  av_parser_close(sti->parser);
212  sti->parser = NULL;
213  }
214 
215  /* update internal codec context, for the parser */
217  if (ret < 0)
218  return ret;
219 
221 
222  sti->need_context_update = 0;
223  }
224  return 0;
225 }
226 
229 }
230 
231 int avformat_open_input(AVFormatContext **ps, const char *filename,
232  const AVInputFormat *fmt, AVDictionary **options)
233 {
235  AVFormatContext *s = *ps;
236  FFFormatContext *si;
237  AVDictionary *tmp = NULL;
238  ID3v2ExtraMeta *id3v2_extra_meta = NULL;
239  int ret = 0;
240 
241  if (!s && !(s = avformat_alloc_context()))
242  return AVERROR(ENOMEM);
243  fci = ff_fc_internal(s);
244  si = &fci->fc;
245  if (!s->av_class) {
246  av_log(NULL, AV_LOG_ERROR, "Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n");
247  return AVERROR(EINVAL);
248  }
249  if (fmt)
250  s->iformat = fmt;
251 
252  if (options)
253  av_dict_copy(&tmp, *options, 0);
254 
255  if (s->pb) // must be before any goto fail
256  s->flags |= AVFMT_FLAG_CUSTOM_IO;
257 
258  if ((ret = av_opt_set_dict(s, &tmp)) < 0)
259  goto fail;
260 
261  if (!(s->url = av_strdup(filename ? filename : ""))) {
262  ret = AVERROR(ENOMEM);
263  goto fail;
264  }
265 
266  if ((ret = init_input(s, filename, &tmp)) < 0)
267  goto fail;
268  s->probe_score = ret;
269 
270  if (!s->protocol_whitelist && s->pb && s->pb->protocol_whitelist) {
271  s->protocol_whitelist = av_strdup(s->pb->protocol_whitelist);
272  if (!s->protocol_whitelist) {
273  ret = AVERROR(ENOMEM);
274  goto fail;
275  }
276  }
277 
278  if (!s->protocol_blacklist && s->pb && s->pb->protocol_blacklist) {
279  s->protocol_blacklist = av_strdup(s->pb->protocol_blacklist);
280  if (!s->protocol_blacklist) {
281  ret = AVERROR(ENOMEM);
282  goto fail;
283  }
284  }
285 
286  if (s->format_whitelist && av_match_list(s->iformat->name, s->format_whitelist, ',') <= 0) {
287  av_log(s, AV_LOG_ERROR, "Format not on whitelist \'%s\'\n", s->format_whitelist);
288  ret = AVERROR(EINVAL);
289  goto fail;
290  }
291 
292  avio_skip(s->pb, s->skip_initial_bytes);
293 
294  /* Check filename in case an image number is expected. */
295  if (s->iformat->flags & AVFMT_NEEDNUMBER) {
296  if (!av_filename_number_test(filename)) {
297  ret = AVERROR(EINVAL);
298  goto fail;
299  }
300  }
301 
302  s->duration = s->start_time = AV_NOPTS_VALUE;
303 
304  /* Allocate private data. */
305  if (ffifmt(s->iformat)->priv_data_size > 0) {
306  if (!(s->priv_data = av_mallocz(ffifmt(s->iformat)->priv_data_size))) {
307  ret = AVERROR(ENOMEM);
308  goto fail;
309  }
310  if (s->iformat->priv_class) {
311  *(const AVClass **) s->priv_data = s->iformat->priv_class;
312  av_opt_set_defaults(s->priv_data);
313  if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0)
314  goto fail;
315  }
316  }
317 
318  /* e.g. AVFMT_NOFILE formats will not have an AVIOContext */
319  if (s->pb && is_id3v2_format(s->iformat))
320  ff_id3v2_read_dict(s->pb, &si->id3v2_meta, ID3v2_DEFAULT_MAGIC, &id3v2_extra_meta);
321 
322  if (ffifmt(s->iformat)->read_header)
323  if ((ret = ffifmt(s->iformat)->read_header(s)) < 0) {
325  goto close;
326  goto fail;
327  }
328 
329  if (!s->metadata) {
330  s->metadata = si->id3v2_meta;
331  si->id3v2_meta = NULL;
332  } else if (si->id3v2_meta) {
333  av_log(s, AV_LOG_WARNING, "Discarding ID3 tags because more suitable tags were found.\n");
334  av_dict_free(&si->id3v2_meta);
335  }
336 
337  if (id3v2_extra_meta) {
338  if ((ret = ff_id3v2_parse_apic(s, id3v2_extra_meta)) < 0)
339  goto close;
340  if ((ret = ff_id3v2_parse_chapters(s, id3v2_extra_meta)) < 0)
341  goto close;
342  if ((ret = ff_id3v2_parse_priv(s, id3v2_extra_meta)) < 0)
343  goto close;
344  ff_id3v2_free_extra_meta(&id3v2_extra_meta);
345  }
346 
348  goto close;
349 
350  if (s->pb && !si->data_offset)
351  si->data_offset = avio_tell(s->pb);
352 
353  fci->raw_packet_buffer_size = 0;
354 
356 
357  if (options) {
359  *options = tmp;
360  }
361  *ps = s;
362  return 0;
363 
364 close:
365  if (ffifmt(s->iformat)->read_close)
366  ffifmt(s->iformat)->read_close(s);
367 fail:
368  ff_id3v2_free_extra_meta(&id3v2_extra_meta);
369  av_dict_free(&tmp);
370  if (s->pb && !(s->flags & AVFMT_FLAG_CUSTOM_IO))
371  avio_closep(&s->pb);
373  *ps = NULL;
374  return ret;
375 }
376 
378 {
380  AVIOContext *pb;
381 
382  if (!ps || !*ps)
383  return;
384 
385  s = *ps;
386  pb = s->pb;
387 
388  if ((s->iformat && strcmp(s->iformat->name, "image2") && s->iformat->flags & AVFMT_NOFILE) ||
389  (s->flags & AVFMT_FLAG_CUSTOM_IO))
390  pb = NULL;
391 
392  if (s->iformat)
393  if (ffifmt(s->iformat)->read_close)
394  ffifmt(s->iformat)->read_close(s);
395 
396  ff_format_io_close(s, &pb);
398 
399  *ps = NULL;
400 }
401 
403 {
404  switch (st->codecpar->codec_type) {
405  case AVMEDIA_TYPE_VIDEO:
406  if (s->video_codec_id)
407  st->codecpar->codec_id = s->video_codec_id;
408  break;
409  case AVMEDIA_TYPE_AUDIO:
410  if (s->audio_codec_id)
411  st->codecpar->codec_id = s->audio_codec_id;
412  break;
414  if (s->subtitle_codec_id)
415  st->codecpar->codec_id = s->subtitle_codec_id;
416  break;
417  case AVMEDIA_TYPE_DATA:
418  if (s->data_codec_id)
419  st->codecpar->codec_id = s->data_codec_id;
420  break;
421  }
422 }
423 
425 {
426  FormatContextInternal *const fci = ff_fc_internal(s);
427  FFStream *const sti = ffstream(st);
428 
429  if (sti->request_probe > 0) {
430  AVProbeData *const pd = &sti->probe_data;
431  int end;
432  av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, sti->probe_packets);
433  --sti->probe_packets;
434 
435  if (pkt) {
436  uint8_t *new_buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE);
437  if (!new_buf) {
439  "Failed to reallocate probe buffer for stream %d\n",
440  st->index);
441  goto no_packet;
442  }
443  pd->buf = new_buf;
444  memcpy(pd->buf + pd->buf_size, pkt->data, pkt->size);
445  pd->buf_size += pkt->size;
446  memset(pd->buf + pd->buf_size, 0, AVPROBE_PADDING_SIZE);
447  } else {
448 no_packet:
449  sti->probe_packets = 0;
450  if (!pd->buf_size) {
452  "nothing to probe for stream %d\n", st->index);
453  }
454  }
455 
456  end = fci->raw_packet_buffer_size >= s->probesize ||
457  sti->probe_packets <= 0;
458 
459  if (end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) {
460  int score = set_codec_from_probe_data(s, st, pd);
462  || end) {
463  pd->buf_size = 0;
464  av_freep(&pd->buf);
465  sti->request_probe = -1;
466  if (st->codecpar->codec_id != AV_CODEC_ID_NONE) {
467  av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index);
468  } else
469  av_log(s, AV_LOG_WARNING, "probed stream %d failed\n", st->index);
470  }
471  force_codec_ids(s, st);
472  }
473  }
474  return 0;
475 }
476 
477 static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt)
478 {
479  FFStream *const sti = ffstream(st);
480  int64_t ref = pkt->dts;
481  int pts_wrap_behavior;
482  int64_t pts_wrap_reference;
483  AVProgram *first_program;
484 
485  if (ref == AV_NOPTS_VALUE)
486  ref = pkt->pts;
487  if (sti->pts_wrap_reference != AV_NOPTS_VALUE || st->pts_wrap_bits >= 63 || ref == AV_NOPTS_VALUE || !s->correct_ts_overflow)
488  return 0;
489  ref &= (1LL << st->pts_wrap_bits)-1;
490 
491  // reference time stamp should be 60 s before first time stamp
492  pts_wrap_reference = ref - av_rescale(60, st->time_base.den, st->time_base.num);
493  // if first time stamp is not more than 1/8 and 60s before the wrap point, subtract rather than add wrap offset
494  pts_wrap_behavior = (ref < (1LL << st->pts_wrap_bits) - (1LL << st->pts_wrap_bits-3)) ||
495  (ref < (1LL << st->pts_wrap_bits) - av_rescale(60, st->time_base.den, st->time_base.num)) ?
497 
498  first_program = av_find_program_from_stream(s, NULL, stream_index);
499 
500  if (!first_program) {
501  int default_stream_index = av_find_default_stream_index(s);
502  FFStream *const default_sti = ffstream(s->streams[default_stream_index]);
503  if (default_sti->pts_wrap_reference == AV_NOPTS_VALUE) {
504  for (unsigned i = 0; i < s->nb_streams; i++) {
505  FFStream *const sti = ffstream(s->streams[i]);
507  continue;
508  sti->pts_wrap_reference = pts_wrap_reference;
509  sti->pts_wrap_behavior = pts_wrap_behavior;
510  }
511  } else {
512  sti->pts_wrap_reference = default_sti->pts_wrap_reference;
513  sti->pts_wrap_behavior = default_sti->pts_wrap_behavior;
514  }
515  } else {
516  AVProgram *program = first_program;
517  while (program) {
518  if (program->pts_wrap_reference != AV_NOPTS_VALUE) {
519  pts_wrap_reference = program->pts_wrap_reference;
520  pts_wrap_behavior = program->pts_wrap_behavior;
521  break;
522  }
523  program = av_find_program_from_stream(s, program, stream_index);
524  }
525 
526  // update every program with differing pts_wrap_reference
527  program = first_program;
528  while (program) {
529  if (program->pts_wrap_reference != pts_wrap_reference) {
530  for (unsigned i = 0; i < program->nb_stream_indexes; i++) {
531  FFStream *const sti = ffstream(s->streams[program->stream_index[i]]);
532  sti->pts_wrap_reference = pts_wrap_reference;
533  sti->pts_wrap_behavior = pts_wrap_behavior;
534  }
535 
536  program->pts_wrap_reference = pts_wrap_reference;
537  program->pts_wrap_behavior = pts_wrap_behavior;
538  }
539  program = av_find_program_from_stream(s, program, stream_index);
540  }
541  }
542  return 1;
543 }
544 
546 {
547  FFStream *const sti = ffstream(st);
548 
550  // correct first time stamps to negative values
551  if (!is_relative(sti->first_dts))
552  sti->first_dts = wrap_timestamp(st, sti->first_dts);
553  if (!is_relative(st->start_time))
554  st->start_time = wrap_timestamp(st, st->start_time);
555  if (!is_relative(sti->cur_dts))
556  sti->cur_dts = wrap_timestamp(st, sti->cur_dts);
557  }
558 
559  pkt->dts = wrap_timestamp(st, pkt->dts);
560  pkt->pts = wrap_timestamp(st, pkt->pts);
561 
562  force_codec_ids(s, st);
563 
564  /* TODO: audio: time filter; video: frame reordering (pts != dts) */
565  if (s->use_wallclock_as_timestamps)
567 }
568 
569 /**
570  * Handle a new packet and either return it directly if possible and
571  * allow_passthrough is true or queue the packet (or drop the packet
572  * if corrupt).
573  *
574  * @return < 0 on error, 0 if the packet was passed through,
575  * 1 if it was queued or dropped
576  */
577 static int handle_new_packet(AVFormatContext *s, AVPacket *pkt, int allow_passthrough)
578 {
579  FormatContextInternal *const fci = ff_fc_internal(s);
580  AVStream *st;
581  FFStream *sti;
582  int err;
583 
584  av_assert0(pkt->stream_index < (unsigned)s->nb_streams &&
585  "Invalid stream index.\n");
586 
587  if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
589  "Packet corrupt (stream = %d, dts = %s)%s.\n",
591  s->flags & AVFMT_FLAG_DISCARD_CORRUPT ? ", dropping it" : "");
592  if (s->flags & AVFMT_FLAG_DISCARD_CORRUPT) {
594  return 1;
595  }
596  }
597 
598  st = s->streams[pkt->stream_index];
599  sti = ffstream(st);
600 
601  update_timestamps(s, st, pkt);
602 
603  if (sti->request_probe <= 0 && allow_passthrough && !fci->raw_packet_buffer.head)
604  return 0;
605 
607  if (err < 0) {
609  return err;
610  }
611 
612  pkt = &fci->raw_packet_buffer.tail->pkt;
614 
615  err = probe_codec(s, st, pkt);
616  if (err < 0)
617  return err;
618 
619  return 1;
620 }
621 
623 {
624  int err = handle_new_packet(s, pkt, 0);
625 
626  return err < 0 ? err : 0;
627 }
628 
630 {
631  FormatContextInternal *const fci = ff_fc_internal(s);
632  int err;
633 
634 #if FF_API_INIT_PACKET
636  pkt->data = NULL;
637  pkt->size = 0;
638  av_init_packet(pkt);
640 #else
642 #endif
643 
644  for (;;) {
646 
647  if (pktl) {
648  AVStream *const st = s->streams[pktl->pkt.stream_index];
649  if (fci->raw_packet_buffer_size >= s->probesize)
650  if ((err = probe_codec(s, st, NULL)) < 0)
651  return err;
652  if (ffstream(st)->request_probe <= 0) {
655  return 0;
656  }
657  }
658 
659  err = ffifmt(s->iformat)->read_packet(s, pkt);
660  if (err < 0) {
662 
663  /* Some demuxers return FFERROR_REDO when they consume
664  data and discard it (ignored streams, junk, extradata).
665  We must re-call the demuxer to get the real packet. */
666  if (err == FFERROR_REDO)
667  continue;
668  if (!pktl || err == AVERROR(EAGAIN))
669  return err;
670  for (unsigned i = 0; i < s->nb_streams; i++) {
671  AVStream *const st = s->streams[i];
672  FFStream *const sti = ffstream(st);
673  if (sti->probe_packets || sti->request_probe > 0)
674  if ((err = probe_codec(s, st, NULL)) < 0)
675  return err;
676  av_assert0(sti->request_probe <= 0);
677  }
678  continue;
679  }
680 
682  if (err < 0) {
684  return err;
685  }
686 
687  err = handle_new_packet(s, pkt, 1);
688  if (err <= 0) /* Error or passthrough */
689  return err;
690  }
691 }
692 
693 /**
694  * Return the frame duration in seconds. Return 0 if not available.
695  */
696 static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden,
698  AVPacket *pkt)
699 {
700  FFStream *const sti = ffstream(st);
701  AVRational codec_framerate = sti->avctx->framerate;
702  int frame_size, sample_rate;
703 
704  *pnum = 0;
705  *pden = 0;
706  switch (st->codecpar->codec_type) {
707  case AVMEDIA_TYPE_VIDEO:
708  if (st->r_frame_rate.num && (!pc || !codec_framerate.num)) {
709  *pnum = st->r_frame_rate.den;
710  *pden = st->r_frame_rate.num;
711  } else if ((s->iformat->flags & AVFMT_NOTIMESTAMPS) &&
712  !codec_framerate.num &&
713  st->avg_frame_rate.num && st->avg_frame_rate.den) {
714  *pnum = st->avg_frame_rate.den;
715  *pden = st->avg_frame_rate.num;
716  } else if (st->time_base.num * 1000LL > st->time_base.den) {
717  *pnum = st->time_base.num;
718  *pden = st->time_base.den;
719  } else if (codec_framerate.den * 1000LL > codec_framerate.num) {
720  int ticks_per_frame = (sti->codec_desc &&
721  (sti->codec_desc->props & AV_CODEC_PROP_FIELDS)) ? 2 : 1;
722  av_reduce(pnum, pden,
723  codec_framerate.den,
724  codec_framerate.num * (int64_t)ticks_per_frame,
725  INT_MAX);
726 
727  if (pc && pc->repeat_pict) {
728  av_reduce(pnum, pden,
729  (*pnum) * (1LL + pc->repeat_pict),
730  (*pden),
731  INT_MAX);
732  }
733  /* If this codec can be interlaced or progressive then we need
734  * a parser to compute duration of a packet. Thus if we have
735  * no parser in such case leave duration undefined. */
736  if (sti->codec_desc &&
737  (sti->codec_desc->props & AV_CODEC_PROP_FIELDS) && !pc)
738  *pnum = *pden = 0;
739  }
740  break;
741  case AVMEDIA_TYPE_AUDIO:
742  if (sti->avctx_inited) {
744  sample_rate = sti->avctx->sample_rate;
745  } else {
747  sample_rate = st->codecpar->sample_rate;
748  }
749  if (frame_size <= 0 || sample_rate <= 0)
750  break;
751  *pnum = frame_size;
752  *pden = sample_rate;
753  break;
754  default:
755  break;
756  }
757 }
758 
760 {
761  FFStream *const sti = ffstream(st);
762  if (st->codecpar->codec_id != AV_CODEC_ID_H264) return 1;
763  if (!sti->info) // if we have left find_stream_info then nb_decoded_frames won't increase anymore for stream copy
764  return 1;
766 #if CONFIG_H264_DECODER
767  if (sti->avctx->has_b_frames && avcodec_is_open(sti->avctx) &&
769  return 1;
770 #endif
771  if (sti->avctx->has_b_frames < 3)
772  return sti->nb_decoded_frames >= 7;
773  else if (sti->avctx->has_b_frames < 4)
774  return sti->nb_decoded_frames >= 18;
775  else
776  return sti->nb_decoded_frames >= 20;
777 }
778 
780  PacketListEntry *pktl)
781 {
782  FormatContextInternal *const fci = ff_fc_internal(s);
783  FFFormatContext *const si = &fci->fc;
784  if (pktl->next)
785  return pktl->next;
786  if (pktl == si->packet_buffer.tail)
787  return fci->parse_queue.head;
788  return NULL;
789 }
790 
792 {
793  FFStream *const sti = ffstream(st);
794  int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 &&
797 
798  if (!onein_oneout) {
799  int delay = sti->avctx->has_b_frames;
800 
801  if (dts == AV_NOPTS_VALUE) {
802  int64_t best_score = INT64_MAX;
803  for (int i = 0; i < delay; i++) {
804  if (sti->pts_reorder_error_count[i]) {
805  int64_t score = sti->pts_reorder_error[i] / sti->pts_reorder_error_count[i];
806  if (score < best_score) {
807  best_score = score;
808  dts = pts_buffer[i];
809  }
810  }
811  }
812  } else {
813  for (int i = 0; i < delay; i++) {
814  if (pts_buffer[i] != AV_NOPTS_VALUE) {
815  int64_t diff = FFABS(pts_buffer[i] - dts)
816  + (uint64_t)sti->pts_reorder_error[i];
817  diff = FFMAX(diff, sti->pts_reorder_error[i]);
818  sti->pts_reorder_error[i] = diff;
819  sti->pts_reorder_error_count[i]++;
820  if (sti->pts_reorder_error_count[i] > 250) {
821  sti->pts_reorder_error[i] >>= 1;
822  sti->pts_reorder_error_count[i] >>= 1;
823  }
824  }
825  }
826  }
827  }
828 
829  if (dts == AV_NOPTS_VALUE)
830  dts = pts_buffer[0];
831 
832  return dts;
833 }
834 
835 /**
836  * Updates the dts of packets of a stream in pkt_buffer, by re-ordering the pts
837  * of the packets in a window.
838  */
839 static void update_dts_from_pts(AVFormatContext *s, int stream_index,
840  PacketListEntry *pkt_buffer)
841 {
842  AVStream *const st = s->streams[stream_index];
843  int delay = ffstream(st)->avctx->has_b_frames;
844 
845  int64_t pts_buffer[MAX_REORDER_DELAY+1];
846 
847  for (int i = 0; i < MAX_REORDER_DELAY + 1; i++)
848  pts_buffer[i] = AV_NOPTS_VALUE;
849 
850  for (; pkt_buffer; pkt_buffer = get_next_pkt(s, st, pkt_buffer)) {
851  if (pkt_buffer->pkt.stream_index != stream_index)
852  continue;
853 
854  if (pkt_buffer->pkt.pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) {
855  pts_buffer[0] = pkt_buffer->pkt.pts;
856  for (int i = 0; i < delay && pts_buffer[i] > pts_buffer[i + 1]; i++)
857  FFSWAP(int64_t, pts_buffer[i], pts_buffer[i + 1]);
858 
859  pkt_buffer->pkt.dts = select_from_pts_buffer(st, pts_buffer, pkt_buffer->pkt.dts);
860  }
861  }
862 }
863 
864 static void update_initial_timestamps(AVFormatContext *s, int stream_index,
865  int64_t dts, int64_t pts, AVPacket *pkt)
866 {
867  FormatContextInternal *const fci = ff_fc_internal(s);
868  FFFormatContext *const si = &fci->fc;
869  AVStream *const st = s->streams[stream_index];
870  FFStream *const sti = ffstream(st);
872 
873  uint64_t shift;
874 
875  if (sti->first_dts != AV_NOPTS_VALUE ||
876  dts == AV_NOPTS_VALUE ||
877  sti->cur_dts == AV_NOPTS_VALUE ||
878  sti->cur_dts < INT_MIN + RELATIVE_TS_BASE ||
879  dts < INT_MIN + (sti->cur_dts - RELATIVE_TS_BASE) ||
880  is_relative(dts))
881  return;
882 
883  sti->first_dts = dts - (sti->cur_dts - RELATIVE_TS_BASE);
884  sti->cur_dts = dts;
885  shift = (uint64_t)sti->first_dts - RELATIVE_TS_BASE;
886 
887  if (is_relative(pts))
888  pts += shift;
889 
890  for (PacketListEntry *pktl_it = pktl; pktl_it; pktl_it = get_next_pkt(s, st, pktl_it)) {
891  if (pktl_it->pkt.stream_index != stream_index)
892  continue;
893  if (is_relative(pktl_it->pkt.pts))
894  pktl_it->pkt.pts += shift;
895 
896  if (is_relative(pktl_it->pkt.dts))
897  pktl_it->pkt.dts += shift;
898 
899  if (st->start_time == AV_NOPTS_VALUE && pktl_it->pkt.pts != AV_NOPTS_VALUE) {
900  st->start_time = pktl_it->pkt.pts;
902  st->start_time = av_sat_add64(st->start_time, av_rescale_q(sti->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base));
903  }
904  }
905 
907  update_dts_from_pts(s, stream_index, pktl);
908 
909  if (st->start_time == AV_NOPTS_VALUE) {
911  st->start_time = pts;
912  }
914  st->start_time = av_sat_add64(st->start_time, av_rescale_q(sti->skip_samples, (AVRational){1, st->codecpar->sample_rate}, st->time_base));
915  }
916 }
917 
919  int stream_index, int64_t duration)
920 {
921  FormatContextInternal *const fci = ff_fc_internal(s);
922  FFFormatContext *const si = &fci->fc;
923  FFStream *const sti = ffstream(st);
925  int64_t cur_dts = RELATIVE_TS_BASE;
926 
927  if (sti->first_dts != AV_NOPTS_VALUE) {
929  return;
931  cur_dts = sti->first_dts;
932  for (; pktl; pktl = get_next_pkt(s, st, pktl)) {
933  if (pktl->pkt.stream_index == stream_index) {
934  if (pktl->pkt.pts != pktl->pkt.dts ||
935  pktl->pkt.dts != AV_NOPTS_VALUE ||
936  pktl->pkt.duration)
937  break;
938  cur_dts -= duration;
939  }
940  }
941  if (pktl && pktl->pkt.dts != sti->first_dts) {
942  av_log(s, AV_LOG_DEBUG, "first_dts %s not matching first dts %s (pts %s, duration %"PRId64") in the queue\n",
943  av_ts2str(sti->first_dts), av_ts2str(pktl->pkt.dts), av_ts2str(pktl->pkt.pts), pktl->pkt.duration);
944  return;
945  }
946  if (!pktl) {
947  av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(sti->first_dts));
948  return;
949  }
950  pktl = si->packet_buffer.head ? si->packet_buffer.head : fci->parse_queue.head;
951  sti->first_dts = cur_dts;
952  } else if (sti->cur_dts != RELATIVE_TS_BASE)
953  return;
954 
955  for (; pktl; pktl = get_next_pkt(s, st, pktl)) {
956  if (pktl->pkt.stream_index != stream_index)
957  continue;
958  if ((pktl->pkt.pts == pktl->pkt.dts ||
959  pktl->pkt.pts == AV_NOPTS_VALUE) &&
960  (pktl->pkt.dts == AV_NOPTS_VALUE ||
961  pktl->pkt.dts == sti->first_dts ||
962  pktl->pkt.dts == RELATIVE_TS_BASE) &&
963  !pktl->pkt.duration &&
964  av_sat_add64(cur_dts, duration) == cur_dts + (uint64_t)duration
965  ) {
966  pktl->pkt.dts = cur_dts;
967  if (!sti->avctx->has_b_frames)
968  pktl->pkt.pts = cur_dts;
969  pktl->pkt.duration = duration;
970  } else
971  break;
972  cur_dts = pktl->pkt.dts + pktl->pkt.duration;
973  }
974  if (!pktl)
975  sti->cur_dts = cur_dts;
976 }
977 
980  int64_t next_dts, int64_t next_pts)
981 {
982  FormatContextInternal *const fci = ff_fc_internal(s);
983  FFFormatContext *const si = &fci->fc;
984  FFStream *const sti = ffstream(st);
985  int num, den, presentation_delayed, delay;
986  int64_t offset;
988  int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 &&
991 
992  if (s->flags & AVFMT_FLAG_NOFILLIN)
993  return;
994 
996  if (pkt->dts == pkt->pts && sti->last_dts_for_order_check != AV_NOPTS_VALUE) {
997  if (sti->last_dts_for_order_check <= pkt->dts) {
998  sti->dts_ordered++;
999  } else {
1001  "DTS %"PRIi64" < %"PRIi64" out of order\n",
1002  pkt->dts,
1004  sti->dts_misordered++;
1005  }
1006  if (sti->dts_ordered + sti->dts_misordered > 250) {
1007  sti->dts_ordered >>= 1;
1008  sti->dts_misordered >>= 1;
1009  }
1010  }
1011 
1013  if (sti->dts_ordered < 8 * sti->dts_misordered && pkt->dts == pkt->pts)
1014  pkt->dts = AV_NOPTS_VALUE;
1015  }
1016 
1017  if ((s->flags & AVFMT_FLAG_IGNDTS) && pkt->pts != AV_NOPTS_VALUE)
1018  pkt->dts = AV_NOPTS_VALUE;
1019 
1020  if (pc && pc->pict_type == AV_PICTURE_TYPE_B
1021  && !sti->avctx->has_b_frames)
1022  //FIXME Set low_delay = 0 when has_b_frames = 1
1023  sti->avctx->has_b_frames = 1;
1024 
1025  /* do we have a video B-frame ? */
1026  delay = sti->avctx->has_b_frames;
1027  presentation_delayed = 0;
1028 
1029  /* XXX: need has_b_frame, but cannot get it if the codec is
1030  * not initialized */
1031  if (delay &&
1032  pc && pc->pict_type != AV_PICTURE_TYPE_B)
1033  presentation_delayed = 1;
1034 
1035  if (pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE &&
1036  st->pts_wrap_bits < 63 && pkt->dts > INT64_MIN + (1LL << st->pts_wrap_bits) &&
1037  pkt->dts - (1LL << (st->pts_wrap_bits - 1)) > pkt->pts) {
1038  if (is_relative(sti->cur_dts) || pkt->dts - (1LL<<(st->pts_wrap_bits - 1)) > sti->cur_dts) {
1039  pkt->dts -= 1LL << st->pts_wrap_bits;
1040  } else
1041  pkt->pts += 1LL << st->pts_wrap_bits;
1042  }
1043 
1044  /* Some MPEG-2 in MPEG-PS lack dts (issue #171 / input_file.mpg).
1045  * We take the conservative approach and discard both.
1046  * Note: If this is misbehaving for an H.264 file, then possibly
1047  * presentation_delayed is not set correctly. */
1048  if (delay == 1 && pkt->dts == pkt->pts &&
1049  pkt->dts != AV_NOPTS_VALUE && presentation_delayed) {
1050  av_log(s, AV_LOG_DEBUG, "invalid dts/pts combination %"PRIi64"\n", pkt->dts);
1051  if ( strcmp(s->iformat->name, "mov,mp4,m4a,3gp,3g2,mj2")
1052  && strcmp(s->iformat->name, "flv")) // otherwise we discard correct timestamps for vc1-wmapro.ism
1053  pkt->dts = AV_NOPTS_VALUE;
1054  }
1055 
1057  if (pkt->duration <= 0) {
1058  compute_frame_duration(s, &num, &den, st, pc, pkt);
1059  if (den && num) {
1060  duration = (AVRational) {num, den};
1062  num * (int64_t) st->time_base.den,
1063  den * (int64_t) st->time_base.num,
1064  AV_ROUND_DOWN);
1065  }
1066  }
1067 
1068  if (pkt->duration > 0 && (si->packet_buffer.head || fci->parse_queue.head))
1070 
1071  /* Correct timestamps with byte offset if demuxers only have timestamps
1072  * on packet boundaries */
1073  if (pc && sti->need_parsing == AVSTREAM_PARSE_TIMESTAMPS && pkt->size) {
1074  /* this will estimate bitrate based on this frame's duration and size */
1076  if (pkt->pts != AV_NOPTS_VALUE)
1077  pkt->pts += offset;
1078  if (pkt->dts != AV_NOPTS_VALUE)
1079  pkt->dts += offset;
1080  }
1081 
1082  /* This may be redundant, but it should not hurt. */
1083  if (pkt->dts != AV_NOPTS_VALUE &&
1084  pkt->pts != AV_NOPTS_VALUE &&
1085  pkt->pts > pkt->dts)
1086  presentation_delayed = 1;
1087 
1088  if (s->debug & FF_FDEBUG_TS)
1090  "IN delayed:%d pts:%s, dts:%s cur_dts:%s st:%d pc:%p duration:%"PRId64" delay:%d onein_oneout:%d\n",
1091  presentation_delayed, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts),
1092  pkt->stream_index, pc, pkt->duration, delay, onein_oneout);
1093 
1094  /* Interpolate PTS and DTS if they are not present. We skip H264
1095  * currently because delay and has_b_frames are not reliably set. */
1096  if ((delay == 0 || (delay == 1 && pc)) &&
1097  onein_oneout) {
1098  if (presentation_delayed) {
1099  /* DTS = decompression timestamp */
1100  /* PTS = presentation timestamp */
1101  if (pkt->dts == AV_NOPTS_VALUE)
1102  pkt->dts = sti->last_IP_pts;
1104  if (pkt->dts == AV_NOPTS_VALUE)
1105  pkt->dts = sti->cur_dts;
1106 
1107  /* This is tricky: the dts must be incremented by the duration
1108  * of the frame we are displaying, i.e. the last I- or P-frame. */
1109  if (sti->last_IP_duration == 0 && (uint64_t)pkt->duration <= INT32_MAX)
1110  sti->last_IP_duration = pkt->duration;
1111  if (pkt->dts != AV_NOPTS_VALUE)
1112  sti->cur_dts = av_sat_add64(pkt->dts, sti->last_IP_duration);
1113  if (pkt->dts != AV_NOPTS_VALUE &&
1114  pkt->pts == AV_NOPTS_VALUE &&
1115  sti->last_IP_duration > 0 &&
1116  ((uint64_t)sti->cur_dts - (uint64_t)next_dts + 1) <= 2 &&
1117  next_dts != next_pts &&
1118  next_pts != AV_NOPTS_VALUE)
1119  pkt->pts = next_dts;
1120 
1121  if ((uint64_t)pkt->duration <= INT32_MAX)
1122  sti->last_IP_duration = pkt->duration;
1123  sti->last_IP_pts = pkt->pts;
1124  /* Cannot compute PTS if not present (we can compute it only
1125  * by knowing the future. */
1126  } else if (pkt->pts != AV_NOPTS_VALUE ||
1127  pkt->dts != AV_NOPTS_VALUE ||
1128  pkt->duration > 0 ) {
1129 
1130  /* presentation is not delayed : PTS and DTS are the same */
1131  if (pkt->pts == AV_NOPTS_VALUE)
1132  pkt->pts = pkt->dts;
1134  pkt->pts, pkt);
1135  if (pkt->pts == AV_NOPTS_VALUE)
1136  pkt->pts = sti->cur_dts;
1137  pkt->dts = pkt->pts;
1138  if (pkt->pts != AV_NOPTS_VALUE && duration.num >= 0)
1139  sti->cur_dts = av_add_stable(st->time_base, pkt->pts, duration, 1);
1140  }
1141  }
1142 
1143  if (pkt->pts != AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY) {
1144  sti->pts_buffer[0] = pkt->pts;
1145  for (int i = 0; i < delay && sti->pts_buffer[i] > sti->pts_buffer[i + 1]; i++)
1146  FFSWAP(int64_t, sti->pts_buffer[i], sti->pts_buffer[i + 1]);
1147 
1150  }
1151  // We skipped it above so we try here.
1152  if (!onein_oneout)
1153  // This should happen on the first packet
1155  if (pkt->dts > sti->cur_dts)
1156  sti->cur_dts = pkt->dts;
1157 
1158  if (s->debug & FF_FDEBUG_TS)
1159  av_log(s, AV_LOG_DEBUG, "OUTdelayed:%d/%d pts:%s, dts:%s cur_dts:%s st:%d (%d)\n",
1160  presentation_delayed, delay, av_ts2str(pkt->pts), av_ts2str(pkt->dts), av_ts2str(sti->cur_dts), st->index, st->id);
1161 
1162  /* update flags */
1165 }
1166 
1167 /**
1168  * Parse a packet, add all split parts to parse_queue.
1169  *
1170  * @param pkt Packet to parse; must not be NULL.
1171  * @param flush Indicates whether to flush. If set, pkt must be blank.
1172  */
1174  int stream_index, int flush)
1175 {
1176  FormatContextInternal *const fci = ff_fc_internal(s);
1177  FFFormatContext *const si = &fci->fc;
1178  AVPacket *out_pkt = si->parse_pkt;
1179  AVStream *st = s->streams[stream_index];
1180  FFStream *const sti = ffstream(st);
1181  const AVPacketSideData *sd = NULL;
1182  const uint8_t *data = pkt->data;
1183  uint8_t *extradata = sti->avctx->extradata;
1184  int extradata_size = sti->avctx->extradata_size;
1185  int size = pkt->size;
1186  int ret = 0, got_output = flush;
1187 
1188  if (!size && !flush && sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) {
1189  // preserve 0-size sync packets
1190  compute_pkt_fields(s, st, sti->parser, pkt, pkt->dts, pkt->pts);
1191 
1192  // Theora has valid 0-sized packets that need to be output
1193  if (st->codecpar->codec_id == AV_CODEC_ID_THEORA) {
1195  pkt, NULL, 0);
1196  if (ret < 0)
1197  goto fail;
1198  }
1199  }
1200 
1201  if (pkt->side_data_elems)
1204  if (sd) {
1205  av_assert1(size && !flush);
1206 
1207  sti->avctx->extradata = sd->data;
1208  sti->avctx->extradata_size = sd->size;
1209  }
1210 
1211  while (size > 0 || (flush && got_output)) {
1212  int64_t next_pts = pkt->pts;
1213  int64_t next_dts = pkt->dts;
1214  int len;
1215 
1216  len = av_parser_parse2(sti->parser, sti->avctx,
1217  &out_pkt->data, &out_pkt->size, data, size,
1218  pkt->pts, pkt->dts, pkt->pos);
1219 
1220  pkt->pts = pkt->dts = AV_NOPTS_VALUE;
1221  pkt->pos = -1;
1222  /* increment read pointer */
1223  av_assert1(data || !len);
1224  data = len ? data + len : data;
1225  size -= len;
1226 
1227  got_output = !!out_pkt->size;
1228 
1229  if (!out_pkt->size)
1230  continue;
1231 
1232  if (pkt->buf && out_pkt->data == pkt->data) {
1233  /* reference pkt->buf only when out_pkt->data is guaranteed to point
1234  * to data in it and not in the parser's internal buffer. */
1235  /* XXX: Ensure this is the case with all parsers when sti->parser->flags
1236  * is PARSER_FLAG_COMPLETE_FRAMES and check for that instead? */
1237  out_pkt->buf = av_buffer_ref(pkt->buf);
1238  if (!out_pkt->buf) {
1239  ret = AVERROR(ENOMEM);
1240  goto fail;
1241  }
1242  } else {
1243  ret = av_packet_make_refcounted(out_pkt);
1244  if (ret < 0)
1245  goto fail;
1246  }
1247 
1248  if (pkt->side_data) {
1249  out_pkt->side_data = pkt->side_data;
1250  out_pkt->side_data_elems = pkt->side_data_elems;
1251  pkt->side_data = NULL;
1252  pkt->side_data_elems = 0;
1253  }
1254 
1255  /* set the duration */
1256  out_pkt->duration = (sti->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->duration : 0;
1258  if (sti->avctx->sample_rate > 0) {
1259  out_pkt->duration =
1261  (AVRational) { 1, sti->avctx->sample_rate },
1262  st->time_base,
1263  AV_ROUND_DOWN);
1264  }
1265  } else if (st->codecpar->codec_id == AV_CODEC_ID_GIF) {
1266  if (st->time_base.num > 0 && st->time_base.den > 0 &&
1267  sti->parser->duration) {
1268  out_pkt->duration = sti->parser->duration;
1269  }
1270  }
1271 
1272  out_pkt->stream_index = st->index;
1273  out_pkt->pts = sti->parser->pts;
1274  out_pkt->dts = sti->parser->dts;
1275  out_pkt->pos = sti->parser->pos;
1277 
1279  out_pkt->pos = sti->parser->frame_offset;
1280 
1281  if (sti->parser->key_frame == 1 ||
1282  (sti->parser->key_frame == -1 &&
1284  out_pkt->flags |= AV_PKT_FLAG_KEY;
1285 
1287  out_pkt->flags |= AV_PKT_FLAG_KEY;
1288 
1289  compute_pkt_fields(s, st, sti->parser, out_pkt, next_dts, next_pts);
1290 
1292  out_pkt, NULL, 0);
1293  if (ret < 0)
1294  goto fail;
1295  }
1296 
1297  /* end of the stream => close and free the parser */
1298  if (flush) {
1299  av_parser_close(sti->parser);
1300  sti->parser = NULL;
1301  }
1302 
1303 fail:
1304  if (sd) {
1305  sti->avctx->extradata = extradata;
1306  sti->avctx->extradata_size = extradata_size;
1307  }
1308 
1309  if (ret < 0)
1310  av_packet_unref(out_pkt);
1312  return ret;
1313 }
1314 
1316 {
1317  return av_rescale(ts, st->time_base.num * st->codecpar->sample_rate, st->time_base.den);
1318 }
1319 
1320 static int codec_close(FFStream *sti)
1321 {
1322  AVCodecContext *avctx_new = NULL;
1323  AVCodecParameters *par_tmp = NULL;
1324  const AVCodec *new_codec = NULL;
1325  int ret;
1326 
1327  new_codec =
1328  (sti->avctx->codec_id != sti->pub.codecpar->codec_id) ?
1330  sti->avctx->codec;
1331 
1332  avctx_new = avcodec_alloc_context3(new_codec);
1333  if (!avctx_new) {
1334  ret = AVERROR(ENOMEM);
1335  goto fail;
1336  }
1337 
1338  par_tmp = avcodec_parameters_alloc();
1339  if (!par_tmp) {
1340  ret = AVERROR(ENOMEM);
1341  goto fail;
1342  }
1343 
1344  ret = avcodec_parameters_from_context(par_tmp, sti->avctx);
1345  if (ret < 0)
1346  goto fail;
1347 
1348  ret = avcodec_parameters_to_context(avctx_new, par_tmp);
1349  if (ret < 0)
1350  goto fail;
1351 
1352  avctx_new->pkt_timebase = sti->avctx->pkt_timebase;
1353 
1354  avcodec_free_context(&sti->avctx);
1355  sti->avctx = avctx_new;
1356 
1357  avctx_new = NULL;
1358  ret = 0;
1359 
1360 fail:
1361  avcodec_free_context(&avctx_new);
1362  avcodec_parameters_free(&par_tmp);
1363 
1364  return ret;
1365 }
1366 
1367 static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt);
1368 
1370 {
1371  FormatContextInternal *const fci = ff_fc_internal(s);
1372  FFFormatContext *const si = &fci->fc;
1373  int ret, got_packet = 0;
1375 
1376  while (!got_packet && !fci->parse_queue.head) {
1377  AVStream *st;
1378  FFStream *sti;
1379 
1380  /* read next packet */
1381  ret = ff_read_packet(s, pkt);
1382  if (ret < 0) {
1383  if (ret == AVERROR(EAGAIN))
1384  return ret;
1385  /* flush the parsers */
1386  for (unsigned i = 0; i < s->nb_streams; i++) {
1387  AVStream *const st = s->streams[i];
1388  FFStream *const sti = ffstream(st);
1389  if (sti->parser && sti->need_parsing)
1390  parse_packet(s, pkt, st->index, 1);
1391  }
1392  /* all remaining packets are now in parse_queue =>
1393  * really terminate parsing */
1394  break;
1395  }
1396  ret = 0;
1397  st = s->streams[pkt->stream_index];
1398  sti = ffstream(st);
1399 
1401 
1402  int new_extradata = !!av_packet_side_data_get(pkt->side_data, pkt->side_data_elems,
1404  if (new_extradata)
1405  sti->need_context_update = 1;
1406 
1407  /* update context if required */
1408  if (sti->need_context_update) {
1409  if (avcodec_is_open(sti->avctx)) {
1410  av_log(s, AV_LOG_DEBUG, "Demuxer context update while decoder is open, closing and trying to re-open\n");
1411  ret = codec_close(sti);
1412  sti->info->found_decoder = 0;
1413  if (ret < 0)
1414  return ret;
1415  }
1416 
1417  /* close parser, because it depends on the codec and extradata */
1418  if (sti->parser &&
1419  (sti->avctx->codec_id != st->codecpar->codec_id || new_extradata)) {
1420  av_parser_close(sti->parser);
1421  sti->parser = NULL;
1422  }
1423 
1425  if (ret < 0) {
1427  return ret;
1428  }
1429 
1430  if (!sti->avctx->extradata) {
1431  sti->extract_extradata.inited = 0;
1432 
1433  ret = extract_extradata(si, st, pkt);
1434  if (ret < 0) {
1436  return ret;
1437  }
1438  }
1439 
1441 
1442  sti->need_context_update = 0;
1443  }
1444 
1445  if (pkt->pts != AV_NOPTS_VALUE &&
1446  pkt->dts != AV_NOPTS_VALUE &&
1447  pkt->pts < pkt->dts) {
1449  "Invalid timestamps stream=%d, pts=%s, dts=%s, size=%d\n",
1450  pkt->stream_index,
1451  av_ts2str(pkt->pts),
1452  av_ts2str(pkt->dts),
1453  pkt->size);
1454  }
1455  if (s->debug & FF_FDEBUG_TS)
1457  "ff_read_packet stream=%d, pts=%s, dts=%s, size=%d, duration=%"PRId64", flags=%d\n",
1458  pkt->stream_index,
1459  av_ts2str(pkt->pts),
1460  av_ts2str(pkt->dts),
1461  pkt->size, pkt->duration, pkt->flags);
1462 
1463  if (sti->need_parsing && !sti->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) {
1464  sti->parser = av_parser_init(st->codecpar->codec_id);
1465  if (!sti->parser) {
1466  av_log(s, AV_LOG_VERBOSE, "parser not found for codec "
1467  "%s, packets or times may be invalid.\n",
1469  /* no parser available: just output the raw packets */
1471  } else if (sti->need_parsing == AVSTREAM_PARSE_HEADERS)
1473  else if (sti->need_parsing == AVSTREAM_PARSE_FULL_ONCE)
1474  sti->parser->flags |= PARSER_FLAG_ONCE;
1475  else if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW)
1477  }
1478 
1479  if (!sti->need_parsing || !sti->parser) {
1480  /* no parsing needed: we just output the packet as is */
1482  if ((s->iformat->flags & AVFMT_GENERIC_INDEX) &&
1484  ff_reduce_index(s, st->index);
1485  av_add_index_entry(st, pkt->pos, pkt->dts,
1486  0, 0, AVINDEX_KEYFRAME);
1487  }
1488  got_packet = 1;
1489  } else if (st->discard < AVDISCARD_ALL) {
1490  if ((ret = parse_packet(s, pkt, pkt->stream_index, 0)) < 0)
1491  return ret;
1492  st->codecpar->sample_rate = sti->avctx->sample_rate;
1493  st->codecpar->bit_rate = sti->avctx->bit_rate;
1495  if (ret < 0)
1496  return ret;
1497  st->codecpar->codec_id = sti->avctx->codec_id;
1498  } else {
1499  /* free packet */
1501  }
1502  if (pkt->flags & AV_PKT_FLAG_KEY)
1503  sti->skip_to_keyframe = 0;
1504  if (sti->skip_to_keyframe) {
1506  got_packet = 0;
1507  }
1508  }
1509 
1510  if (!got_packet && fci->parse_queue.head)
1512 
1513  if (ret >= 0) {
1514  AVStream *const st = s->streams[pkt->stream_index];
1515  FFStream *const sti = ffstream(st);
1516  int discard_padding = 0;
1517  if (sti->first_discard_sample && pkt->pts != AV_NOPTS_VALUE) {
1521  int64_t end_sample = sample + duration;
1522  if (duration > 0 && end_sample >= sti->first_discard_sample &&
1523  sample < sti->last_discard_sample)
1524  discard_padding = FFMIN(end_sample - sti->first_discard_sample, duration);
1525  }
1526  if (sti->start_skip_samples && (pkt->pts == 0 || pkt->pts == RELATIVE_TS_BASE))
1527  sti->skip_samples = sti->start_skip_samples;
1528  sti->skip_samples = FFMAX(0, sti->skip_samples);
1529  if (sti->skip_samples || discard_padding) {
1531  if (p) {
1532  AV_WL32(p, sti->skip_samples);
1533  AV_WL32(p + 4, discard_padding);
1534  av_log(s, AV_LOG_DEBUG, "demuxer injecting skip %u / discard %u\n",
1535  (unsigned)sti->skip_samples, (unsigned)discard_padding);
1536  }
1537  sti->skip_samples = 0;
1538  }
1539  }
1540 
1541  if (!fci->metafree) {
1542  int metaret = av_opt_get_dict_val(s, "metadata", AV_OPT_SEARCH_CHILDREN, &metadata);
1543  if (metadata) {
1544  s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
1545  av_dict_copy(&s->metadata, metadata, 0);
1548  }
1549  fci->metafree = metaret == AVERROR_OPTION_NOT_FOUND;
1550  }
1551 
1552  if (s->debug & FF_FDEBUG_TS)
1554  "read_frame_internal stream=%d, pts=%s, dts=%s, "
1555  "size=%d, duration=%"PRId64", flags=%d\n",
1556  pkt->stream_index,
1557  av_ts2str(pkt->pts),
1558  av_ts2str(pkt->dts),
1559  pkt->size, pkt->duration, pkt->flags);
1560 
1561  /* A demuxer might have returned EOF because of an IO error, let's
1562  * propagate this back to the user. */
1563  if (ret == AVERROR_EOF && s->pb && s->pb->error < 0 && s->pb->error != AVERROR(EAGAIN))
1564  ret = s->pb->error;
1565 
1566  return ret;
1567 }
1568 
1570 {
1571  FFFormatContext *const si = ffformatcontext(s);
1572  const int genpts = s->flags & AVFMT_FLAG_GENPTS;
1573  int eof = 0;
1574  int ret;
1575  AVStream *st;
1576 
1577  if (!genpts) {
1578  ret = si->packet_buffer.head
1581  if (ret < 0)
1582  return ret;
1583  goto return_packet;
1584  }
1585 
1586  for (;;) {
1587  PacketListEntry *pktl = si->packet_buffer.head;
1588 
1589  if (pktl) {
1590  AVPacket *next_pkt = &pktl->pkt;
1591 
1592  if (next_pkt->dts != AV_NOPTS_VALUE) {
1593  int wrap_bits = s->streams[next_pkt->stream_index]->pts_wrap_bits;
1594  // last dts seen for this stream. if any of packets following
1595  // current one had no dts, we will set this to AV_NOPTS_VALUE.
1596  int64_t last_dts = next_pkt->dts;
1597  av_assert2(wrap_bits <= 64);
1598  while (pktl && next_pkt->pts == AV_NOPTS_VALUE) {
1599  if (pktl->pkt.stream_index == next_pkt->stream_index &&
1600  av_compare_mod(next_pkt->dts, pktl->pkt.dts, 2ULL << (wrap_bits - 1)) < 0) {
1601  if (av_compare_mod(pktl->pkt.pts, pktl->pkt.dts, 2ULL << (wrap_bits - 1))) {
1602  // not B-frame
1603  next_pkt->pts = pktl->pkt.dts;
1604  }
1605  if (last_dts != AV_NOPTS_VALUE) {
1606  // Once last dts was set to AV_NOPTS_VALUE, we don't change it.
1607  last_dts = pktl->pkt.dts;
1608  }
1609  }
1610  pktl = pktl->next;
1611  }
1612  if (eof && next_pkt->pts == AV_NOPTS_VALUE && last_dts != AV_NOPTS_VALUE) {
1613  // Fixing the last reference frame had none pts issue (For MXF etc).
1614  // We only do this when
1615  // 1. eof.
1616  // 2. we are not able to resolve a pts value for current packet.
1617  // 3. the packets for this stream at the end of the files had valid dts.
1618  next_pkt->pts = last_dts + next_pkt->duration;
1619  }
1620  pktl = si->packet_buffer.head;
1621  }
1622 
1623  /* read packet from packet buffer, if there is data */
1624  st = s->streams[next_pkt->stream_index];
1625  if (!(next_pkt->pts == AV_NOPTS_VALUE && st->discard < AVDISCARD_ALL &&
1626  next_pkt->dts != AV_NOPTS_VALUE && !eof)) {
1628  goto return_packet;
1629  }
1630  }
1631 
1633  if (ret < 0) {
1634  if (pktl && ret != AVERROR(EAGAIN)) {
1635  eof = 1;
1636  continue;
1637  } else
1638  return ret;
1639  }
1640 
1642  pkt, NULL, 0);
1643  if (ret < 0) {
1645  return ret;
1646  }
1647  }
1648 
1649 return_packet:
1650  st = s->streams[pkt->stream_index];
1651  if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & AV_PKT_FLAG_KEY) {
1652  ff_reduce_index(s, st->index);
1654  }
1655 
1656  if (is_relative(pkt->dts))
1657  pkt->dts -= RELATIVE_TS_BASE;
1658  if (is_relative(pkt->pts))
1659  pkt->pts -= RELATIVE_TS_BASE;
1660 
1661  return ret;
1662 }
1663 
1664 /**
1665  * Return TRUE if the stream has accurate duration in any stream.
1666  *
1667  * @return TRUE if the stream has accurate duration for at least one component.
1668  */
1670 {
1671  for (unsigned i = 0; i < ic->nb_streams; i++) {
1672  const AVStream *const st = ic->streams[i];
1673  if (st->duration != AV_NOPTS_VALUE)
1674  return 1;
1675  }
1676  if (ic->duration != AV_NOPTS_VALUE)
1677  return 1;
1678  return 0;
1679 }
1680 
1681 /**
1682  * Estimate the stream timings from the one of each components.
1683  *
1684  * Also computes the global bitrate if possible.
1685  */
1687 {
1688  int64_t start_time, start_time1, start_time_text, end_time, end_time1, end_time_text;
1689  int64_t duration, duration1, duration_text, filesize;
1690 
1691  start_time = INT64_MAX;
1692  start_time_text = INT64_MAX;
1693  end_time = INT64_MIN;
1694  end_time_text = INT64_MIN;
1695  duration = INT64_MIN;
1696  duration_text = INT64_MIN;
1697 
1698  for (unsigned i = 0; i < ic->nb_streams; i++) {
1699  AVStream *const st = ic->streams[i];
1700  int is_text = st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE ||
1702 
1703  if (st->start_time != AV_NOPTS_VALUE && st->time_base.den) {
1704  start_time1 = av_rescale_q(st->start_time, st->time_base,
1705  AV_TIME_BASE_Q);
1706  if (is_text)
1707  start_time_text = FFMIN(start_time_text, start_time1);
1708  else
1709  start_time = FFMIN(start_time, start_time1);
1710  end_time1 = av_rescale_q_rnd(st->duration, st->time_base,
1713  if (end_time1 != AV_NOPTS_VALUE && (end_time1 > 0 ? start_time1 <= INT64_MAX - end_time1 : start_time1 >= INT64_MIN - end_time1)) {
1714  end_time1 += start_time1;
1715  if (is_text)
1716  end_time_text = FFMAX(end_time_text, end_time1);
1717  else
1718  end_time = FFMAX(end_time, end_time1);
1719  }
1720  for (AVProgram *p = NULL; (p = av_find_program_from_stream(ic, p, i)); ) {
1721  if (p->start_time == AV_NOPTS_VALUE || p->start_time > start_time1)
1722  p->start_time = start_time1;
1723  if (p->end_time < end_time1)
1724  p->end_time = end_time1;
1725  }
1726  }
1727  if (st->duration != AV_NOPTS_VALUE) {
1728  duration1 = av_rescale_q(st->duration, st->time_base,
1729  AV_TIME_BASE_Q);
1730  if (is_text)
1731  duration_text = FFMAX(duration_text, duration1);
1732  else
1733  duration = FFMAX(duration, duration1);
1734  }
1735  }
1736  if (start_time == INT64_MAX || (start_time > start_time_text && start_time - (uint64_t)start_time_text < AV_TIME_BASE))
1737  start_time = start_time_text;
1738  else if (start_time > start_time_text)
1739  av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream starttime %f\n", start_time_text / (float)AV_TIME_BASE);
1740 
1741  if (end_time == INT64_MIN || (end_time < end_time_text && end_time_text - (uint64_t)end_time < AV_TIME_BASE))
1742  end_time = end_time_text;
1743  else if (end_time < end_time_text)
1744  av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream endtime %f\n", end_time_text / (float)AV_TIME_BASE);
1745 
1746  if (duration == INT64_MIN || (duration < duration_text && (uint64_t)duration_text - duration < AV_TIME_BASE))
1747  duration = duration_text;
1748  else if (duration < duration_text)
1749  av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream duration %f\n", duration_text / (float)AV_TIME_BASE);
1750 
1751  if (start_time != INT64_MAX) {
1752  ic->start_time = start_time;
1753  if (end_time != INT64_MIN) {
1754  if (ic->nb_programs > 1) {
1755  for (unsigned i = 0; i < ic->nb_programs; i++) {
1756  AVProgram *const p = ic->programs[i];
1757 
1758  if (p->start_time != AV_NOPTS_VALUE &&
1759  p->end_time > p->start_time &&
1760  p->end_time - (uint64_t)p->start_time <= INT64_MAX)
1761  duration = FFMAX(duration, p->end_time - p->start_time);
1762  }
1763  } else if (end_time >= start_time && end_time - (uint64_t)start_time <= INT64_MAX) {
1764  duration = FFMAX(duration, end_time - start_time);
1765  }
1766  }
1767  }
1768  if (duration != INT64_MIN && duration > 0 && ic->duration == AV_NOPTS_VALUE) {
1769  ic->duration = duration;
1770  }
1771  if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration > 0) {
1772  /* compute the bitrate */
1773  double bitrate = (double) filesize * 8.0 * AV_TIME_BASE /
1774  (double) ic->duration;
1775  if (bitrate >= 0 && bitrate <= INT64_MAX)
1776  ic->bit_rate = bitrate;
1777  }
1778 }
1779 
1781 {
1783  for (unsigned i = 0; i < ic->nb_streams; i++) {
1784  AVStream *const st = ic->streams[i];
1785 
1786  if (st->start_time == AV_NOPTS_VALUE) {
1787  if (ic->start_time != AV_NOPTS_VALUE)
1789  st->time_base);
1790  if (ic->duration != AV_NOPTS_VALUE)
1792  st->time_base);
1793  }
1794  }
1795 }
1796 
1798 {
1799  FFFormatContext *const si = ffformatcontext(ic);
1800  int show_warning = 0;
1801 
1802  /* if bit_rate is already set, we believe it */
1803  if (ic->bit_rate <= 0) {
1804  int64_t bit_rate = 0;
1805  for (unsigned i = 0; i < ic->nb_streams; i++) {
1806  const AVStream *const st = ic->streams[i];
1807  const FFStream *const sti = cffstream(st);
1808  if (st->codecpar->bit_rate <= 0 && sti->avctx->bit_rate > 0)
1809  st->codecpar->bit_rate = sti->avctx->bit_rate;
1810  if (st->codecpar->bit_rate > 0) {
1811  if (INT64_MAX - st->codecpar->bit_rate < bit_rate) {
1812  bit_rate = 0;
1813  break;
1814  }
1815  bit_rate += st->codecpar->bit_rate;
1816  } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sti->codec_info_nb_frames > 1) {
1817  // If we have a videostream with packets but without a bitrate
1818  // then consider the sum not known
1819  bit_rate = 0;
1820  break;
1821  }
1822  }
1823  ic->bit_rate = bit_rate;
1824  }
1825 
1826  /* if duration is already set, we believe it */
1827  if (ic->duration == AV_NOPTS_VALUE &&
1828  ic->bit_rate != 0) {
1829  int64_t filesize = ic->pb ? avio_size(ic->pb) : 0;
1830  if (filesize > si->data_offset) {
1831  filesize -= si->data_offset;
1832  for (unsigned i = 0; i < ic->nb_streams; i++) {
1833  AVStream *const st = ic->streams[i];
1834 
1835  if ( st->time_base.num <= INT64_MAX / ic->bit_rate
1836  && st->duration == AV_NOPTS_VALUE) {
1837  st->duration = av_rescale(filesize, 8LL * st->time_base.den,
1838  ic->bit_rate *
1839  (int64_t) st->time_base.num);
1840  show_warning = 1;
1841  }
1842  }
1843  }
1844  }
1845  if (show_warning)
1846  av_log(ic, AV_LOG_WARNING,
1847  "Estimating duration from bitrate, this may be inaccurate\n");
1848 }
1849 
1850 #define DURATION_DEFAULT_MAX_READ_SIZE 250000LL
1851 #define DURATION_DEFAULT_MAX_RETRY 6
1852 #define DURATION_MAX_RETRY 1
1853 
1854 /* only usable for MPEG-PS streams */
1856 {
1857  FFFormatContext *const si = ffformatcontext(ic);
1858  AVPacket *const pkt = si->pkt;
1859  int num, den, read_size, ret;
1861  int duration_max_retry = ic->duration_probesize ? DURATION_MAX_RETRY : DURATION_DEFAULT_MAX_RETRY;
1862  int found_duration = 0;
1863  int is_end;
1865  int retry = 0;
1866 
1867  /* flush packet queue */
1869 
1870  for (unsigned i = 0; i < ic->nb_streams; i++) {
1871  AVStream *const st = ic->streams[i];
1872  FFStream *const sti = ffstream(st);
1873 
1874  if (st->start_time == AV_NOPTS_VALUE &&
1875  sti->first_dts == AV_NOPTS_VALUE &&
1877  av_log(ic, AV_LOG_WARNING,
1878  "start time for stream %d is not set in estimate_timings_from_pts\n", i);
1879 
1880  if (sti->parser) {
1881  av_parser_close(sti->parser);
1882  sti->parser = NULL;
1883  }
1884  }
1885 
1887  av_log(ic, AV_LOG_INFO, "Skipping duration calculation in estimate_timings_from_pts\n");
1888  goto skip_duration_calc;
1889  }
1890 
1891  av_opt_set_int(ic, "skip_changes", 1, AV_OPT_SEARCH_CHILDREN);
1892  /* estimate the end time (duration) */
1893  /* XXX: may need to support wrapping */
1894  filesize = ic->pb ? avio_size(ic->pb) : 0;
1895  do {
1896  is_end = found_duration;
1897  offset = filesize - (duration_max_read_size << retry);
1898  if (offset < 0)
1899  offset = 0;
1900 
1901  avio_seek(ic->pb, offset, SEEK_SET);
1902  read_size = 0;
1903  for (;;) {
1904  AVStream *st;
1905  FFStream *sti;
1906  if (read_size >= duration_max_read_size << (FFMAX(retry - 1, 0)))
1907  break;
1908 
1909  do {
1910  ret = ff_read_packet(ic, pkt);
1911  } while (ret == AVERROR(EAGAIN));
1912  if (ret != 0)
1913  break;
1914  read_size += pkt->size;
1915  st = ic->streams[pkt->stream_index];
1916  sti = ffstream(st);
1917  if (pkt->pts != AV_NOPTS_VALUE &&
1918  (st->start_time != AV_NOPTS_VALUE ||
1919  sti->first_dts != AV_NOPTS_VALUE)) {
1920  if (pkt->duration == 0) {
1921  compute_frame_duration(ic, &num, &den, st, sti->parser, pkt);
1922  if (den && num) {
1924  num * (int64_t) st->time_base.den,
1925  den * (int64_t) st->time_base.num,
1926  AV_ROUND_DOWN);
1927  }
1928  }
1929  duration = pkt->pts + pkt->duration;
1930  found_duration = 1;
1931  if (st->start_time != AV_NOPTS_VALUE)
1932  duration -= st->start_time;
1933  else
1934  duration -= sti->first_dts;
1935  if (duration > 0) {
1936  if (st->duration == AV_NOPTS_VALUE || sti->info->last_duration<= 0 ||
1937  (st->duration < duration && FFABS(duration - sti->info->last_duration) < 60LL*st->time_base.den / st->time_base.num))
1938  st->duration = duration;
1939  sti->info->last_duration = duration;
1940  }
1941  }
1943  }
1944 
1945  /* check if all audio/video streams have valid duration */
1946  if (!is_end) {
1947  is_end = 1;
1948  for (unsigned i = 0; i < ic->nb_streams; i++) {
1949  const AVStream *const st = ic->streams[i];
1950  switch (st->codecpar->codec_type) {
1951  case AVMEDIA_TYPE_VIDEO:
1952  case AVMEDIA_TYPE_AUDIO:
1953  if (st->duration == AV_NOPTS_VALUE)
1954  is_end = 0;
1955  }
1956  }
1957  }
1958  } while (!is_end &&
1959  offset &&
1960  ++retry <= duration_max_retry);
1961 
1962  av_opt_set_int(ic, "skip_changes", 0, AV_OPT_SEARCH_CHILDREN);
1963 
1964  /* warn about audio/video streams which duration could not be estimated */
1965  for (unsigned i = 0; i < ic->nb_streams; i++) {
1966  const AVStream *const st = ic->streams[i];
1967  const FFStream *const sti = cffstream(st);
1968 
1969  if (st->duration == AV_NOPTS_VALUE) {
1970  switch (st->codecpar->codec_type) {
1971  case AVMEDIA_TYPE_VIDEO:
1972  case AVMEDIA_TYPE_AUDIO:
1973  if (st->start_time != AV_NOPTS_VALUE || sti->first_dts != AV_NOPTS_VALUE) {
1974  av_log(ic, AV_LOG_WARNING, "stream %d : no PTS found at end of file, duration not set\n", i);
1975  } else
1976  av_log(ic, AV_LOG_WARNING, "stream %d : no TS found at start of file, duration not set\n", i);
1977  }
1978  }
1979  }
1980 skip_duration_calc:
1982 
1983  avio_seek(ic->pb, old_offset, SEEK_SET);
1984  for (unsigned i = 0; i < ic->nb_streams; i++) {
1985  AVStream *const st = ic->streams[i];
1986  FFStream *const sti = ffstream(st);
1987 
1988  sti->cur_dts = sti->first_dts;
1989  sti->last_IP_pts = AV_NOPTS_VALUE;
1991  for (int j = 0; j < MAX_REORDER_DELAY + 1; j++)
1992  sti->pts_buffer[j] = AV_NOPTS_VALUE;
1993  }
1994 }
1995 
1996 /* 1:1 map to AVDurationEstimationMethod */
1997 static const char *const duration_name[] = {
1998  [AVFMT_DURATION_FROM_PTS] = "pts",
1999  [AVFMT_DURATION_FROM_STREAM] = "stream",
2000  [AVFMT_DURATION_FROM_BITRATE] = "bit rate",
2001 };
2002 
2004 {
2005  return duration_name[method];
2006 }
2007 
2008 static void estimate_timings(AVFormatContext *ic, int64_t old_offset)
2009 {
2010  int64_t file_size;
2011 
2012  /* get the file size, if possible */
2013  if (ic->iformat->flags & AVFMT_NOFILE) {
2014  file_size = 0;
2015  } else {
2016  file_size = avio_size(ic->pb);
2017  file_size = FFMAX(0, file_size);
2018  }
2019 
2020  if ((!strcmp(ic->iformat->name, "mpeg") ||
2021  !strcmp(ic->iformat->name, "mpegts")) &&
2022  file_size && (ic->pb->seekable & AVIO_SEEKABLE_NORMAL)) {
2023  /* get accurate estimate from the PTSes */
2024  estimate_timings_from_pts(ic, old_offset);
2026  } else if (has_duration(ic)) {
2027  /* at least one component has timings - we use them for all
2028  * the components */
2030  /* nut demuxer estimate the duration from PTS */
2031  if (!strcmp(ic->iformat->name, "nut"))
2033  else
2035  } else {
2036  /* less precise: use bitrate info */
2039  }
2041 
2042  for (unsigned i = 0; i < ic->nb_streams; i++) {
2043  AVStream *const st = ic->streams[i];
2044  if (st->time_base.den)
2045  av_log(ic, AV_LOG_TRACE, "stream %u: start_time: %s duration: %s\n", i,
2046  av_ts2timestr(st->start_time, &st->time_base),
2047  av_ts2timestr(st->duration, &st->time_base));
2048  }
2049  av_log(ic, AV_LOG_TRACE,
2050  "format: start_time: %s duration: %s (estimate from %s) bitrate=%"PRId64" kb/s\n",
2054  (int64_t)ic->bit_rate / 1000);
2055 }
2056 
2057 static int determinable_frame_size(const AVCodecContext *avctx)
2058 {
2059  switch(avctx->codec_id) {
2060  case AV_CODEC_ID_MP1:
2061  case AV_CODEC_ID_MP2:
2062  case AV_CODEC_ID_MP3:
2063  case AV_CODEC_ID_CODEC2:
2064  return 1;
2065  }
2066 
2067  return 0;
2068 }
2069 
2070 static int has_codec_parameters(const AVStream *st, const char **errmsg_ptr)
2071 {
2072  const FFStream *const sti = cffstream(st);
2073  const AVCodecContext *const avctx = sti->avctx;
2074 
2075 #define FAIL(errmsg) do { \
2076  if (errmsg_ptr) \
2077  *errmsg_ptr = errmsg; \
2078  return 0; \
2079  } while (0)
2080 
2081  if ( avctx->codec_id == AV_CODEC_ID_NONE
2082  && avctx->codec_type != AVMEDIA_TYPE_DATA)
2083  FAIL("unknown codec");
2084  switch (avctx->codec_type) {
2085  case AVMEDIA_TYPE_AUDIO:
2086  if (!avctx->frame_size && determinable_frame_size(avctx))
2087  FAIL("unspecified frame size");
2088  if (sti->info->found_decoder >= 0 &&
2089  avctx->sample_fmt == AV_SAMPLE_FMT_NONE)
2090  FAIL("unspecified sample format");
2091  if (!avctx->sample_rate)
2092  FAIL("unspecified sample rate");
2093  if (!avctx->ch_layout.nb_channels)
2094  FAIL("unspecified number of channels");
2095  if (sti->info->found_decoder >= 0 && !sti->nb_decoded_frames && avctx->codec_id == AV_CODEC_ID_DTS)
2096  FAIL("no decodable DTS frames");
2097  break;
2098  case AVMEDIA_TYPE_VIDEO:
2099  if (!avctx->width)
2100  FAIL("unspecified size");
2101  if (sti->info->found_decoder >= 0 && avctx->pix_fmt == AV_PIX_FMT_NONE)
2102  FAIL("unspecified pixel format");
2105  FAIL("no frame in rv30/40 and no sar");
2106  break;
2107  case AVMEDIA_TYPE_SUBTITLE:
2108  if (avctx->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE && !avctx->width)
2109  FAIL("unspecified size");
2110  break;
2111  case AVMEDIA_TYPE_DATA:
2112  if (avctx->codec_id == AV_CODEC_ID_NONE) return 1;
2113  }
2114 
2115  return 1;
2116 }
2117 
2118 /* returns 1 or 0 if or if not decoded data was returned, or a negative error */
2120  const AVPacket *pkt, AVDictionary **options)
2121 {
2122  FFStream *const sti = ffstream(st);
2123  AVCodecContext *const avctx = sti->avctx;
2124  const AVCodec *codec;
2125  int got_picture = 1, ret = 0;
2127  AVSubtitle subtitle;
2128  int do_skip_frame = 0;
2129  enum AVDiscard skip_frame;
2130  int pkt_to_send = pkt->size > 0;
2131 
2132  if (!frame)
2133  return AVERROR(ENOMEM);
2134 
2135  if (!avcodec_is_open(avctx) &&
2136  sti->info->found_decoder <= 0 &&
2137  (st->codecpar->codec_id != -sti->info->found_decoder || !st->codecpar->codec_id)) {
2138  AVDictionary *thread_opt = NULL;
2139 
2140  codec = find_probe_decoder(s, st, st->codecpar->codec_id);
2141 
2142  if (!codec) {
2143  sti->info->found_decoder = -st->codecpar->codec_id;
2144  ret = -1;
2145  goto fail;
2146  }
2147 
2148  /* Force thread count to 1 since the H.264 decoder will not extract
2149  * SPS and PPS to extradata during multi-threaded decoding. */
2150  av_dict_set(options ? options : &thread_opt, "threads", "1", 0);
2151  /* Force lowres to 0. The decoder might reduce the video size by the
2152  * lowres factor, and we don't want that propagated to the stream's
2153  * codecpar */
2154  av_dict_set(options ? options : &thread_opt, "lowres", "0", 0);
2155  if (s->codec_whitelist)
2156  av_dict_set(options ? options : &thread_opt, "codec_whitelist", s->codec_whitelist, 0);
2157  ret = avcodec_open2(avctx, codec, options ? options : &thread_opt);
2158  if (!options)
2159  av_dict_free(&thread_opt);
2160  if (ret < 0) {
2161  sti->info->found_decoder = -avctx->codec_id;
2162  goto fail;
2163  }
2164  sti->info->found_decoder = 1;
2165  } else if (!sti->info->found_decoder)
2166  sti->info->found_decoder = 1;
2167 
2168  if (sti->info->found_decoder < 0) {
2169  ret = -1;
2170  goto fail;
2171  }
2172 
2174  do_skip_frame = 1;
2175  skip_frame = avctx->skip_frame;
2176  avctx->skip_frame = AVDISCARD_ALL;
2177  }
2178 
2179  while ((pkt_to_send || (!pkt->data && got_picture)) &&
2180  ret >= 0 &&
2182  (!sti->codec_info_nb_frames &&
2184  got_picture = 0;
2185  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO ||
2186  avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
2187  ret = avcodec_send_packet(avctx, pkt);
2188  if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
2189  break;
2190  if (ret >= 0)
2191  pkt_to_send = 0;
2192  ret = avcodec_receive_frame(avctx, frame);
2193  if (ret >= 0)
2194  got_picture = 1;
2195  if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
2196  ret = 0;
2197  } else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
2198  ret = avcodec_decode_subtitle2(avctx, &subtitle,
2199  &got_picture, pkt);
2200  if (got_picture)
2201  avsubtitle_free(&subtitle);
2202  if (ret >= 0)
2203  pkt_to_send = 0;
2204  }
2205  if (ret >= 0) {
2206  if (got_picture)
2207  sti->nb_decoded_frames++;
2208  ret = got_picture;
2209  }
2210  }
2211 
2212 fail:
2213  if (do_skip_frame) {
2214  avctx->skip_frame = skip_frame;
2215  }
2216 
2217  av_frame_free(&frame);
2218  return ret;
2219 }
2220 
2221 static int chapter_start_cmp(const void *p1, const void *p2)
2222 {
2223  const AVChapter *const ch1 = *(AVChapter**)p1;
2224  const AVChapter *const ch2 = *(AVChapter**)p2;
2225  int delta = av_compare_ts(ch1->start, ch1->time_base, ch2->start, ch2->time_base);
2226  if (delta)
2227  return delta;
2228  return FFDIFFSIGN(ch1->id, ch2->id);
2229 }
2230 
2232 {
2233  int64_t max_time = 0;
2234  AVChapter **timetable;
2235 
2236  if (!s->nb_chapters)
2237  return 0;
2238 
2239  if (s->duration > 0 && s->start_time < INT64_MAX - s->duration)
2240  max_time = s->duration +
2241  ((s->start_time == AV_NOPTS_VALUE) ? 0 : s->start_time);
2242 
2243  timetable = av_memdup(s->chapters, s->nb_chapters * sizeof(*timetable));
2244  if (!timetable)
2245  return AVERROR(ENOMEM);
2246  qsort(timetable, s->nb_chapters, sizeof(*timetable), chapter_start_cmp);
2247 
2248  for (unsigned i = 0; i < s->nb_chapters; i++)
2249  if (timetable[i]->end == AV_NOPTS_VALUE) {
2250  AVChapter *const ch = timetable[i];
2251  int64_t end = max_time ? av_rescale_q(max_time, AV_TIME_BASE_Q,
2252  ch->time_base)
2253  : INT64_MAX;
2254 
2255  if (i + 1 < s->nb_chapters) {
2256  const AVChapter *const ch1 = timetable[i + 1];
2257  int64_t next_start = av_rescale_q(ch1->start, ch1->time_base,
2258  ch->time_base);
2259  if (next_start > ch->start && next_start < end)
2260  end = next_start;
2261  }
2262  ch->end = (end == INT64_MAX || end < ch->start) ? ch->start : end;
2263  }
2264  av_free(timetable);
2265  return 0;
2266 }
2267 
2268 static int get_std_framerate(int i)
2269 {
2270  if (i < 30*12)
2271  return (i + 1) * 1001;
2272  i -= 30*12;
2273 
2274  if (i < 30)
2275  return (i + 31) * 1001 * 12;
2276  i -= 30;
2277 
2278  if (i < 3)
2279  return ((const int[]) { 80, 120, 240})[i] * 1001 * 12;
2280 
2281  i -= 3;
2282 
2283  return ((const int[]) { 24, 30, 60, 12, 15, 48 })[i] * 1000 * 12;
2284 }
2285 
2286 /* Is the time base unreliable?
2287  * This is a heuristic to balance between quick acceptance of the values in
2288  * the headers vs. some extra checks.
2289  * Old DivX and Xvid often have nonsense timebases like 1fps or 2fps.
2290  * MPEG-2 commonly misuses field repeat flags to store different framerates.
2291  * And there are "variable" fps files this needs to detect as well. */
2293 {
2294  FFStream *const sti = ffstream(st);
2295  const AVCodecDescriptor *desc = sti->codec_desc;
2296  AVCodecContext *c = sti->avctx;
2297  AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 };
2298  AVRational time_base = c->framerate.num ? av_inv_q(av_mul_q(c->framerate, mul))
2299  /* NOHEADER check added to not break existing behavior */
2300  : (((ic->ctx_flags & AVFMTCTX_NOHEADER) ||
2302  : st->time_base);
2303 
2304  if (time_base.den >= 101LL * time_base.num ||
2305  time_base.den < 5LL * time_base.num ||
2306  // c->codec_tag == AV_RL32("DIVX") ||
2307  // c->codec_tag == AV_RL32("XVID") ||
2308  c->codec_tag == AV_RL32("mp4v") ||
2309  c->codec_id == AV_CODEC_ID_MPEG2VIDEO ||
2310  c->codec_id == AV_CODEC_ID_GIF ||
2311  c->codec_id == AV_CODEC_ID_HEVC ||
2312  c->codec_id == AV_CODEC_ID_H264)
2313  return 1;
2314  return 0;
2315 }
2316 
2318 {
2319  FFStream *const sti = ffstream(st);
2320  FFStreamInfo *info = sti->info;
2321  int64_t last = info->last_dts;
2322 
2323  if ( ts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && ts > last
2324  && ts - (uint64_t)last < INT64_MAX) {
2325  double dts = (is_relative(ts) ? ts - RELATIVE_TS_BASE : ts) * av_q2d(st->time_base);
2326  int64_t duration = ts - last;
2327 
2328  if (!info->duration_error)
2329  info->duration_error = av_mallocz(sizeof(info->duration_error[0])*2);
2330  if (!info->duration_error)
2331  return AVERROR(ENOMEM);
2332 
2333 // if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
2334 // av_log(NULL, AV_LOG_ERROR, "%f\n", dts);
2335  for (int i = 0; i < MAX_STD_TIMEBASES; i++) {
2336  if (info->duration_error[0][1][i] < 1e10) {
2337  int framerate = get_std_framerate(i);
2338  double sdts = dts*framerate/(1001*12);
2339  for (int j = 0; j < 2; j++) {
2340  int64_t ticks = llrint(sdts+j*0.5);
2341  double error = sdts - ticks + j*0.5;
2342  info->duration_error[j][0][i] += error;
2343  info->duration_error[j][1][i] += error*error;
2344  }
2345  }
2346  }
2347  if (info->rfps_duration_sum <= INT64_MAX - duration) {
2348  info->duration_count++;
2349  info->rfps_duration_sum += duration;
2350  }
2351 
2352  if (info->duration_count % 10 == 0) {
2353  int n = info->duration_count;
2354  for (int i = 0; i < MAX_STD_TIMEBASES; i++) {
2355  if (info->duration_error[0][1][i] < 1e10) {
2356  double a0 = info->duration_error[0][0][i] / n;
2357  double error0 = info->duration_error[0][1][i] / n - a0*a0;
2358  double a1 = info->duration_error[1][0][i] / n;
2359  double error1 = info->duration_error[1][1][i] / n - a1*a1;
2360  if (error0 > 0.04 && error1 > 0.04) {
2361  info->duration_error[0][1][i] = 2e10;
2362  info->duration_error[1][1][i] = 2e10;
2363  }
2364  }
2365  }
2366  }
2367 
2368  // ignore the first 4 values, they might have some random jitter
2369  if (info->duration_count > 3 && is_relative(ts) == is_relative(last))
2370  info->duration_gcd = av_gcd(info->duration_gcd, duration);
2371  }
2372  if (ts != AV_NOPTS_VALUE)
2373  info->last_dts = ts;
2374 
2375  return 0;
2376 }
2377 
2379 {
2380  for (unsigned i = 0; i < ic->nb_streams; i++) {
2381  AVStream *const st = ic->streams[i];
2382  FFStream *const sti = ffstream(st);
2383 
2385  continue;
2386  // the check for tb_unreliable() is not completely correct, since this is not about handling
2387  // an unreliable/inexact time base, but a time base that is finer than necessary, as e.g.
2388  // ipmovie.c produces.
2389  if (tb_unreliable(ic, st) && sti->info->duration_count > 15 && sti->info->duration_gcd > FFMAX(1, st->time_base.den/(500LL*st->time_base.num)) && !st->r_frame_rate.num &&
2390  sti->info->duration_gcd < INT64_MAX / st->time_base.num)
2391  av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time_base.den, st->time_base.num * sti->info->duration_gcd, INT_MAX);
2392  if (sti->info->duration_count > 1 && !st->r_frame_rate.num
2393  && tb_unreliable(ic, st)) {
2394  int num = 0;
2395  double best_error = 0.01;
2396  AVRational ref_rate = st->r_frame_rate.num ? st->r_frame_rate : av_inv_q(st->time_base);
2397 
2398  for (int j = 0; j < MAX_STD_TIMEBASES; j++) {
2399  if (sti->info->codec_info_duration &&
2400  sti->info->codec_info_duration*av_q2d(st->time_base) < (1001*11.5)/get_std_framerate(j))
2401  continue;
2402  if (!sti->info->codec_info_duration && get_std_framerate(j) < 1001*12)
2403  continue;
2404 
2405  if (av_q2d(st->time_base) * sti->info->rfps_duration_sum / sti->info->duration_count < (1001*12.0 * 0.8)/get_std_framerate(j))
2406  continue;
2407 
2408  for (int k = 0; k < 2; k++) {
2409  int n = sti->info->duration_count;
2410  double a = sti->info->duration_error[k][0][j] / n;
2411  double error = sti->info->duration_error[k][1][j]/n - a*a;
2412 
2413  if (error < best_error && best_error> 0.000000001) {
2414  best_error= error;
2415  num = get_std_framerate(j);
2416  }
2417  if (error < 0.02)
2418  av_log(ic, AV_LOG_DEBUG, "rfps: %f %f\n", get_std_framerate(j) / 12.0/1001, error);
2419  }
2420  }
2421  // do not increase frame rate by more than 1 % in order to match a standard rate.
2422  if (num && (!ref_rate.num || (double)num/(12*1001) < 1.01 * av_q2d(ref_rate)))
2423  av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, 12*1001, INT_MAX);
2424  }
2425  if ( !st->avg_frame_rate.num
2426  && st->r_frame_rate.num && sti->info->rfps_duration_sum
2427  && sti->info->codec_info_duration <= 0
2428  && sti->info->duration_count > 2
2429  && fabs(1.0 / (av_q2d(st->r_frame_rate) * av_q2d(st->time_base)) - sti->info->rfps_duration_sum / (double)sti->info->duration_count) <= 1.0
2430  ) {
2431  av_log(ic, AV_LOG_DEBUG, "Setting avg frame rate based on r frame rate\n");
2432  st->avg_frame_rate = st->r_frame_rate;
2433  }
2434 
2435  av_freep(&sti->info->duration_error);
2436  sti->info->last_dts = AV_NOPTS_VALUE;
2437  sti->info->duration_count = 0;
2438  sti->info->rfps_duration_sum = 0;
2439  }
2440 }
2441 
2443 {
2444  const AVBitStreamFilter *const f = av_bsf_get_by_name("extract_extradata");
2445  if (!f)
2446  return 0;
2447 
2448  if (f->codec_ids) {
2449  const enum AVCodecID *ids;
2450  for (ids = f->codec_ids; *ids != AV_CODEC_ID_NONE; ids++)
2451  if (*ids == st->codecpar->codec_id)
2452  return 1;
2453  }
2454 
2455  return 0;
2456 }
2457 
2459 {
2460  FFStream *const sti = ffstream(st);
2461  const AVBitStreamFilter *f;
2462  int ret;
2463 
2464  f = av_bsf_get_by_name("extract_extradata");
2465  if (!f)
2466  goto finish;
2467 
2468  /* check that the codec id is supported */
2470  if (!ret)
2471  goto finish;
2472 
2475  if (ret < 0)
2476  return ret;
2477 
2479  st->codecpar);
2480  if (ret < 0)
2481  goto fail;
2482 
2484 
2486  if (ret < 0)
2487  goto fail;
2488 
2489 finish:
2490  sti->extract_extradata.inited = 1;
2491 
2492  return 0;
2493 fail:
2495  return ret;
2496 }
2497 
2499 {
2500  FFStream *const sti = ffstream(st);
2501  AVPacket *const pkt_ref = si->parse_pkt;
2502  int ret;
2503 
2504  if (!sti->extract_extradata.inited) {
2506  if (ret < 0)
2507  return ret;
2508  }
2509 
2510  if (sti->extract_extradata.inited && !sti->extract_extradata.bsf)
2511  return 0;
2512 
2513  ret = av_packet_ref(pkt_ref, pkt);
2514  if (ret < 0)
2515  return ret;
2516 
2517  ret = av_bsf_send_packet(sti->extract_extradata.bsf, pkt_ref);
2518  if (ret < 0) {
2519  av_packet_unref(pkt_ref);
2520  return ret;
2521  }
2522 
2523  while (ret >= 0 && !sti->avctx->extradata) {
2525  if (ret < 0) {
2526  if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
2527  return ret;
2528  continue;
2529  }
2530 
2531  for (int i = 0; i < pkt_ref->side_data_elems; i++) {
2532  AVPacketSideData *const side_data = &pkt_ref->side_data[i];
2533  if (side_data->type == AV_PKT_DATA_NEW_EXTRADATA) {
2534  sti->avctx->extradata = side_data->data;
2535  sti->avctx->extradata_size = side_data->size;
2536  side_data->data = NULL;
2537  side_data->size = 0;
2538  break;
2539  }
2540  }
2541  av_packet_unref(pkt_ref);
2542  }
2543 
2544  return 0;
2545 }
2546 
2548  const AVCodecContext *avctx)
2549 {
2550  AVCodecParameters *par_tmp;
2551  int ret;
2552 
2553  par_tmp = avcodec_parameters_alloc();
2554  if (!par_tmp)
2555  return AVERROR(ENOMEM);
2556 
2557  ret = avcodec_parameters_copy(par_tmp, par);
2558  if (ret < 0)
2559  goto fail;
2560 
2561  ret = avcodec_parameters_from_context(par, avctx);
2562  if (ret < 0)
2563  goto fail;
2564 
2565  /* Restore some values if they are signaled at the container level
2566  * given they may have been replaced by codec level values as read
2567  * internally by avformat_find_stream_info().
2568  */
2569  if (par_tmp->color_range != AVCOL_RANGE_UNSPECIFIED)
2570  par->color_range = par_tmp->color_range;
2571  if (par_tmp->color_primaries != AVCOL_PRI_UNSPECIFIED ||
2572  par_tmp->color_trc != AVCOL_TRC_UNSPECIFIED ||
2573  par_tmp->color_space != AVCOL_SPC_UNSPECIFIED) {
2574  par->color_primaries = par_tmp->color_primaries;
2575  par->color_trc = par_tmp->color_trc;
2576  par->color_space = par_tmp->color_space;
2577  }
2578  if (par_tmp->chroma_location != AVCHROMA_LOC_UNSPECIFIED)
2579  par->chroma_location = par_tmp->chroma_location;
2580 
2581  ret = 0;
2582 fail:
2583  avcodec_parameters_free(&par_tmp);
2584 
2585  return ret;
2586 }
2587 
2589 {
2590  FFFormatContext *const si = ffformatcontext(ic);
2591  int count = 0, ret = 0, err;
2592  int64_t read_size;
2593  AVPacket *pkt1 = si->pkt;
2594  int64_t old_offset = avio_tell(ic->pb);
2595  // new streams might appear, no options for those
2596  int orig_nb_streams = ic->nb_streams;
2597  int flush_codecs;
2598  int64_t max_analyze_duration = ic->max_analyze_duration;
2599  int64_t max_stream_analyze_duration;
2600  int64_t max_subtitle_analyze_duration;
2601  int64_t probesize = ic->probesize;
2602  int eof_reached = 0;
2603 
2604  flush_codecs = probesize > 0;
2605 
2606  av_opt_set_int(ic, "skip_clear", 1, AV_OPT_SEARCH_CHILDREN);
2607 
2608  max_stream_analyze_duration = max_analyze_duration;
2609  max_subtitle_analyze_duration = max_analyze_duration;
2610  if (!max_analyze_duration) {
2611  max_stream_analyze_duration =
2612  max_analyze_duration = 5*AV_TIME_BASE;
2613  max_subtitle_analyze_duration = 30*AV_TIME_BASE;
2614  if (!strcmp(ic->iformat->name, "flv"))
2615  max_stream_analyze_duration = 90*AV_TIME_BASE;
2616  if (!strcmp(ic->iformat->name, "mpeg") || !strcmp(ic->iformat->name, "mpegts"))
2617  max_stream_analyze_duration = 7*AV_TIME_BASE;
2618  }
2619 
2620  if (ic->pb) {
2621  FFIOContext *const ctx = ffiocontext(ic->pb);
2622  av_log(ic, AV_LOG_DEBUG, "Before avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d nb_streams:%d\n",
2623  avio_tell(ic->pb), ctx->bytes_read, ctx->seek_count, ic->nb_streams);
2624  }
2625 
2626  for (unsigned i = 0; i < ic->nb_streams; i++) {
2627  const AVCodec *codec;
2628  AVDictionary *thread_opt = NULL;
2629  AVStream *const st = ic->streams[i];
2630  FFStream *const sti = ffstream(st);
2631  AVCodecContext *const avctx = sti->avctx;
2632 
2633  /* check if the caller has overridden the codec id */
2634  // only for the split stuff
2635  if (!sti->parser && !(ic->flags & AVFMT_FLAG_NOPARSE) && sti->request_probe <= 0) {
2636  sti->parser = av_parser_init(st->codecpar->codec_id);
2637  if (sti->parser) {
2638  if (sti->need_parsing == AVSTREAM_PARSE_HEADERS) {
2640  } else if (sti->need_parsing == AVSTREAM_PARSE_FULL_RAW) {
2642  }
2643  } else if (sti->need_parsing) {
2644  av_log(ic, AV_LOG_VERBOSE, "parser not found for codec "
2645  "%s, packets or times may be invalid.\n",
2647  }
2648  }
2649 
2651  if (ret < 0)
2652  goto find_stream_info_err;
2653  if (sti->request_probe <= 0)
2654  sti->avctx_inited = 1;
2655 
2656  codec = find_probe_decoder(ic, st, st->codecpar->codec_id);
2657 
2658  /* Force thread count to 1 since the H.264 decoder will not extract
2659  * SPS and PPS to extradata during multi-threaded decoding. */
2660  av_dict_set(options ? &options[i] : &thread_opt, "threads", "1", 0);
2661  /* Force lowres to 0. The decoder might reduce the video size by the
2662  * lowres factor, and we don't want that propagated to the stream's
2663  * codecpar */
2664  av_dict_set(options ? &options[i] : &thread_opt, "lowres", "0", 0);
2665 
2666  if (ic->codec_whitelist)
2667  av_dict_set(options ? &options[i] : &thread_opt, "codec_whitelist", ic->codec_whitelist, 0);
2668 
2669  // Try to just open decoders, in case this is enough to get parameters.
2670  // Also ensure that subtitle_header is properly set.
2671  if (!has_codec_parameters(st, NULL) && sti->request_probe <= 0 ||
2673  if (codec && !avctx->codec)
2674  if (avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt) < 0)
2675  av_log(ic, AV_LOG_WARNING,
2676  "Failed to open codec in %s\n", __func__);
2677  }
2678  if (!options)
2679  av_dict_free(&thread_opt);
2680  }
2681 
2682  read_size = 0;
2683  for (;;) {
2684  const AVPacket *pkt;
2685  AVStream *st;
2686  FFStream *sti;
2687  AVCodecContext *avctx;
2688  int analyzed_all_streams;
2689  unsigned i;
2691  ret = AVERROR_EXIT;
2692  av_log(ic, AV_LOG_DEBUG, "interrupted\n");
2693  break;
2694  }
2695 
2696  /* read_frame_internal() in a previous iteration of this loop may
2697  * have made changes to streams without returning a packet for them.
2698  * Handle that here. */
2699  ret = update_stream_avctx(ic);
2700  if (ret < 0)
2701  goto unref_then_goto_end;
2702 
2703  /* check if one codec still needs to be handled */
2704  for (i = 0; i < ic->nb_streams; i++) {
2705  AVStream *const st = ic->streams[i];
2706  FFStream *const sti = ffstream(st);
2707  int fps_analyze_framecount = 20;
2708  int count;
2709 
2710  if (!has_codec_parameters(st, NULL))
2711  break;
2712  /* If the timebase is coarse (like the usual millisecond precision
2713  * of mkv), we need to analyze more frames to reliably arrive at
2714  * the correct fps. */
2715  if (av_q2d(st->time_base) > 0.0005)
2716  fps_analyze_framecount *= 2;
2717  if (!tb_unreliable(ic, st))
2718  fps_analyze_framecount = 0;
2719  if (ic->fps_probe_size >= 0)
2720  fps_analyze_framecount = ic->fps_probe_size;
2722  fps_analyze_framecount = 0;
2723  /* variable fps and no guess at the real fps */
2724  count = (ic->iformat->flags & AVFMT_NOTIMESTAMPS) ?
2726  sti->info->duration_count;
2727  if (!(st->r_frame_rate.num && st->avg_frame_rate.num) &&
2729  if (count < fps_analyze_framecount)
2730  break;
2731  }
2732  // Look at the first 3 frames if there is evidence of frame delay
2733  // but the decoder delay is not set.
2734  if (sti->info->frame_delay_evidence && count < 2 && sti->avctx->has_b_frames == 0)
2735  break;
2736  if (!sti->avctx->extradata &&
2737  (!sti->extract_extradata.inited || sti->extract_extradata.bsf) &&
2739  break;
2740  if (sti->first_dts == AV_NOPTS_VALUE &&
2745  break;
2746  }
2747  analyzed_all_streams = 0;
2748  if (i == ic->nb_streams && !si->missing_streams) {
2749  analyzed_all_streams = 1;
2750  /* NOTE: If the format has no header, then we need to read some
2751  * packets to get most of the streams, so we cannot stop here. */
2752  if (!(ic->ctx_flags & AVFMTCTX_NOHEADER)) {
2753  /* If we found the info for all the codecs, we can stop. */
2754  ret = count;
2755  av_log(ic, AV_LOG_DEBUG, "All info found\n");
2756  flush_codecs = 0;
2757  break;
2758  }
2759  }
2760  /* We did not get all the codec info, but we read too much data. */
2761  if (read_size >= probesize) {
2762  ret = count;
2763  av_log(ic, AV_LOG_DEBUG,
2764  "Probe buffer size limit of %"PRId64" bytes reached\n", probesize);
2765  for (unsigned i = 0; i < ic->nb_streams; i++) {
2766  AVStream *const st = ic->streams[i];
2767  FFStream *const sti = ffstream(st);
2768  if (!st->r_frame_rate.num &&
2769  sti->info->duration_count <= 1 &&
2771  strcmp(ic->iformat->name, "image2"))
2772  av_log(ic, AV_LOG_WARNING,
2773  "Stream #%d: not enough frames to estimate rate; "
2774  "consider increasing probesize\n", i);
2775  }
2776  break;
2777  }
2778 
2779  /* NOTE: A new stream can be added there if no header in file
2780  * (AVFMTCTX_NOHEADER). */
2781  ret = read_frame_internal(ic, pkt1);
2782  if (ret == AVERROR(EAGAIN))
2783  continue;
2784 
2785  if (ret < 0) {
2786  /* EOF or error*/
2787  eof_reached = 1;
2788  break;
2789  }
2790 
2791  if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) {
2793  pkt1, NULL, 0);
2794  if (ret < 0)
2795  goto unref_then_goto_end;
2796 
2797  pkt = &si->packet_buffer.tail->pkt;
2798  } else {
2799  pkt = pkt1;
2800  }
2801 
2802  st = ic->streams[pkt->stream_index];
2803  sti = ffstream(st);
2805  read_size += pkt->size;
2806 
2807  avctx = sti->avctx;
2808  if (!sti->avctx_inited) {
2810  if (ret < 0)
2811  goto unref_then_goto_end;
2812  sti->avctx_inited = 1;
2813  }
2814 
2815  if (pkt->dts != AV_NOPTS_VALUE && sti->codec_info_nb_frames > 1) {
2816  /* check for non-increasing dts */
2817  if (sti->info->fps_last_dts != AV_NOPTS_VALUE &&
2818  sti->info->fps_last_dts >= pkt->dts) {
2819  av_log(ic, AV_LOG_DEBUG,
2820  "Non-increasing DTS in stream %d: packet %d with DTS "
2821  "%"PRId64", packet %d with DTS %"PRId64"\n",
2822  st->index, sti->info->fps_last_dts_idx,
2824  pkt->dts);
2825  sti->info->fps_first_dts =
2827  }
2828  /* Check for a discontinuity in dts. If the difference in dts
2829  * is more than 1000 times the average packet duration in the
2830  * sequence, we treat it as a discontinuity. */
2831  if (sti->info->fps_last_dts != AV_NOPTS_VALUE &&
2832  sti->info->fps_last_dts_idx > sti->info->fps_first_dts_idx &&
2833  (pkt->dts - (uint64_t)sti->info->fps_last_dts) / 1000 >
2834  (sti->info->fps_last_dts - (uint64_t)sti->info->fps_first_dts) /
2835  (sti->info->fps_last_dts_idx - sti->info->fps_first_dts_idx)) {
2836  av_log(ic, AV_LOG_WARNING,
2837  "DTS discontinuity in stream %d: packet %d with DTS "
2838  "%"PRId64", packet %d with DTS %"PRId64"\n",
2839  st->index, sti->info->fps_last_dts_idx,
2841  pkt->dts);
2842  sti->info->fps_first_dts =
2844  }
2845 
2846  /* update stored dts values */
2847  if (sti->info->fps_first_dts == AV_NOPTS_VALUE) {
2848  sti->info->fps_first_dts = pkt->dts;
2850  }
2851  sti->info->fps_last_dts = pkt->dts;
2853  }
2854  if (sti->codec_info_nb_frames > 1) {
2855  int64_t t = 0;
2856  int64_t limit;
2857 
2858  if (st->time_base.den > 0)
2860  if (st->avg_frame_rate.num > 0)
2862 
2863  if ( t == 0
2864  && sti->codec_info_nb_frames > 30
2865  && sti->info->fps_first_dts != AV_NOPTS_VALUE
2866  && sti->info->fps_last_dts != AV_NOPTS_VALUE) {
2868  t = FFMAX(t, av_rescale_q(dur, st->time_base, AV_TIME_BASE_Q));
2869  }
2870 
2871  if (analyzed_all_streams) limit = max_analyze_duration;
2872  else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) limit = max_subtitle_analyze_duration;
2873  else limit = max_stream_analyze_duration;
2874 
2875  if (t >= limit) {
2876  av_log(ic, AV_LOG_VERBOSE, "max_analyze_duration %"PRId64" reached at %"PRId64" microseconds st:%d\n",
2877  limit,
2878  t, pkt->stream_index);
2879  if (ic->flags & AVFMT_FLAG_NOBUFFER)
2880  av_packet_unref(pkt1);
2881  break;
2882  }
2883  if (pkt->duration > 0 && pkt->duration < INT64_MAX - sti->info->codec_info_duration) {
2884  const int fields = sti->codec_desc && (sti->codec_desc->props & AV_CODEC_PROP_FIELDS);
2886  && (uint64_t)pkt->pts - st->start_time < INT64_MAX
2887  ) {
2889  } else
2891  sti->info->codec_info_duration_fields += sti->parser && sti->need_parsing && fields
2892  ? sti->parser->repeat_pict + 1 : 2;
2893  }
2894  }
2895  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
2896 #if FF_API_R_FRAME_RATE
2897  ff_rfps_add_frame(ic, st, pkt->dts);
2898 #endif
2899  if (pkt->dts != pkt->pts && pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE)
2900  sti->info->frame_delay_evidence = 1;
2901  }
2902  if (!sti->avctx->extradata) {
2903  ret = extract_extradata(si, st, pkt);
2904  if (ret < 0)
2905  goto unref_then_goto_end;
2906  }
2907 
2908  /* If still no information, we try to open the codec and to
2909  * decompress the frame. We try to avoid that in most cases as
2910  * it takes longer and uses more memory. For MPEG-4, we need to
2911  * decompress for QuickTime.
2912  *
2913  * If AV_CODEC_CAP_CHANNEL_CONF is set this will force decoding of at
2914  * least one frame of codec data, this makes sure the codec initializes
2915  * the channel configuration and does not only trust the values from
2916  * the container. */
2917  try_decode_frame(ic, st, pkt,
2918  (options && i < orig_nb_streams) ? &options[i] : NULL);
2919 
2920  if (ic->flags & AVFMT_FLAG_NOBUFFER)
2921  av_packet_unref(pkt1);
2922 
2923  sti->codec_info_nb_frames++;
2924  count++;
2925  }
2926 
2927  if (eof_reached) {
2928  for (unsigned stream_index = 0; stream_index < ic->nb_streams; stream_index++) {
2929  AVStream *const st = ic->streams[stream_index];
2930  AVCodecContext *const avctx = ffstream(st)->avctx;
2931  if (!has_codec_parameters(st, NULL)) {
2932  const AVCodec *codec = find_probe_decoder(ic, st, st->codecpar->codec_id);
2933  if (codec && !avctx->codec) {
2934  AVDictionary *opts = NULL;
2935  if (ic->codec_whitelist)
2936  av_dict_set(&opts, "codec_whitelist", ic->codec_whitelist, 0);
2937  if (avcodec_open2(avctx, codec, (options && stream_index < orig_nb_streams) ? &options[stream_index] : &opts) < 0)
2938  av_log(ic, AV_LOG_WARNING,
2939  "Failed to open codec in %s\n", __func__);
2940  av_dict_free(&opts);
2941  }
2942  }
2943 
2944  // EOF already reached while reading the stream above.
2945  // So continue with reoordering DTS with whatever delay we have.
2947  update_dts_from_pts(ic, stream_index, si->packet_buffer.head);
2948  }
2949  }
2950  }
2951 
2952  if (flush_codecs) {
2953  AVPacket *empty_pkt = si->pkt;
2954  int err = 0;
2955  av_packet_unref(empty_pkt);
2956 
2957  for (unsigned i = 0; i < ic->nb_streams; i++) {
2958  AVStream *const st = ic->streams[i];
2959  FFStream *const sti = ffstream(st);
2960 
2961  /* flush the decoders */
2962  if (sti->info->found_decoder == 1) {
2963  err = try_decode_frame(ic, st, empty_pkt,
2964  (options && i < orig_nb_streams)
2965  ? &options[i] : NULL);
2966 
2967  if (err < 0) {
2968  av_log(ic, AV_LOG_INFO,
2969  "decoding for stream %d failed\n", st->index);
2970  }
2971  }
2972  }
2973  }
2974 
2975  ff_rfps_calculate(ic);
2976 
2977  for (unsigned i = 0; i < ic->nb_streams; i++) {
2978  AVStream *const st = ic->streams[i];
2979  FFStream *const sti = ffstream(st);
2980  AVCodecContext *const avctx = sti->avctx;
2981 
2982  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
2983  if (avctx->codec_id == AV_CODEC_ID_RAWVIDEO && !avctx->codec_tag && !avctx->bits_per_coded_sample) {
2984  uint32_t tag= avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt);
2986  avctx->codec_tag= tag;
2987  }
2988 
2989  /* estimate average framerate if not set by demuxer */
2990  if (sti->info->codec_info_duration_fields &&
2991  !st->avg_frame_rate.num &&
2992  sti->info->codec_info_duration) {
2993  int best_fps = 0;
2994  double best_error = 0.01;
2995  AVRational codec_frame_rate = avctx->framerate;
2996 
2997  if (sti->info->codec_info_duration >= INT64_MAX / st->time_base.num / 2||
2998  sti->info->codec_info_duration_fields >= INT64_MAX / st->time_base.den ||
2999  sti->info->codec_info_duration < 0)
3000  continue;
3003  sti->info->codec_info_duration * 2 * (int64_t) st->time_base.num, 60000);
3004 
3005  /* Round guessed framerate to a "standard" framerate if it's
3006  * within 1% of the original estimate. */
3007  for (int j = 0; j < MAX_STD_TIMEBASES; j++) {
3008  AVRational std_fps = { get_std_framerate(j), 12 * 1001 };
3009  double error = fabs(av_q2d(st->avg_frame_rate) /
3010  av_q2d(std_fps) - 1);
3011 
3012  if (error < best_error) {
3013  best_error = error;
3014  best_fps = std_fps.num;
3015  }
3016 
3018  codec_frame_rate.num > 0 && codec_frame_rate.den > 0) {
3019  error = fabs(av_q2d(codec_frame_rate) /
3020  av_q2d(std_fps) - 1);
3021  if (error < best_error) {
3022  best_error = error;
3023  best_fps = std_fps.num;
3024  }
3025  }
3026  }
3027  if (best_fps)
3029  best_fps, 12 * 1001, INT_MAX);
3030  }
3031  if (!st->r_frame_rate.num) {
3032  const AVCodecDescriptor *desc = sti->codec_desc;
3033  AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 };
3034  AVRational fr = av_mul_q(avctx->framerate, mul);
3035 
3036  if (fr.num && fr.den && av_cmp_q(st->time_base, av_inv_q(fr)) <= 0) {
3037  st->r_frame_rate = fr;
3038  } else {
3039  st->r_frame_rate.num = st->time_base.den;
3040  st->r_frame_rate.den = st->time_base.num;
3041  }
3042  }
3043  st->codecpar->framerate = avctx->framerate;
3044  if (sti->display_aspect_ratio.num && sti->display_aspect_ratio.den) {
3045  AVRational hw_ratio = { avctx->height, avctx->width };
3047  hw_ratio);
3048  }
3049  } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
3050  if (!avctx->bits_per_coded_sample)
3051  avctx->bits_per_coded_sample =
3053  // set stream disposition based on audio service type
3054  switch (avctx->audio_service_type) {
3057  break;
3060  break;
3063  break;
3066  break;
3069  break;
3070  }
3071  }
3072  }
3073 
3074  if (probesize)
3075  estimate_timings(ic, old_offset);
3076 
3077  av_opt_set_int(ic, "skip_clear", 0, AV_OPT_SEARCH_CHILDREN);
3078 
3079  if (ret >= 0 && ic->nb_streams)
3080  /* We could not have all the codec parameters before EOF. */
3081  ret = -1;
3082  for (unsigned i = 0; i < ic->nb_streams; i++) {
3083  AVStream *const st = ic->streams[i];
3084  FFStream *const sti = ffstream(st);
3085  const char *errmsg;
3086 
3087  /* if no packet was ever seen, update context now for has_codec_parameters */
3088  if (!sti->avctx_inited) {
3089  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
3091  st->codecpar->format = sti->avctx->sample_fmt;
3093  if (ret < 0)
3094  goto find_stream_info_err;
3095  }
3096  if (!has_codec_parameters(st, &errmsg)) {
3097  char buf[256];
3098  avcodec_string(buf, sizeof(buf), sti->avctx, 0);
3099  av_log(ic, AV_LOG_WARNING,
3100  "Could not find codec parameters for stream %d (%s): %s\n"
3101  "Consider increasing the value for the 'analyzeduration' (%"PRId64") and 'probesize' (%"PRId64") options\n",
3102  i, buf, errmsg, ic->max_analyze_duration, ic->probesize);
3103  } else {
3104  ret = 0;
3105  }
3106  }
3107 
3108  err = compute_chapters_end(ic);
3109  if (err < 0) {
3110  ret = err;
3111  goto find_stream_info_err;
3112  }
3113 
3114  /* update the stream parameters from the internal codec contexts */
3115  for (unsigned i = 0; i < ic->nb_streams; i++) {
3116  AVStream *const st = ic->streams[i];
3117  FFStream *const sti = ffstream(st);
3118 
3119  if (sti->avctx_inited) {
3120  ret = parameters_from_context(ic, st->codecpar, sti->avctx);
3121  if (ret < 0)
3122  goto find_stream_info_err;
3123 
3124  if (sti->avctx->rc_buffer_size > 0 || sti->avctx->rc_max_rate > 0 ||
3125  sti->avctx->rc_min_rate) {
3126  size_t cpb_size;
3127  AVCPBProperties *props = av_cpb_properties_alloc(&cpb_size);
3128  if (props) {
3129  if (sti->avctx->rc_buffer_size > 0)
3130  props->buffer_size = sti->avctx->rc_buffer_size;
3131  if (sti->avctx->rc_min_rate > 0)
3132  props->min_bitrate = sti->avctx->rc_min_rate;
3133  if (sti->avctx->rc_max_rate > 0)
3134  props->max_bitrate = sti->avctx->rc_max_rate;
3138  (uint8_t *)props, cpb_size, 0))
3139  av_free(props);
3140  }
3141  }
3142  }
3143 
3144  sti->avctx_inited = 0;
3145  }
3146 
3147 find_stream_info_err:
3148  for (unsigned i = 0; i < ic->nb_streams; i++) {
3149  AVStream *const st = ic->streams[i];
3150  FFStream *const sti = ffstream(st);
3151  int err;
3152 
3153  if (sti->info) {
3154  av_freep(&sti->info->duration_error);
3155  av_freep(&sti->info);
3156  }
3157 
3158  if (avcodec_is_open(sti->avctx)) {
3159  err = codec_close(sti);
3160  if (err < 0 && ret >= 0)
3161  ret = err;
3162  }
3163 
3165  }
3166  if (ic->pb) {
3167  FFIOContext *const ctx = ffiocontext(ic->pb);
3168  av_log(ic, AV_LOG_DEBUG, "After avformat_find_stream_info() pos: %"PRId64" bytes read:%"PRId64" seeks:%d frames:%d\n",
3169  avio_tell(ic->pb), ctx->bytes_read, ctx->seek_count, count);
3170  }
3171  return ret;
3172 
3173 unref_then_goto_end:
3174  av_packet_unref(pkt1);
3175  goto find_stream_info_err;
3176 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:605
AVSubtitle
Definition: avcodec.h:2090
FFStreamInfo::fps_last_dts
int64_t fps_last_dts
Definition: demux.h:173
AVCodecContext::frame_size
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1059
av_opt_get_dict_val
int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
Definition: opt.c:1383
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:432
AVCodec
AVCodec.
Definition: codec.h:172
ff_rfps_add_frame
int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts)
add frame for rfps calculation.
Definition: demux.c:2317
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:203
AVBSFContext::par_in
AVCodecParameters * par_in
Parameters of the input stream.
Definition: bsf.h:90
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AVFMT_FLAG_DISCARD_CORRUPT
#define AVFMT_FLAG_DISCARD_CORRUPT
Discard frames marked corrupted.
Definition: avformat.h:1424
FFStream::skip_samples
int skip_samples
Number of samples to skip at the start of the frame decoded from the next packet.
Definition: internal.h:208
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
PacketList::head
PacketListEntry * head
Definition: packet_internal.h:34
AVCodecParserContext::pts
int64_t pts
Definition: avcodec.h:2608
DURATION_DEFAULT_MAX_RETRY
#define DURATION_DEFAULT_MAX_RETRY
Definition: demux.c:1851
AV_CODEC_ID_AC3
@ AV_CODEC_ID_AC3
Definition: codec_id.h:463
program
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C program
Definition: undefined.txt:6
AVFMT_DURATION_FROM_BITRATE
@ AVFMT_DURATION_FROM_BITRATE
Duration estimated from bitrate (less accurate)
Definition: avformat.h:1247
av_opt_set_defaults
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1678
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
av_probe_input_buffer2
int av_probe_input_buffer2(AVIOContext *pb, const AVInputFormat **fmt, const char *url, void *logctx, unsigned int offset, unsigned int max_probe_size)
Probe a bytestream to determine the input format.
Definition: format.c:253
AVCodecContext::audio_service_type
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
Definition: avcodec.h:1079
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:422
av_compare_ts
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare two timestamps each in its own time base.
Definition: mathematics.c:147
FF_FDEBUG_TS
#define FF_FDEBUG_TS
Definition: avformat.h:1540
AVSTREAM_EVENT_FLAG_NEW_PACKETS
#define AVSTREAM_EVENT_FLAG_NEW_PACKETS
Definition: avformat.h:868
av_add_stable
int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t inc)
Add a value to a timestamp.
Definition: mathematics.c:191
ff_find_decoder
const AVCodec * ff_find_decoder(AVFormatContext *s, const AVStream *st, enum AVCodecID codec_id)
Definition: avformat.c:804
is_relative
static av_always_inline int is_relative(int64_t ts)
Definition: avformat_internal.h:107
FFStream::first_dts
int64_t first_dts
Timestamp corresponding to the last dts sync point.
Definition: internal.h:337
AVCodecParserContext::pict_type
int pict_type
Definition: avcodec.h:2597
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1032
AVCodecContext::rc_min_rate
int64_t rc_min_rate
minimum bitrate
Definition: avcodec.h:1285
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
ffiocontext
static av_always_inline FFIOContext * ffiocontext(AVIOContext *ctx)
Definition: avio_internal.h:81
FFStream::bsf
struct AVBSFContext * bsf
Definition: internal.h:166
FFStream::last_IP_pts
int64_t last_IP_pts
Definition: internal.h:305
ffformatcontext
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition: internal.h:123
AVCodecParameters::color_space
enum AVColorSpace color_space
Definition: codec_par.h:169
AV_PKT_DATA_NEW_EXTRADATA
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition: packet.h:56
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AV_DISPOSITION_ATTACHED_PIC
#define AV_DISPOSITION_ATTACHED_PIC
The stream is stored in the file as an attached picture/"cover art" (e.g.
Definition: avformat.h:670
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:815
av_find_program_from_stream
AVProgram * av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s)
Find the programs which belong to a given stream.
Definition: avformat.c:325
AV_PKT_FLAG_DISCARD
#define AV_PKT_FLAG_DISCARD
Flag is used to discard packets which are required to maintain valid decoder state but are not requir...
Definition: packet.h:650
AVCodecParserContext::duration
int duration
Duration of the current frame.
Definition: avcodec.h:2703
avcodec_string
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
Definition: avcodec.c:504
AVFMT_NOTIMESTAMPS
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:478
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:263
int64_t
long long int64_t
Definition: coverity.c:34
AV_CODEC_ID_RAWVIDEO
@ AV_CODEC_ID_RAWVIDEO
Definition: codec_id.h:65
ff_buffer_packet
int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt)
Definition: demux.c:622
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
FormatContextInternal::raw_packet_buffer
PacketList raw_packet_buffer
Raw packets from the demuxer, prior to parsing and decoding.
Definition: avformat_internal.h:75
id3v2.h
FFStream::first_discard_sample
int64_t first_discard_sample
If not 0, the first audio sample that should be discarded from the stream.
Definition: internal.h:225
FF_INFMT_FLAG_ID3V2_AUTO
#define FF_INFMT_FLAG_ID3V2_AUTO
Automatically parse ID3v2 metadata.
Definition: demux.h:45
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1332
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:409
AVCodec::capabilities
int capabilities
Codec capabilities.
Definition: codec.h:191
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:588
AV_CODEC_ID_DVB_TELETEXT
@ AV_CODEC_ID_DVB_TELETEXT
Definition: codec_id.h:579
extract_extradata_check
static int extract_extradata_check(AVStream *st)
Definition: demux.c:2442
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:669
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:833
AVChapter::start
int64_t start
Definition: avformat.h:1226
AVFMT_FLAG_CUSTOM_IO
#define AVFMT_FLAG_CUSTOM_IO
The caller has supplied a custom AVIOContext, don't avio_close() it.
Definition: avformat.h:1423
data
const char data[16]
Definition: mxf.c:149
has_duration
static int has_duration(AVFormatContext *ic)
Return TRUE if the stream has accurate duration in any stream.
Definition: demux.c:1669
AVFormatContext::duration_estimation_method
enum AVDurationEstimationMethod duration_estimation_method
The duration field can be estimated through various ways, and this field can be used to know how the ...
Definition: avformat.h:1692
AVCodecParameters::framerate
AVRational framerate
Video only.
Definition: codec_par.h:156
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
AVFormatContext::programs
AVProgram ** programs
Definition: avformat.h:1462
handle_new_packet
static int handle_new_packet(AVFormatContext *s, AVPacket *pkt, int allow_passthrough)
Handle a new packet and either return it directly if possible and allow_passthrough is true or queue ...
Definition: demux.c:577
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:606
ts_to_samples
static int64_t ts_to_samples(AVStream *st, int64_t ts)
Definition: demux.c:1315
FormatContextInternal::metafree
int metafree
Contexts and child contexts do not contain a metadata option.
Definition: avformat_internal.h:90
mathematics.h
AVDictionary
Definition: dict.c:32
AVProbeData::buf_size
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:454
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
AVFormatContext::probesize
int64_t probesize
Maximum number of bytes read from input in order to determine stream properties.
Definition: avformat.h:1448
estimate_timings_from_pts
static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
Definition: demux.c:1855
av_read_frame
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
Definition: demux.c:1569
cffstream
static const av_always_inline FFStream * cffstream(const AVStream *st)
Definition: internal.h:352
avcodec_is_open
int avcodec_is_open(AVCodecContext *s)
Definition: avcodec.c:703
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:329
wrap_timestamp
static int64_t wrap_timestamp(const AVStream *st, int64_t timestamp)
Definition: demux.c:53
FFInputFormat::priv_data_size
int priv_data_size
Size of private data so that it can be allocated in the wrapper.
Definition: demux.h:61
FFStream::last_dts_for_order_check
int64_t last_dts_for_order_check
Internal data to analyze DTS and detect faulty mpeg streams.
Definition: internal.h:287
AV_CODEC_ID_HDMV_PGS_SUBTITLE
@ AV_CODEC_ID_HDMV_PGS_SUBTITLE
Definition: codec_id.h:578
FFInputFormat::read_header
int(* read_header)(struct AVFormatContext *)
Read the format header and initialize the AVFormatContext structure.
Definition: demux.h:80
av_bsf_free
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
Definition: bsf.c:52
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:326
AV_CODEC_ID_TRUEHD
@ AV_CODEC_ID_TRUEHD
Definition: codec_id.h:504
update_stream_timings
static void update_stream_timings(AVFormatContext *ic)
Estimate the stream timings from the one of each components.
Definition: demux.c:1686
FFIOContext
Definition: avio_internal.h:28
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:643
codec_close
static int codec_close(FFStream *sti)
Definition: demux.c:1320
FormatContextInternal
Definition: avformat_internal.h:33
AVINDEX_KEYFRAME
#define AVINDEX_KEYFRAME
Definition: avformat.h:606
FFStream::codec_desc
const struct AVCodecDescriptor * codec_desc
Definition: internal.h:340
avcodec_pix_fmt_to_codec_tag
unsigned int avcodec_pix_fmt_to_codec_tag(enum AVPixelFormat pix_fmt)
Return a value representing the fourCC code associated to the pixel format pix_fmt,...
Definition: raw.c:31
av_gcd
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
Definition: mathematics.c:37
genpts
static int genpts
Definition: ffplay.c:329
av_filename_number_test
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
Definition: utils.c:121
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:304
FFStream::extract_extradata
struct FFStream::@455 extract_extradata
avformat_queue_attached_pictures
int avformat_queue_attached_pictures(AVFormatContext *s)
Definition: demux_utils.c:84
AVCodecParameters::color_primaries
enum AVColorPrimaries color_primaries
Definition: codec_par.h:167
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:559
close
static av_cold void close(AVCodecParserContext *s)
Definition: apv_parser.c:197
avformat_close_input
void avformat_close_input(AVFormatContext **ps)
Close an opened input AVFormatContext.
Definition: demux.c:377
AVPacketSideData::size
size_t size
Definition: packet.h:411
AVCodecParserContext::offset
int64_t offset
byte offset from starting packet start
Definition: avcodec.h:2629
MAX_STD_TIMEBASES
#define MAX_STD_TIMEBASES
Definition: demux.h:148
AVFormatContext::interrupt_callback
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1534
AVCodecParserContext::key_frame
int key_frame
Set by parser to 1 for key frames and 0 for non-key frames.
Definition: avcodec.h:2638
FFStream::dts_ordered
uint8_t dts_ordered
Definition: internal.h:288
finish
static void finish(void)
Definition: movenc.c:374
FFStream::last_IP_duration
int last_IP_duration
Definition: internal.h:306
force_codec_ids
static void force_codec_ids(AVFormatContext *s, AVStream *st)
Definition: demux.c:402
bsf.h
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:448
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:347
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1047
update_initial_timestamps
static void update_initial_timestamps(AVFormatContext *s, int stream_index, int64_t dts, int64_t pts, AVPacket *pkt)
Definition: demux.c:864
AVCodecContext::skip_frame
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:1670
fail
#define fail()
Definition: checkasm.h:214
av_add_index_entry
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
Definition: seek.c:122
AVSTREAM_PARSE_FULL_ONCE
@ AVSTREAM_PARSE_FULL_ONCE
full parsing and repack of the first frame only, only implemented for H.264 currently
Definition: avformat.h:592
FFStreamInfo::fps_first_dts
int64_t fps_first_dts
Those are used for average framerate estimation.
Definition: demux.h:171
FFStream::inited
int inited
Definition: internal.h:167
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:494
avpriv_packet_list_get
int avpriv_packet_list_get(PacketList *pkt_buffer, AVPacket *pkt)
Remove the oldest AVPacket in the list and return it.
Definition: packet.c:595
AVERROR_OPTION_NOT_FOUND
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:63
FFStream::avctx
struct AVCodecContext * avctx
The codec context used by avformat_find_stream_info, the parser, etc.
Definition: internal.h:156
AVChapter
Definition: avformat.h:1223
AVFMT_GENERIC_INDEX
#define AVFMT_GENERIC_INDEX
Use generic index building code.
Definition: avformat.h:479
AVFMT_DURATION_FROM_PTS
@ AVFMT_DURATION_FROM_PTS
Duration accurately estimated from PTSes.
Definition: avformat.h:1245
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AVPROBE_PADDING_SIZE
#define AVPROBE_PADDING_SIZE
extra allocated bytes at the end of the probe buffer
Definition: avformat.h:465
av_parser_init
AVCodecParserContext * av_parser_init(int codec_id)
Definition: parser.c:35
pts
static int64_t pts
Definition: transcode_aac.c:644
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:461
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:803
av_probe_input_format3
const AVInputFormat * av_probe_input_format3(const AVProbeData *pd, int is_opened, int *score_ret)
Guess the file format.
Definition: format.c:156
AV_PTS_WRAP_IGNORE
#define AV_PTS_WRAP_IGNORE
Options for behavior on timestamp wrap detection.
Definition: avformat.h:733
ff_check_interrupt
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
Definition: avio.c:855
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
extract_extradata_init
static int extract_extradata_init(AVStream *st)
Definition: demux.c:2458
AVCodecParserContext::dts
int64_t dts
Definition: avcodec.h:2609
AVRational::num
int num
Numerator.
Definition: rational.h:59
FFDIFFSIGN
#define FFDIFFSIGN(x, y)
Comparator.
Definition: macros.h:45
ff_id3v2_parse_chapters
int ff_id3v2_parse_chapters(AVFormatContext *s, ID3v2ExtraMeta *cur)
Create chapters for all CHAP tags found in the ID3v2 header.
Definition: id3v2.c:1200
avsubtitle_free
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
Definition: avcodec.c:411
raw.h
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
AV_CODEC_ID_DVB_SUBTITLE
@ AV_CODEC_ID_DVB_SUBTITLE
Definition: codec_id.h:573
AVFormatContext::bit_rate
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
Definition: avformat.h:1406
av_get_bits_per_sample
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:549
AVCodecParameters::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: codec_par.h:168
avcodec_decode_subtitle2
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Decode a subtitle message.
Definition: decode.c:914
AV_DISPOSITION_CLEAN_EFFECTS
#define AV_DISPOSITION_CLEAN_EFFECTS
The audio stream contains music and sound effects without voice.
Definition: avformat.h:662
AVFormatContext::max_ts_probe
int max_ts_probe
Maximum number of packets to read while waiting for the first timestamp.
Definition: avformat.h:1589
avassert.h
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:236
pkt
AVPacket * pkt
Definition: movenc.c:60
chapter_start_cmp
static int chapter_start_cmp(const void *p1, const void *p2)
Definition: demux.c:2221
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
AV_CODEC_CAP_EXPERIMENTAL
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: codec.h:87
AVInputFormat
Definition: avformat.h:544
AV_PKT_FLAG_CORRUPT
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition: packet.h:644
ID3v2ExtraMeta
Definition: id3v2.h:84
AVFormatContext::ctx_flags
int ctx_flags
Flags signalling stream properties.
Definition: avformat.h:1313
duration
int64_t duration
Definition: movenc.c:65
avformat_open_input
int avformat_open_input(AVFormatContext **ps, const char *filename, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition: demux.c:231
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:523
AVCodecContext::has_b_frames
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:705
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:149
AVChapter::end
int64_t end
chapter start/end time in time_base units
Definition: avformat.h:1226
AVCodecDescriptor
This struct describes the properties of a single codec described by an AVCodecID.
Definition: codec_desc.h:38
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_CODEC_ID_EVC
@ AV_CODEC_ID_EVC
Definition: codec_id.h:325
FFInputFormat::flags_internal
int flags_internal
Internal flags.
Definition: demux.h:66
FFFormatContext::packet_buffer
PacketList packet_buffer
This buffer is only needed when packets were already buffered but not decoded, for example to get the...
Definition: internal.h:86
FFStreamInfo::last_dts
int64_t last_dts
Definition: demux.h:150
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1415
AVCodecParameters::sample_aspect_ratio
AVRational sample_aspect_ratio
Video only.
Definition: codec_par.h:144
duration_name
static const char *const duration_name[]
Definition: demux.c:1997
AVFormatContext::nb_programs
unsigned int nb_programs
Definition: avformat.h:1461
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:549
bitrate
int64_t bitrate
Definition: av1_levels.c:47
AVFormatContext::iformat
const struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:1276
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:453
frame_size
int frame_size
Definition: mxfenc.c:2487
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:201
AV_CODEC_ID_MP2
@ AV_CODEC_ID_MP2
Definition: codec_id.h:460
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
info
MIPS optimizations info
Definition: mips.txt:2
FFStream::nb_decoded_frames
int nb_decoded_frames
Number of internally decoded frames, used internally in libavformat, do not access its lifetime diffe...
Definition: internal.h:238
av_opt_set_dict_val
int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags)
Definition: opt.c:984
avpriv_h264_has_num_reorder_frames
int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx)
Definition: h264dec.c:62
avcodec_receive_frame
int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Alias for avcodec_receive_frame_flags(avctx, frame, 0).
Definition: avcodec.c:721
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:41
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
AVPacketSideData::data
uint8_t * data
Definition: packet.h:410
FFFormatContext::data_offset
int64_t data_offset
offset of the first packet
Definition: internal.h:89
ctx
AVFormatContext * ctx
Definition: movenc.c:49
FFStream::codec_info_nb_frames
int codec_info_nb_frames
Number of frames that have been demuxed during avformat_find_stream_info()
Definition: internal.h:320
AVBSFContext::time_base_in
AVRational time_base_in
The timebase used for the timestamps of the input packets.
Definition: bsf.h:102
FFStream::pts_reorder_error_count
uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1]
Definition: internal.h:280
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
FFStream::display_aspect_ratio
AVRational display_aspect_ratio
display aspect ratio (0 if unknown)
Definition: internal.h:296
AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED
@ AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED
Definition: defs.h:239
av_bsf_alloc
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **pctx)
Allocate a context for a given bitstream filter.
Definition: bsf.c:104
RELATIVE_TS_BASE
#define RELATIVE_TS_BASE
Definition: avformat_internal.h:105
DURATION_MAX_RETRY
#define DURATION_MAX_RETRY
Definition: demux.c:1852
AV_CODEC_ID_CODEC2
@ AV_CODEC_ID_CODEC2
Definition: codec_id.h:527
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
AVCodecContext::rc_max_rate
int64_t rc_max_rate
maximum bitrate
Definition: avcodec.h:1278
AVCodecParameters::nb_coded_side_data
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition: codec_par.h:86
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:202
av_mallocz
#define av_mallocz(s)
Definition: tableprint_vlc.h:31
AV_ROUND_NEAR_INF
@ AV_ROUND_NEAR_INF
Round to nearest and halfway cases away from zero.
Definition: mathematics.h:135
FFStream::pts_reorder_error
int64_t pts_reorder_error[MAX_REORDER_DELAY+1]
Internal data to generate dts from pts.
Definition: internal.h:279
determinable_frame_size
static int determinable_frame_size(const AVCodecContext *avctx)
Definition: demux.c:2057
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:639
AVCPBProperties
This structure describes the bitrate properties of an encoded bitstream.
Definition: defs.h:282
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
AV_ROUND_PASS_MINMAX
@ AV_ROUND_PASS_MINMAX
Flag telling rescaling functions to pass INT64_MIN/MAX through unchanged, avoiding special cases for ...
Definition: mathematics.h:159
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
PacketList::tail
PacketListEntry * tail
Definition: packet_internal.h:34
AVFMT_NEEDNUMBER
#define AVFMT_NEEDNUMBER
Needs 'd' in filename.
Definition: avformat.h:469
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:449
parameters_from_context
static int parameters_from_context(AVFormatContext *ic, AVCodecParameters *par, const AVCodecContext *avctx)
Definition: demux.c:2547
FFStreamInfo::found_decoder
int found_decoder
0 -> decoder has not been searched for yet.
Definition: demux.h:164
AVFormatContext::max_analyze_duration
int64_t max_analyze_duration
Maximum duration (in AV_TIME_BASE units) of the data read from input in avformat_find_stream_info().
Definition: avformat.h:1456
AVCodecDescriptor::props
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: codec_desc.h:54
AVFMT_FLAG_NOPARSE
#define AVFMT_FLAG_NOPARSE
Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the filling code works on frames and n...
Definition: avformat.h:1421
fields
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the then the processing requires a frame on this link and the filter is expected to make efforts in that direction The status of input links is stored by the fifo and status_out fields
Definition: filter_design.txt:155
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
if
if(ret)
Definition: filter_design.txt:179
av_probe_input_format2
const AVInputFormat * av_probe_input_format2(const AVProbeData *pd, int is_opened, int *score_max)
Guess the file format.
Definition: format.c:235
get_std_framerate
static int get_std_framerate(int i)
Definition: demux.c:2268
has_codec_parameters
static int has_codec_parameters(const AVStream *st, const char **errmsg_ptr)
Definition: demux.c:2070
FFFormatContext
Definition: internal.h:64
FF_INFMT_FLAG_INIT_CLEANUP
#define FF_INFMT_FLAG_INIT_CLEANUP
For an FFInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
Definition: demux.h:35
AVCodecParserContext::repeat_pict
int repeat_pict
This field is used for proper frame duration computation in lavf.
Definition: avcodec.h:2607
FFStream::need_parsing
enum AVStreamParseType need_parsing
Definition: internal.h:314
AVCodecContext::rc_buffer_size
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:1263
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:232
AVFormatContext
Format I/O context.
Definition: avformat.h:1264
FFStream::pub
AVStream pub
The public context.
Definition: internal.h:132
opts
AVDictionary * opts
Definition: movenc.c:51
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:571
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:767
avcodec_parameters_to_context
int avcodec_parameters_to_context(AVCodecContext *codec, const struct AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
framerate
float framerate
Definition: av1_levels.c:29
av_bsf_init
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition: bsf.c:149
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
metadata
Stream codec metadata
Definition: ogg-flac-chained-meta.txt:2
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:783
NULL
#define NULL
Definition: coverity.c:32
FFStream::avctx_inited
int avctx_inited
1 if avctx has been initialized with the values from the codec parameters
Definition: internal.h:160
avcodec_find_decoder_by_name
const AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: allcodecs.c:1071
av_match_list
int av_match_list(const char *name, const char *list, char separator)
Check if a name is in a list.
Definition: avstring.c:445
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:284
avcodec_parameters_free
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
Definition: codec_par.c:67
AVFMTCTX_NOHEADER
#define AVFMTCTX_NOHEADER
signal that no header is present (streams are added dynamically)
Definition: avformat.h:1215
av_bsf_receive_packet
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:230
FFStreamInfo::codec_info_duration
int64_t codec_info_duration
Definition: demux.h:155
avpriv_packet_list_put
int avpriv_packet_list_put(PacketList *packet_buffer, AVPacket *pkt, int(*copy)(AVPacket *dst, const AVPacket *src), int flags)
Append an AVPacket to the list.
Definition: packet.c:546
AVFormatContext::fps_probe_size
int fps_probe_size
The number of frames used for determining the framerate in avformat_find_stream_info().
Definition: avformat.h:1516
avcodec_free_context
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition: options.c:164
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVFMT_DURATION_FROM_STREAM
@ AVFMT_DURATION_FROM_STREAM
Duration estimated from a stream with a known duration.
Definition: avformat.h:1246
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:489
AVPacketSideData::type
enum AVPacketSideDataType type
Definition: packet.h:412
AV_DISPOSITION_COMMENT
#define AV_DISPOSITION_COMMENT
The stream is a commentary track.
Definition: avformat.h:635
AVSTREAM_PARSE_NONE
@ AVSTREAM_PARSE_NONE
Definition: avformat.h:588
update_initial_durations
static void update_initial_durations(AVFormatContext *s, AVStream *st, int stream_index, int64_t duration)
Definition: demux.c:918
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:278
ff_id3v2_parse_apic
int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Create a stream for each APIC (attached picture) extracted from the ID3v2 header.
Definition: id3v2.c:1169
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1306
probe_codec
static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
Definition: demux.c:424
AVDurationEstimationMethod
AVDurationEstimationMethod
The duration of a video can be estimated through various ways, and this enum can be used to know how ...
Definition: avformat.h:1244
AVFormatContext::duration_probesize
int64_t duration_probesize
Maximum number of bytes read from input in order to determine stream durations when using estimate_ti...
Definition: avformat.h:1884
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:451
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts.c:552
options
Definition: swscale.c:43
get_next_pkt
static PacketListEntry * get_next_pkt(AVFormatContext *s, AVStream *st, PacketListEntry *pktl)
Definition: demux.c:779
double
double
Definition: af_crystalizer.c:132
avcodec_open2
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: avcodec.c:144
AVCodecParserContext::flags
int flags
Definition: avcodec.h:2622
time.h
AVFormatContext::skip_estimate_duration_from_pts
int skip_estimate_duration_from_pts
Skip duration calculation in estimate_timings_from_pts.
Definition: avformat.h:1677
FFStreamInfo::codec_info_duration_fields
int64_t codec_info_duration_fields
Definition: demux.h:156
av_packet_ref
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: packet.c:440
FormatContextInternal::fc
FFFormatContext fc
Definition: avformat_internal.h:34
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:180
PacketListEntry::next
struct PacketListEntry * next
Definition: packet_internal.h:29
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:743
read_frame_internal
static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
Definition: demux.c:1369
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
FAIL
#define FAIL(errmsg)
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:184
av_opt_set_int
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:880
duration_estimate_name
static const char * duration_estimate_name(enum AVDurationEstimationMethod method)
Definition: demux.c:2003
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
av_packet_side_data_get
const AVPacketSideData * av_packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Get side information from a side data array.
Definition: packet.c:644
FFInputFormat::read_packet
int(* read_packet)(struct AVFormatContext *, AVPacket *pkt)
Read one packet and put it in 'pkt'.
Definition: demux.h:90
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:1043
AV_CODEC_ID_EAC3
@ AV_CODEC_ID_EAC3
Definition: codec_id.h:500
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1320
AV_CODEC_CAP_CHANNEL_CONF
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition: codec.h:91
FFFormatContext::id3v2_meta
AVDictionary * id3v2_meta
ID3v2 tag useful for MP3 demuxing.
Definition: internal.h:118
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:462
AVFMT_FLAG_NOFILLIN
#define AVFMT_FLAG_NOFILLIN
Do not infer any values from other values, just return what is stored in the container.
Definition: avformat.h:1420
FormatContextInternal::raw_packet_buffer_size
int raw_packet_buffer_size
Sum of the size of packets in raw_packet_buffer, in bytes.
Definition: avformat_internal.h:80
AV_ROUND_DOWN
@ AV_ROUND_DOWN
Round toward -infinity.
Definition: mathematics.h:133
av_codec_is_decoder
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:85
av_sat_sub64
#define av_sat_sub64
Definition: common.h:142
av_rescale_rnd
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
Definition: mathematics.c:58
avformat_find_stream_info
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition: demux.c:2588
f
f
Definition: af_crystalizer.c:122
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
av_ts2timestr
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:83
AVMediaType
AVMediaType
Definition: avutil.h:198
AVCodecParserContext::frame_offset
int64_t frame_offset
Definition: avcodec.h:2592
AV_PTS_WRAP_SUB_OFFSET
#define AV_PTS_WRAP_SUB_OFFSET
subtract the format specific offset on wrap detection
Definition: avformat.h:735
AVPacket::size
int size
Definition: packet.h:589
avpriv_pix_fmt_find
enum AVPixelFormat avpriv_pix_fmt_find(enum PixelFormatTagLists list, unsigned fourcc)
Definition: raw.c:78
FFFormatContext::parse_pkt
AVPacket * parse_pkt
The generic code uses this as a temporary packet to parse packets or for muxing, especially flushing.
Definition: internal.h:104
FFStreamInfo
Definition: demux.h:149
avformat_alloc_context
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:162
init_input
static int init_input(AVFormatContext *s, const char *filename, AVDictionary **options)
Definition: demux.c:158
AVIOContext::seekable
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:261
FFStream
Definition: internal.h:128
shift
static int shift(int a, int b)
Definition: bonk.c:261
av_bsf_send_packet
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:202
is_id3v2_format
static av_always_inline int is_id3v2_format(const AVInputFormat *fmt)
Definition: demux.c:227
start_time
static int64_t start_time
Definition: ffplay.c:326
AV_CODEC_ID_DTS
@ AV_CODEC_ID_DTS
Definition: codec_id.h:464
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1039
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition: avcodec.h:550
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
sample
#define sample
Definition: flacdsp_template.c:44
FFStreamInfo::duration_count
int duration_count
Definition: demux.h:152
size
int size
Definition: twinvq_data.h:10344
FF_INFMT_FLAG_PREFER_CODEC_FRAMERATE
#define FF_INFMT_FLAG_PREFER_CODEC_FRAMERATE
Definition: demux.h:40
ID3v2_DEFAULT_MAGIC
#define ID3v2_DEFAULT_MAGIC
Default magic bytes for ID3v2 header: "ID3".
Definition: id3v2.h:35
PIX_FMT_LIST_RAW
@ PIX_FMT_LIST_RAW
Definition: raw.h:38
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:247
AV_CODEC_PROP_FIELDS
#define AV_CODEC_PROP_FIELDS
Video codec supports separate coding of fields in interlaced frames.
Definition: codec_desc.h:97
update_wrap_reference
static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt)
Definition: demux.c:477
AVStream::event_flags
int event_flags
Flags indicating events happening on the stream, a combination of AVSTREAM_EVENT_FLAG_*.
Definition: avformat.h:855
FFStream::dts_misordered
uint8_t dts_misordered
Definition: internal.h:289
av_get_audio_frame_duration2
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters in...
Definition: utils.c:816
PacketListEntry::pkt
AVPacket pkt
Definition: packet_internal.h:30
AV_PTS_WRAP_ADD_OFFSET
#define AV_PTS_WRAP_ADD_OFFSET
add the format specific offset on wrap detection
Definition: avformat.h:734
AVFMT_FLAG_IGNDTS
#define AVFMT_FLAG_IGNDTS
Ignore DTS on frames that contain both DTS & PTS.
Definition: avformat.h:1419
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:468
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:797
ff_format_io_close
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: avformat.c:868
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:199
AV_PICTURE_TYPE_NONE
@ AV_PICTURE_TYPE_NONE
Undefined.
Definition: avutil.h:277
AVCPBProperties::min_bitrate
int64_t min_bitrate
Minimum bitrate of the stream, in bits per second.
Definition: defs.h:292
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:822
set_codec_from_probe_data
static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeData *pd)
Definition: demux.c:103
diff
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
Definition: vf_paletteuse.c:166
AV_DISPOSITION_HEARING_IMPAIRED
#define AV_DISPOSITION_HEARING_IMPAIRED
The stream is intended for hearing impaired audiences.
Definition: avformat.h:654
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:587
update_stream_avctx
static int update_stream_avctx(AVFormatContext *s)
Definition: demux.c:191
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
a0
static double a0(void *priv, double x, double y)
Definition: vf_xfade.c:2028
AV_CODEC_ID_VVC
@ AV_CODEC_ID_VVC
Definition: codec_id.h:252
av_packet_side_data_add
AVPacketSideData * av_packet_side_data_add(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, void *data, size_t size, int flags)
Wrap existing data as packet side data.
Definition: packet.c:687
AV_CODEC_ID_RV30
@ AV_CODEC_ID_RV30
Definition: codec_id.h:120
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
FFStream::pts_wrap_behavior
int pts_wrap_behavior
Options for behavior, when a wrap is detected.
Definition: internal.h:267
FFStreamInfo::last_duration
int64_t last_duration
Definition: demux.h:166
av_packet_make_refcounted
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
Definition: packet.c:495
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:594
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:233
FFStreamInfo::rfps_duration_sum
int64_t rfps_duration_sum
Definition: demux.h:153
FFStream::update_initial_durations_done
int update_initial_durations_done
Internal data to prevent doing update_initial_durations() twice.
Definition: internal.h:272
FFStream::start_skip_samples
int64_t start_skip_samples
If not 0, the number of samples that should be skipped from the start of the stream (the samples are ...
Definition: internal.h:217
estimate_timings_from_bit_rate
static void estimate_timings_from_bit_rate(AVFormatContext *ic)
Definition: demux.c:1797
FFStream::probe_packets
int probe_packets
Number of packets to buffer for codec probing.
Definition: internal.h:311
ff_rfps_calculate
void ff_rfps_calculate(AVFormatContext *ic)
Definition: demux.c:2378
avformat_internal.h
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
FFERROR_REDO
#define FFERROR_REDO
Returned by demuxers to indicate that data was consumed but discarded (ignored streams or junk data).
Definition: demux.h:181
FFStream::probe_data
AVProbeData probe_data
Definition: internal.h:298
AVCodec::id
enum AVCodecID id
Definition: codec.h:186
filesize
static int64_t filesize(AVIOContext *pb)
Definition: ffmpeg_mux.c:51
FFStream::skip_to_keyframe
int skip_to_keyframe
Indicates that everything up to the next keyframe should be discarded.
Definition: internal.h:203
avcodec_parameters_alloc
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: codec_par.c:57
FFStreamInfo::duration_error
double(* duration_error)[2][MAX_STD_TIMEBASES]
Definition: demux.h:154
AV_CODEC_ID_GIF
@ AV_CODEC_ID_GIF
Definition: codec_id.h:149
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:406
AVCodecContext::bits_per_coded_sample
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:1554
avcodec_send_packet
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
Definition: decode.c:709
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:68
AVFMT_FLAG_NOBUFFER
#define AVFMT_FLAG_NOBUFFER
Do not buffer frames when possible.
Definition: avformat.h:1422
AV_PKT_DATA_CPB_PROPERTIES
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
Definition: packet.h:142
ff_is_intra_only
int ff_is_intra_only(enum AVCodecID id)
Definition: avformat.c:850
AV_CODEC_ID_RV40
@ AV_CODEC_ID_RV40
Definition: codec_id.h:121
AVCodecParserContext::pos
int64_t pos
Byte position of currently parsed frame in stream.
Definition: avcodec.h:2691
PacketListEntry
Definition: packet_internal.h:28
PARSER_FLAG_COMPLETE_FRAMES
#define PARSER_FLAG_COMPLETE_FRAMES
Definition: avcodec.h:2623
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:581
avio_internal.h
ff_read_packet
int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
Read a transport packet from a media file.
Definition: demux.c:629
AVChapter::id
int64_t id
unique ID to identify the chapter
Definition: avformat.h:1224
AVCodecContext::extradata
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition: avcodec.h:522
AV_CODEC_ID_THEORA
@ AV_CODEC_ID_THEORA
Definition: codec_id.h:82
internal.h
find_probe_decoder
static const AVCodec * find_probe_decoder(AVFormatContext *s, const AVStream *st, enum AVCodecID codec_id)
Definition: demux.c:73
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:253
ff_id3v2_read_dict
void ff_id3v2_read_dict(AVIOContext *pb, AVDictionary **metadata, const char *magic, ID3v2ExtraMeta **extra_meta)
Read an ID3v2 tag into specified dictionary and retrieve supported extra metadata.
Definition: id3v2.c:1141
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:57
AVFormatContext::codec_whitelist
char * codec_whitelist
',' separated list of allowed decoders.
Definition: avformat.h:1748
AVCPBProperties::max_bitrate
int64_t max_bitrate
Maximum bitrate of the stream, in bits per second.
Definition: defs.h:287
compute_frame_duration
static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt)
Return the frame duration in seconds.
Definition: demux.c:696
delta
float delta
Definition: vorbis_enc_data.h:430
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:228
AV_DISPOSITION_KARAOKE
#define AV_DISPOSITION_KARAOKE
The stream contains karaoke audio.
Definition: avformat.h:643
av_always_inline
#define av_always_inline
Definition: attributes.h:63
ff_wrap_timestamp
int64_t ff_wrap_timestamp(const AVStream *st, int64_t timestamp)
Wrap a given time stamp, if there is an indication for an overflow.
Definition: demux.c:68
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
url.h
FFStream::pts_buffer
int64_t pts_buffer[MAX_REORDER_DELAY+1]
Definition: internal.h:282
av_find_default_stream_index
int av_find_default_stream_index(AVFormatContext *s)
Definition: avformat.c:340
AVPROBE_SCORE_RETRY
#define AVPROBE_SCORE_RETRY
Definition: avformat.h:458
AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED
@ AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED
Definition: defs.h:238
av_get_audio_frame_duration
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
Definition: utils.c:803
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1188
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
demux.h
AVCodecParameters::color_range
enum AVColorRange color_range
Video only.
Definition: codec_par.h:166
len
int len
Definition: vorbis_enc_data.h:426
AV_CODEC_ID_JPEG2000
@ AV_CODEC_ID_JPEG2000
Definition: codec_id.h:140
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:703
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
AVCodecContext::height
int height
Definition: avcodec.h:600
AVCodecParameters::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
Definition: codec_par.h:81
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:639
FFStreamInfo::frame_delay_evidence
int frame_delay_evidence
Definition: demux.h:157
update_timestamps
static void update_timestamps(AVFormatContext *s, AVStream *st, AVPacket *pkt)
Definition: demux.c:545
av_codec_iterate
const AVCodec * av_codec_iterate(void **opaque)
Iterate over all registered codecs.
Definition: allcodecs.c:994
try_decode_frame
static int try_decode_frame(AVFormatContext *s, AVStream *st, const AVPacket *pkt, AVDictionary **options)
Definition: demux.c:2119
avcodec.h
limit
static double limit(double x)
Definition: vf_pseudocolor.c:142
AVCodecParserContext
Definition: avcodec.h:2589
av_cmp_q
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
FFFormatContext::missing_streams
int missing_streams
Definition: internal.h:120
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:813
AVFMT_FLAG_GENPTS
#define AVFMT_FLAG_GENPTS
Generate missing pts even if it requires parsing future frames.
Definition: avformat.h:1416
AV_DISPOSITION_VISUAL_IMPAIRED
#define AV_DISPOSITION_VISUAL_IMPAIRED
The stream is intended for visually impaired audiences.
Definition: avformat.h:658
tag
uint32_t tag
Definition: movenc.c:2032
av_compare_mod
int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod)
Compare the remainders of two integer operands divided by a common divisor.
Definition: mathematics.c:160
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:756
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:744
pixfmt.h
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:236
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
AVCPBProperties::buffer_size
int64_t buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
Definition: defs.h:303
tb_unreliable
static int tb_unreliable(AVFormatContext *ic, AVStream *st)
Definition: demux.c:2292
AVSTREAM_PARSE_HEADERS
@ AVSTREAM_PARSE_HEADERS
Only parse headers, do not repack.
Definition: avformat.h:590
avformat.h
dict.h
AV_AUDIO_SERVICE_TYPE_KARAOKE
@ AV_AUDIO_SERVICE_TYPE_KARAOKE
Definition: defs.h:244
AVPacket::side_data
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
Definition: packet.h:599
id
enum AVCodecID id
Definition: dts2pts.c:549
av_sat_add64
#define av_sat_add64
Definition: common.h:139
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
AVCodecParameters::chroma_location
enum AVChromaLocation chroma_location
Definition: codec_par.h:170
FFInputFormat::read_close
int(* read_close)(struct AVFormatContext *)
Close the stream.
Definition: demux.h:96
AVCodecContext
main external API structure.
Definition: avcodec.h:439
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:750
FFStreamInfo::fps_first_dts_idx
int fps_first_dts_idx
Definition: demux.h:172
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:41
AV_PICTURE_TYPE_B
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:280
FFStreamInfo::duration_gcd
int64_t duration_gcd
Definition: demux.h:151
AVBitStreamFilter
Definition: bsf.h:111
av_packet_new_side_data
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
Definition: packet.c:231
AVInputFormat::flags
int flags
Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:563
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_AUDIO_SERVICE_TYPE_COMMENTARY
@ AV_AUDIO_SERVICE_TYPE_COMMENTARY
Definition: defs.h:241
ffifmt
static const FFInputFormat * ffifmt(const AVInputFormat *fmt)
Definition: demux.h:143
ff_flush_packet_queue
void ff_flush_packet_queue(AVFormatContext *s)
Definition: avformat.c:130
update_dts_from_pts
static void update_dts_from_pts(AVFormatContext *s, int stream_index, PacketListEntry *pkt_buffer)
Updates the dts of packets of a stream in pkt_buffer, by re-ordering the pts of the packets in a wind...
Definition: demux.c:839
DURATION_DEFAULT_MAX_READ_SIZE
#define DURATION_DEFAULT_MAX_READ_SIZE
Definition: demux.c:1850
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: avformat.c:141
ff_fc_internal
static av_always_inline FormatContextInternal * ff_fc_internal(AVFormatContext *s)
Definition: avformat_internal.h:100
PARSER_FLAG_USE_CODEC_TS
#define PARSER_FLAG_USE_CODEC_TS
Definition: avcodec.h:2627
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:878
AV_PKT_DATA_SKIP_SAMPLES
@ AV_PKT_DATA_SKIP_SAMPLES
Recommends skipping the specified number of samples.
Definition: packet.h:153
compute_pkt_fields
static void compute_pkt_fields(AVFormatContext *s, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt, int64_t next_dts, int64_t next_pts)
Definition: demux.c:978
AVSTREAM_PARSE_FULL_RAW
@ AVSTREAM_PARSE_FULL_RAW
full parsing and repack with timestamp and position generation by parser for raw this assumes that ea...
Definition: avformat.h:593
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
FFStream::info
struct FFStreamInfo * info
Stream information used internally by avformat_find_stream_info()
Definition: internal.h:182
AVFormatContext::duration
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1399
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
AVPacket::stream_index
int stream_index
Definition: packet.h:590
AVPROBE_SCORE_STREAM_RETRY
#define AVPROBE_SCORE_STREAM_RETRY
Definition: avformat.h:459
parse_packet
static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index, int flush)
Parse a packet, add all split parts to parse_queue.
Definition: demux.c:1173
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:321
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:449
av_gettime
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:39
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
AVIO_FLAG_READ
#define AVIO_FLAG_READ
read-only
Definition: avio.h:617
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:447
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
desc
const char * desc
Definition: libsvtav1.c:78
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
av_parser_parse2
int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts, int64_t pos)
Parse a packet.
Definition: parser.c:123
extract_extradata
static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket *pkt)
Definition: demux.c:2498
mem.h
packet_internal.h
FFFormatContext::pkt
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
Definition: internal.h:111
llrint
#define llrint(x)
Definition: libm.h:396
avcodec_parameters_from_context
int avcodec_parameters_from_context(struct AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: codec_par.c:138
AVCodecParameters::format
int format
Definition: codec_par.h:92
FFStream::request_probe
int request_probe
stream probing state -1 -> probing finished 0 -> no probing requested rest -> perform probing with re...
Definition: internal.h:198
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:464
AV_AUDIO_SERVICE_TYPE_EFFECTS
@ AV_AUDIO_SERVICE_TYPE_EFFECTS
Definition: defs.h:237
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:565
fill_all_stream_timings
static void fill_all_stream_timings(AVFormatContext *ic)
Definition: demux.c:1780
avio_closep
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
Definition: avio.c:650
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:86
av_dict_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:247
select_from_pts_buffer
static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t dts)
Definition: demux.c:791
ff_id3v2_free_extra_meta
void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta)
Free memory allocated parsing special (non-text) metadata.
Definition: id3v2.c:1153
FFStream::cur_dts
int64_t cur_dts
Definition: internal.h:338
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:608
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:600
timestamp.h
FFStream::need_context_update
int need_context_update
Whether the internal avctx needs to be updated from codecpar (after a late change to codecpar)
Definition: internal.h:173
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:97
ff_id3v2_parse_priv
int ff_id3v2_parse_priv(AVFormatContext *s, ID3v2ExtraMeta *extra_meta)
Add metadata for all PRIV tags in the ID3v2 header.
Definition: id3v2.c:1265
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVFormatContext::start_time
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1389
AV_CODEC_ID_AAC_LATM
@ AV_CODEC_ID_AAC_LATM
Definition: codec_id.h:509
FFStreamInfo::fps_last_dts_idx
int fps_last_dts_idx
Definition: demux.h:174
FFStream::parser
struct AVCodecParserContext * parser
Definition: internal.h:315
AV_CODEC_CAP_AVOID_PROBING
#define AV_CODEC_CAP_AVOID_PROBING
Decoder is not a preferred choice for probing.
Definition: codec.h:123
av_ts2str
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:54
a1
static double a1(void *priv, double x, double y)
Definition: vf_xfade.c:2029
estimate_timings
static void estimate_timings(AVFormatContext *ic, int64_t old_offset)
Definition: demux.c:2008
AVERROR_EXIT
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:58
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3887
has_decode_delay_been_guessed
static int has_decode_delay_been_guessed(AVStream *st)
Definition: demux.c:759
av_opt_set_dict
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition: opt.c:1986
AVStream::start_time
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition: avformat.h:793
PARSER_FLAG_ONCE
#define PARSER_FLAG_ONCE
Definition: avcodec.h:2624
AV_CODEC_ID_APTX
@ AV_CODEC_ID_APTX
Definition: codec_id.h:545
avstring.h
ff_reduce_index
void ff_reduce_index(AVFormatContext *s, int stream_index)
Ensure the index uses less memory than the maximum specified in AVFormatContext.max_index_size by dis...
Definition: seek.c:50
AVSTREAM_PARSE_TIMESTAMPS
@ AVSTREAM_PARSE_TIMESTAMPS
full parsing and interpolation of timestamps for frames not starting on a packet boundary
Definition: avformat.h:591
AVDiscard
AVDiscard
Definition: defs.h:223
AVStream::pts_wrap_bits
int pts_wrap_bits
Number of bits in timestamps.
Definition: avformat.h:887
AVChapter::time_base
AVRational time_base
time base in which the start/end timestamps are specified
Definition: avformat.h:1225
codec_desc.h
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:54
AV_CODEC_ID_MP1
@ AV_CODEC_ID_MP1
Definition: codec_id.h:502
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
FFStream::pts_wrap_reference
int64_t pts_wrap_reference
Internal data to check for wrapping of the time stamp.
Definition: internal.h:255
av_rescale_q_rnd
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
Definition: mathematics.c:134
compute_chapters_end
static int compute_chapters_end(AVFormatContext *s)
Definition: demux.c:2231
avpriv_codec_get_cap_skip_frame_fill_param
int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec)
Definition: utils.c:402
FormatContextInternal::parse_queue
PacketList parse_queue
Packets split by the parser get queued here.
Definition: avformat_internal.h:85
AVFMT_EVENT_FLAG_METADATA_UPDATED
#define AVFMT_EVENT_FLAG_METADATA_UPDATED
Definition: avformat.h:1638
avcodec_parameters_copy
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: codec_par.c:107
MAX_REORDER_DELAY
#define MAX_REORDER_DELAY
Definition: hw_base_encode.h:28
AVPacket::side_data_elems
int side_data_elems
Definition: packet.h:600
av_parser_close
void av_parser_close(AVCodecParserContext *s)
Definition: parser.c:201
av_cpb_properties_alloc
AVCPBProperties * av_cpb_properties_alloc(size_t *size)
Allocate a CPB properties structure and initialize its fields to default values.
Definition: utils.c:968
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:155
av_bsf_get_by_name
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
Definition: bitstream_filters.c:91