FFmpeg
avformat.c
Go to the documentation of this file.
1 /*
2  * Various functions used by both muxers and demuxers
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 <math.h>
23 #include "libavutil/avassert.h"
24 #include "libavutil/avstring.h"
26 #include "libavutil/frame.h"
27 #include "libavutil/iamf.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/mem.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/pixfmt.h"
32 #include "libavutil/samplefmt.h"
33 #include "libavcodec/avcodec.h"
34 #include "libavcodec/codec.h"
35 #include "libavcodec/bsf.h"
36 #include "libavcodec/codec_desc.h"
38 #include "avformat.h"
39 #include "avio.h"
40 #include "demux.h"
41 #include "mux.h"
42 #include "internal.h"
43 
45 {
46  AVStream *st = *pst;
47  FFStream *const sti = ffstream(st);
48 
49  if (!st)
50  return;
51 
52 #if FF_API_AVSTREAM_SIDE_DATA
54  for (int i = 0; i < st->nb_side_data; i++)
55  av_freep(&st->side_data[i].data);
56  av_freep(&st->side_data);
58 #endif
59 
60  if (st->attached_pic.data)
62 
63  av_parser_close(sti->parser);
65  av_bsf_free(&sti->bsfc);
66  av_freep(&sti->index_entries);
67  av_freep(&sti->probe_data.buf);
68 
70 
71  if (sti->info) {
73  av_freep(&sti->info);
74  }
75 
76  av_dict_free(&st->metadata);
78  av_freep(&st->priv_data);
79 
80  av_freep(pst);
81 }
82 
84 {
85  AVStreamGroup *stg = *pstg;
86 
87  if (!stg)
88  return;
89 
90  av_freep(&stg->streams);
91  av_dict_free(&stg->metadata);
92  av_freep(&stg->priv_data);
93  switch (stg->type) {
96  break;
97  }
100  break;
101  }
102  default:
103  break;
104  }
105 
106  av_freep(pstg);
107 }
108 
110 {
111  av_assert0(s->nb_streams>0);
112  av_assert0(s->streams[ s->nb_streams - 1 ] == st);
113 
114  ff_free_stream(&s->streams[ --s->nb_streams ]);
115 }
116 
117 /* XXX: suppress the packet queue */
119 {
120  FFFormatContext *const si = ffformatcontext(s);
124 
125  si->raw_packet_buffer_size = 0;
126 }
127 
129 {
130  FFFormatContext *si;
131 
132  if (!s)
133  return;
134  si = ffformatcontext(s);
135 
136  if (s->oformat && ffofmt(s->oformat)->deinit && si->initialized)
137  ffofmt(s->oformat)->deinit(s);
138 
139  av_opt_free(s);
140  if (s->iformat && s->iformat->priv_class && s->priv_data)
141  av_opt_free(s->priv_data);
142  if (s->oformat && s->oformat->priv_class && s->priv_data)
143  av_opt_free(s->priv_data);
144 
145  for (unsigned i = 0; i < s->nb_streams; i++)
146  ff_free_stream(&s->streams[i]);
147  for (unsigned i = 0; i < s->nb_stream_groups; i++)
148  ff_free_stream_group(&s->stream_groups[i]);
149  s->nb_stream_groups = 0;
150  s->nb_streams = 0;
151 
152  for (unsigned i = 0; i < s->nb_programs; i++) {
153  av_dict_free(&s->programs[i]->metadata);
154  av_freep(&s->programs[i]->stream_index);
155  av_freep(&s->programs[i]);
156  }
157  s->nb_programs = 0;
158 
159  av_freep(&s->programs);
160  av_freep(&s->priv_data);
161  while (s->nb_chapters--) {
162  av_dict_free(&s->chapters[s->nb_chapters]->metadata);
163  av_freep(&s->chapters[s->nb_chapters]);
164  }
165  av_freep(&s->chapters);
166  av_dict_free(&s->metadata);
167  av_dict_free(&si->id3v2_meta);
168  av_packet_free(&si->pkt);
170  av_freep(&s->streams);
171  av_freep(&s->stream_groups);
173  av_freep(&s->url);
174  av_free(s);
175 }
176 
177 #if FF_API_AVSTREAM_SIDE_DATA
179 uint8_t *av_stream_get_side_data(const AVStream *st,
180  enum AVPacketSideDataType type, size_t *size)
181 {
182  for (int i = 0; i < st->nb_side_data; i++) {
183  if (st->side_data[i].type == type) {
184  if (size)
185  *size = st->side_data[i].size;
186  return st->side_data[i].data;
187  }
188  }
189  if (size)
190  *size = 0;
191  return NULL;
192 }
193 
194 int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type,
195  uint8_t *data, size_t size)
196 {
197  AVPacketSideData *sd, *tmp;
198 
199  for (int i = 0; i < st->nb_side_data; i++) {
200  sd = &st->side_data[i];
201 
202  if (sd->type == type) {
203  av_freep(&sd->data);
204  sd->data = data;
205  sd->size = size;
206  return 0;
207  }
208  }
209 
210  if (st->nb_side_data + 1U > FFMIN(INT_MAX, SIZE_MAX / sizeof(*tmp)))
211  return AVERROR(ERANGE);
212 
213  tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp));
214  if (!tmp) {
215  return AVERROR(ENOMEM);
216  }
217 
218  st->side_data = tmp;
219  st->nb_side_data++;
220 
221  sd = &st->side_data[st->nb_side_data - 1];
222  sd->type = type;
223  sd->data = data;
224  sd->size = size;
225 
226  return 0;
227 }
228 
229 uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
230  size_t size)
231 {
232  int ret;
233  uint8_t *data = av_malloc(size);
234 
235  if (!data)
236  return NULL;
237 
238  ret = av_stream_add_side_data(st, type, data, size);
239  if (ret < 0) {
240  av_freep(&data);
241  return NULL;
242  }
243 
244  return data;
245 }
247 #endif
248 
249 /**
250  * Copy all stream parameters from source to destination stream, with the
251  * exception of the index field, which is usually set by avformat_new_stream().
252  *
253  * @param dst pointer to destination AVStream
254  * @param src pointer to source AVStream
255  * @return >=0 on success, AVERROR code on error
256  */
257 static int stream_params_copy(AVStream *dst, const AVStream *src)
258 {
259  int ret;
260 
261  dst->id = src->id;
262  dst->time_base = src->time_base;
263  dst->start_time = src->start_time;
264  dst->duration = src->duration;
265  dst->nb_frames = src->nb_frames;
266  dst->disposition = src->disposition;
267  dst->discard = src->discard;
268  dst->sample_aspect_ratio = src->sample_aspect_ratio;
269  dst->avg_frame_rate = src->avg_frame_rate;
270  dst->event_flags = src->event_flags;
271  dst->r_frame_rate = src->r_frame_rate;
272  dst->pts_wrap_bits = src->pts_wrap_bits;
273 
274  av_dict_free(&dst->metadata);
275  ret = av_dict_copy(&dst->metadata, src->metadata, 0);
276  if (ret < 0)
277  return ret;
278 
279  ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
280  if (ret < 0)
281  return ret;
282 
284  if (src->attached_pic.data) {
285  ret = av_packet_ref(&dst->attached_pic, &src->attached_pic);
286  if (ret < 0)
287  return ret;
288  }
289 
290  return 0;
291 }
292 
294 {
295  AVStream *st;
296  int ret;
297 
298  st = avformat_new_stream(dst_ctx, NULL);
299  if (!st)
300  return NULL;
301 
302  ret = stream_params_copy(st, src);
303  if (ret < 0) {
304  ff_remove_stream(dst_ctx, st);
305  return NULL;
306  }
307 
308  return st;
309 }
310 
312 {
314  int ret;
315 
316  av_log(ac, AV_LOG_TRACE, "new_program: id=0x%04x\n", id);
317 
318  for (unsigned i = 0; i < ac->nb_programs; i++)
319  if (ac->programs[i]->id == id)
320  program = ac->programs[i];
321 
322  if (!program) {
323  program = av_mallocz(sizeof(*program));
324  if (!program)
325  return NULL;
327  if (ret < 0) {
328  av_free(program);
329  return NULL;
330  }
331  program->discard = AVDISCARD_NONE;
332  program->pmt_version = -1;
333  program->id = id;
334  program->pts_wrap_reference = AV_NOPTS_VALUE;
335  program->pts_wrap_behavior = AV_PTS_WRAP_IGNORE;
336  program->start_time =
337  program->end_time = AV_NOPTS_VALUE;
338  }
339  return program;
340 }
341 
342 void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
343 {
345  void *tmp;
346 
347  if (idx >= ac->nb_streams) {
348  av_log(ac, AV_LOG_ERROR, "stream index %d is not valid\n", idx);
349  return;
350  }
351 
352  for (unsigned i = 0; i < ac->nb_programs; i++) {
353  if (ac->programs[i]->id != progid)
354  continue;
355  program = ac->programs[i];
356  for (unsigned j = 0; j < program->nb_stream_indexes; j++)
357  if (program->stream_index[j] == idx)
358  return;
359 
360  tmp = av_realloc_array(program->stream_index, program->nb_stream_indexes+1, sizeof(unsigned int));
361  if (!tmp)
362  return;
363  program->stream_index = tmp;
364  program->stream_index[program->nb_stream_indexes++] = idx;
365  return;
366  }
367 }
368 
370 {
371  for (unsigned i = 0; i < ic->nb_programs; i++) {
372  if (ic->programs[i] == last) {
373  last = NULL;
374  } else {
375  if (!last)
376  for (unsigned j = 0; j < ic->programs[i]->nb_stream_indexes; j++)
377  if (ic->programs[i]->stream_index[j] == s)
378  return ic->programs[i];
379  }
380  }
381  return NULL;
382 }
383 
385 {
386  int best_stream = 0;
387  int best_score = INT_MIN;
388 
389  if (s->nb_streams <= 0)
390  return -1;
391  for (unsigned i = 0; i < s->nb_streams; i++) {
392  const AVStream *const st = s->streams[i];
393  const FFStream *const sti = cffstream(st);
394  int score = 0;
395  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
397  score -= 400;
398  if (st->codecpar->width && st->codecpar->height)
399  score += 50;
400  score+= 25;
401  }
402  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
403  if (st->codecpar->sample_rate)
404  score += 50;
405  }
406  if (sti->codec_info_nb_frames)
407  score += 12;
408 
409  if (st->discard != AVDISCARD_ALL)
410  score += 200;
411 
412  if (score > best_score) {
413  best_score = score;
414  best_stream = i;
415  }
416  }
417  return best_stream;
418 }
419 
421  int wanted_stream_nb, int related_stream,
422  const AVCodec **decoder_ret, int flags)
423 {
424  int nb_streams = ic->nb_streams;
426  int best_count = -1, best_multiframe = -1, best_disposition = -1;
427  int count, multiframe, disposition;
428  int64_t best_bitrate = -1;
429  int64_t bitrate;
430  unsigned *program = NULL;
431  const AVCodec *decoder = NULL, *best_decoder = NULL;
432 
433  if (related_stream >= 0 && wanted_stream_nb < 0) {
434  AVProgram *p = av_find_program_from_stream(ic, NULL, related_stream);
435  if (p) {
436  program = p->stream_index;
438  }
439  }
440  for (unsigned i = 0; i < nb_streams; i++) {
441  int real_stream_index = program ? program[i] : i;
442  AVStream *st = ic->streams[real_stream_index];
443  AVCodecParameters *par = st->codecpar;
444  if (par->codec_type != type)
445  continue;
446  if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
447  continue;
448  if (type == AVMEDIA_TYPE_AUDIO && !(par->ch_layout.nb_channels && par->sample_rate))
449  continue;
450  if (decoder_ret) {
451  decoder = ff_find_decoder(ic, st, par->codec_id);
452  if (!decoder) {
453  if (ret < 0)
455  continue;
456  }
457  }
459  + !! (st->disposition & AV_DISPOSITION_DEFAULT);
460  count = ffstream(st)->codec_info_nb_frames;
461  bitrate = par->bit_rate;
462  multiframe = FFMIN(5, count);
463  if ((best_disposition > disposition) ||
464  (best_disposition == disposition && best_multiframe > multiframe) ||
465  (best_disposition == disposition && best_multiframe == multiframe && best_bitrate > bitrate) ||
466  (best_disposition == disposition && best_multiframe == multiframe && best_bitrate == bitrate && best_count >= count))
467  continue;
468  best_disposition = disposition;
469  best_count = count;
470  best_bitrate = bitrate;
471  best_multiframe = multiframe;
472  ret = real_stream_index;
473  best_decoder = decoder;
474  if (program && i == nb_streams - 1 && ret < 0) {
475  program = NULL;
476  nb_streams = ic->nb_streams;
477  /* no related stream found, try again with everything */
478  i = 0;
479  }
480  }
481  if (decoder_ret)
482  *decoder_ret = best_decoder;
483  return ret;
484 }
485 
486 /**
487  * Matches a stream specifier (but ignores requested index).
488  *
489  * @param indexptr set to point to the requested stream index if there is one
490  *
491  * @return <0 on error
492  * 0 if st is NOT a matching stream
493  * >0 if st is a matching stream
494  */
495 static int match_stream_specifier(const AVFormatContext *s, const AVStream *st,
496  const char *spec, const char **indexptr,
497  const AVStreamGroup **g, const AVProgram **p)
498 {
499  int match = 1; /* Stores if the specifier matches so far. */
500  while (*spec) {
501  if (*spec <= '9' && *spec >= '0') { /* opt:index */
502  if (indexptr)
503  *indexptr = spec;
504  return match;
505  } else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||
506  *spec == 't' || *spec == 'V') { /* opt:[vasdtV] */
507  enum AVMediaType type;
508  int nopic = 0;
509 
510  switch (*spec++) {
511  case 'v': type = AVMEDIA_TYPE_VIDEO; break;
512  case 'a': type = AVMEDIA_TYPE_AUDIO; break;
513  case 's': type = AVMEDIA_TYPE_SUBTITLE; break;
514  case 'd': type = AVMEDIA_TYPE_DATA; break;
515  case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
516  case 'V': type = AVMEDIA_TYPE_VIDEO; nopic = 1; break;
517  default: av_assert0(0);
518  }
519  if (*spec && *spec++ != ':') /* If we are not at the end, then another specifier must follow. */
520  return AVERROR(EINVAL);
521 
522  if (type != st->codecpar->codec_type)
523  match = 0;
524  if (nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC))
525  match = 0;
526  } else if (*spec == 'g' && *(spec + 1) == ':') {
527  int64_t group_idx = -1, group_id = -1;
528  int found = 0;
529  char *endptr;
530  spec += 2;
531  if (*spec == '#' || (*spec == 'i' && *(spec + 1) == ':')) {
532  spec += 1 + (*spec == 'i');
533  group_id = strtol(spec, &endptr, 0);
534  if (spec == endptr || (*endptr && *endptr++ != ':'))
535  return AVERROR(EINVAL);
536  spec = endptr;
537  } else {
538  group_idx = strtol(spec, &endptr, 0);
539  /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
540  if (spec == endptr || (*endptr && *endptr++ != ':'))
541  return AVERROR(EINVAL);
542  spec = endptr;
543  }
544  if (match) {
545  if (group_id > 0) {
546  for (unsigned i = 0; i < s->nb_stream_groups; i++) {
547  if (group_id == s->stream_groups[i]->id) {
548  group_idx = i;
549  break;
550  }
551  }
552  }
553  if (group_idx < 0 || group_idx >= s->nb_stream_groups)
554  return AVERROR(EINVAL);
555  for (unsigned j = 0; j < s->stream_groups[group_idx]->nb_streams; j++) {
556  if (st->index == s->stream_groups[group_idx]->streams[j]->index) {
557  found = 1;
558  if (g)
559  *g = s->stream_groups[group_idx];
560  break;
561  }
562  }
563  }
564  if (!found)
565  match = 0;
566  } else if (*spec == 'p' && *(spec + 1) == ':') {
567  int prog_id;
568  int found = 0;
569  char *endptr;
570  spec += 2;
571  prog_id = strtol(spec, &endptr, 0);
572  /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
573  if (spec == endptr || (*endptr && *endptr++ != ':'))
574  return AVERROR(EINVAL);
575  spec = endptr;
576  if (match) {
577  for (unsigned i = 0; i < s->nb_programs; i++) {
578  if (s->programs[i]->id != prog_id)
579  continue;
580 
581  for (unsigned j = 0; j < s->programs[i]->nb_stream_indexes; j++) {
582  if (st->index == s->programs[i]->stream_index[j]) {
583  found = 1;
584  if (p)
585  *p = s->programs[i];
586  i = s->nb_programs;
587  break;
588  }
589  }
590  }
591  }
592  if (!found)
593  match = 0;
594  } else if (*spec == '#' ||
595  (*spec == 'i' && *(spec + 1) == ':')) {
596  int stream_id;
597  char *endptr;
598  spec += 1 + (*spec == 'i');
599  stream_id = strtol(spec, &endptr, 0);
600  if (spec == endptr || *endptr) /* Disallow empty id and make sure we are at the end. */
601  return AVERROR(EINVAL);
602  return match && (stream_id == st->id);
603  } else if (*spec == 'm' && *(spec + 1) == ':') {
604  const AVDictionaryEntry *tag;
605  char *key, *val;
606  int ret;
607 
608  if (match) {
609  spec += 2;
610  val = strchr(spec, ':');
611 
612  key = val ? av_strndup(spec, val - spec) : av_strdup(spec);
613  if (!key)
614  return AVERROR(ENOMEM);
615 
616  tag = av_dict_get(st->metadata, key, NULL, 0);
617  if (tag) {
618  if (!val || !strcmp(tag->value, val + 1))
619  ret = 1;
620  else
621  ret = 0;
622  } else
623  ret = 0;
624 
625  av_freep(&key);
626  }
627  return match && ret;
628  } else if (*spec == 'u' && *(spec + 1) == '\0') {
629  const AVCodecParameters *par = st->codecpar;
630  int val;
631  switch (par->codec_type) {
632  case AVMEDIA_TYPE_AUDIO:
633  val = par->sample_rate && par->ch_layout.nb_channels;
634  if (par->format == AV_SAMPLE_FMT_NONE)
635  return 0;
636  break;
637  case AVMEDIA_TYPE_VIDEO:
638  val = par->width && par->height;
639  if (par->format == AV_PIX_FMT_NONE)
640  return 0;
641  break;
643  val = 0;
644  break;
645  default:
646  val = 1;
647  break;
648  }
649  return match && (par->codec_id != AV_CODEC_ID_NONE && val != 0);
650  } else {
651  return AVERROR(EINVAL);
652  }
653  }
654 
655  return match;
656 }
657 
659  const char *spec)
660 {
661  int ret, index;
662  char *endptr;
663  const char *indexptr = NULL;
664  const AVStreamGroup *g = NULL;
665  const AVProgram *p = NULL;
666  int nb_streams;
667 
668  ret = match_stream_specifier(s, st, spec, &indexptr, &g, &p);
669  if (ret < 0)
670  goto error;
671 
672  if (!indexptr)
673  return ret;
674 
675  index = strtol(indexptr, &endptr, 0);
676  if (*endptr) { /* We can't have anything after the requested index. */
677  ret = AVERROR(EINVAL);
678  goto error;
679  }
680 
681  /* This is not really needed but saves us a loop for simple stream index specifiers. */
682  if (spec == indexptr)
683  return (index == st->index);
684 
685  /* If we requested a matching stream index, we have to ensure st is that. */
686  nb_streams = g ? g->nb_streams : (p ? p->nb_stream_indexes : s->nb_streams);
687  for (int i = 0; i < nb_streams && index >= 0; i++) {
688  unsigned idx = g ? g->streams[i]->index : (p ? p->stream_index[i] : i);
689  const AVStream *candidate = s->streams[idx];
690  ret = match_stream_specifier(s, candidate, spec, NULL, NULL, NULL);
691  if (ret < 0)
692  goto error;
693  if (ret > 0 && index-- == 0 && st == candidate)
694  return 1;
695  }
696  return 0;
697 
698 error:
699  if (ret == AVERROR(EINVAL))
700  av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
701  return ret;
702 }
703 
705 {
706  AVRational undef = {0, 1};
707  AVRational stream_sample_aspect_ratio = stream ? stream->sample_aspect_ratio : undef;
708  AVRational codec_sample_aspect_ratio = stream && stream->codecpar ? stream->codecpar->sample_aspect_ratio : undef;
709  AVRational frame_sample_aspect_ratio = frame ? frame->sample_aspect_ratio : codec_sample_aspect_ratio;
710 
711  av_reduce(&stream_sample_aspect_ratio.num, &stream_sample_aspect_ratio.den,
712  stream_sample_aspect_ratio.num, stream_sample_aspect_ratio.den, INT_MAX);
713  if (stream_sample_aspect_ratio.num <= 0 || stream_sample_aspect_ratio.den <= 0)
714  stream_sample_aspect_ratio = undef;
715 
716  av_reduce(&frame_sample_aspect_ratio.num, &frame_sample_aspect_ratio.den,
717  frame_sample_aspect_ratio.num, frame_sample_aspect_ratio.den, INT_MAX);
718  if (frame_sample_aspect_ratio.num <= 0 || frame_sample_aspect_ratio.den <= 0)
719  frame_sample_aspect_ratio = undef;
720 
721  if (stream_sample_aspect_ratio.num)
722  return stream_sample_aspect_ratio;
723  else
724  return frame_sample_aspect_ratio;
725 }
726 
728 {
729  AVRational fr = st->r_frame_rate;
731  AVRational avg_fr = st->avg_frame_rate;
732 
733  if (avg_fr.num > 0 && avg_fr.den > 0 && fr.num > 0 && fr.den > 0 &&
734  av_q2d(avg_fr) < 70 && av_q2d(fr) > 210) {
735  fr = avg_fr;
736  }
737 
738  if (desc && (desc->props & AV_CODEC_PROP_FIELDS)) {
739  const AVCodecContext *const avctx = ffstream(st)->avctx;
740  AVRational codec_fr = avctx->framerate;
741 
742  if ( codec_fr.num > 0 && codec_fr.den > 0 &&
743  (fr.num == 0 || av_q2d(codec_fr) < av_q2d(fr)*0.7 && fabs(1.0 - av_q2d(av_div_q(avg_fr, fr))) > 0.1))
744  fr = codec_fr;
745  }
746 
747  return fr;
748 }
749 
751  AVStream *ost, const AVStream *ist,
753 {
755  const AVCodecContext *const dec_ctx = cffstream(ist)->avctx;
756 
757  AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 };
758  AVRational dec_ctx_framerate = dec_ctx ? dec_ctx->framerate : (AVRational){ 0, 0 };
759  AVRational dec_ctx_tb = dec_ctx_framerate.num ? av_inv_q(av_mul_q(dec_ctx_framerate, mul))
760  : (ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ? (AVRational){0, 1}
761  : ist->time_base);
762  AVRational enc_tb = ist->time_base;
763 #if FF_API_TICKS_PER_FRAME
765  int ticks_per_frame = dec_ctx ? dec_ctx->ticks_per_frame : 1;
767 #endif
768 
769  /*
770  * Avi is a special case here because it supports variable fps but
771  * having the fps and timebase differe significantly adds quite some
772  * overhead
773  */
774  if (!strcmp(ofmt->name, "avi")) {
775 #if FF_API_R_FRAME_RATE
776  if (copy_tb == AVFMT_TBCF_AUTO && ist->r_frame_rate.num
777  && av_q2d(ist->r_frame_rate) >= av_q2d(ist->avg_frame_rate)
778  && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(ist->time_base)
779  && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(dec_ctx_tb)
780  && av_q2d(ist->time_base) < 1.0/500 && av_q2d(dec_ctx_tb) < 1.0/500
781  || copy_tb == AVFMT_TBCF_R_FRAMERATE) {
782  enc_tb.num = ist->r_frame_rate.den;
783  enc_tb.den = 2*ist->r_frame_rate.num;
784  } else
785 #endif
786  if (copy_tb == AVFMT_TBCF_AUTO && dec_ctx_framerate.num &&
787  av_q2d(av_inv_q(dec_ctx_framerate)) > 2*av_q2d(ist->time_base)
788  && av_q2d(ist->time_base) < 1.0/500
789  || (copy_tb == AVFMT_TBCF_DECODER &&
790  (dec_ctx_framerate.num || ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))) {
791  enc_tb = dec_ctx_tb;
792  enc_tb.den *= 2;
793 #if FF_API_TICKS_PER_FRAME
794  enc_tb.num *= ticks_per_frame;
795 #endif
796  }
797  } else if (!(ofmt->flags & AVFMT_VARIABLE_FPS)
798  && !av_match_name(ofmt->name, "mov,mp4,3gp,3g2,psp,ipod,ismv,f4v")) {
799  if (copy_tb == AVFMT_TBCF_AUTO && dec_ctx_framerate.num
800  && av_q2d(av_inv_q(dec_ctx_framerate)) > av_q2d(ist->time_base)
801  && av_q2d(ist->time_base) < 1.0/500
802  || (copy_tb == AVFMT_TBCF_DECODER &&
803  (dec_ctx_framerate.num || ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))) {
804  enc_tb = dec_ctx_tb;
805 #if FF_API_TICKS_PER_FRAME
806  enc_tb.num *= ticks_per_frame;
807 #endif
808  }
809  }
810 
811  if (ost->codecpar->codec_tag == AV_RL32("tmcd")
812  && dec_ctx_tb.num < dec_ctx_tb.den
813  && dec_ctx_tb.num > 0
814  && 121LL*dec_ctx_tb.num > dec_ctx_tb.den) {
815  enc_tb = dec_ctx_tb;
816  }
817 
818  av_reduce(&ffstream(ost)->transferred_mux_tb.num,
819  &ffstream(ost)->transferred_mux_tb.den,
820  enc_tb.num, enc_tb.den, INT_MAX);
821 
822  return 0;
823 }
824 
826 {
828 }
829 
830 void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits,
831  unsigned int pts_num, unsigned int pts_den)
832 {
833  FFStream *const sti = ffstream(st);
834  AVRational new_tb;
835  if (av_reduce(&new_tb.num, &new_tb.den, pts_num, pts_den, INT_MAX)) {
836  if (new_tb.num != pts_num)
838  "st:%d removing common factor %d from timebase\n",
839  st->index, pts_num / new_tb.num);
840  } else
842  "st:%d has too large timebase, reducing\n", st->index);
843 
844  if (new_tb.num <= 0 || new_tb.den <= 0) {
846  "Ignoring attempt to set invalid timebase %d/%d for st:%d\n",
847  new_tb.num, new_tb.den,
848  st->index);
849  return;
850  }
851  st->time_base = new_tb;
852  if (sti->avctx)
853  sti->avctx->pkt_timebase = new_tb;
854  st->pts_wrap_bits = pts_wrap_bits;
855 }
856 
858  enum AVCodecID codec_id)
859 {
860  switch (st->codecpar->codec_type) {
861  case AVMEDIA_TYPE_VIDEO:
862  if (s->video_codec) return s->video_codec;
863  break;
864  case AVMEDIA_TYPE_AUDIO:
865  if (s->audio_codec) return s->audio_codec;
866  break;
868  if (s->subtitle_codec) return s->subtitle_codec;
869  break;
870  }
871 
873 }
874 
876 {
877 #define OFF(field) offsetof(AVFormatContext, field)
878  static const unsigned offsets[] = {
879  OFF(codec_whitelist), OFF(format_whitelist),
880  OFF(protocol_whitelist), OFF(protocol_blacklist),
881  };
882 #undef OFF
883  av_assert0(!dst->codec_whitelist &&
884  !dst->format_whitelist &&
885  !dst->protocol_whitelist &&
886  !dst->protocol_blacklist);
887  for (unsigned i = 0; i < FF_ARRAY_ELEMS(offsets); i++) {
888  const char *src_str = *(char *const*)((const char*)src + offsets[i]);
889 
890  if (src_str) {
891  char *dst_str = av_strdup(src_str);
892  if (!dst_str) {
893  av_log(dst, AV_LOG_ERROR, "Failed to duplicate black/whitelist\n");
894  return AVERROR(ENOMEM);
895  }
896 
897  *(char **)((char*)dst + offsets[i]) = dst_str;
898  }
899  }
900  return 0;
901 }
902 
904 {
906  if (!d)
907  return 0;
908  if ((d->type == AVMEDIA_TYPE_VIDEO || d->type == AVMEDIA_TYPE_AUDIO) &&
909  !(d->props & AV_CODEC_PROP_INTRA_ONLY))
910  return 0;
911  return 1;
912 }
913 
915 {
916  av_assert0(url);
917  av_freep(&s->url);
918  s->url = url;
919 }
920 
922 {
923  int ret = 0;
924  if (*pb) {
925 #if FF_API_AVFORMAT_IO_CLOSE
927  if (s->io_close == ff_format_io_close_default || s->io_close == NULL)
928 #endif
929  ret = s->io_close2(s, *pb);
930 #if FF_API_AVFORMAT_IO_CLOSE
931  else
932  s->io_close(s, *pb);
934 #endif
935  }
936  *pb = NULL;
937  return ret;
938 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
iamf.h
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:427
AVCodec
AVCodec.
Definition: codec.h:187
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
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
dec_ctx
static AVCodecContext * dec_ctx
Definition: decode_filter_audio.c:46
AVOutputFormat::name
const char * name
Definition: avformat.h:511
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
AVProgram::nb_stream_indexes
unsigned int nb_stream_indexes
Definition: avformat.h:1131
av_find_best_stream
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, const AVCodec **decoder_ret, int flags)
Definition: avformat.c:420
FFStream::bsfc
struct AVBSFContext * bsfc
bitstream filter to run on stream
Definition: internal.h:217
ff_find_decoder
const AVCodec * ff_find_decoder(AVFormatContext *s, const AVStream *st, enum AVCodecID codec_id)
Definition: avformat.c:857
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
FFStream::bsf
struct AVBSFContext * bsf
Definition: internal.h:237
ffformatcontext
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition: internal.h:194
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
AVStream::priv_data
void * priv_data
Definition: avformat.h:866
AVFMT_VARIABLE_FPS
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:483
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:772
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:912
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:369
av_div_q
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition: rational.c:88
AVFormatContext::protocol_blacklist
char * protocol_blacklist
',' separated list of disallowed protocols.
Definition: avformat.h:1779
AVFMT_TBCF_DECODER
@ AVFMT_TBCF_DECODER
Definition: avformat.h:2987
AV_DISPOSITION_DEFAULT
#define AV_DISPOSITION_DEFAULT
The stream should be chosen by default among other streams of the same type, unless the user has expl...
Definition: avformat.h:719
AVFMT_TBCF_AUTO
@ AVFMT_TBCF_AUTO
Definition: avformat.h:2986
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1270
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:373
AVPacket::data
uint8_t * data
Definition: packet.h:522
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:930
data
const char data[16]
Definition: mxf.c:148
FFFormatContext::initialized
int initialized
Whether or not avformat_init_output has already been called.
Definition: internal.h:166
av_iamf_mix_presentation_free
void av_iamf_mix_presentation_free(AVIAMFMixPresentation **pmix_presentation)
Free an AVIAMFMixPresentation and all its contents.
Definition: iamf.c:534
AVFormatContext::programs
AVProgram ** programs
Definition: avformat.h:1370
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:59
cffstream
static const av_always_inline FFStream * cffstream(const AVStream *st)
Definition: internal.h:428
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:323
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
ost
static AVStream * ost
Definition: vaapi_transcode.c:42
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:74
FFStream::transferred_mux_tb
AVRational transferred_mux_tb
Definition: internal.h:420
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
FFStream::codec_desc
const struct AVCodecDescriptor * codec_desc
Definition: internal.h:418
OFF
#define OFF(field)
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:1807
AVPacketSideData::size
size_t size
Definition: packet.h:375
ff_remove_stream
void ff_remove_stream(AVFormatContext *s, AVStream *st)
Remove a stream from its AVFormatContext and free it.
Definition: avformat.c:109
ff_free_stream_group
void ff_free_stream_group(AVStreamGroup **pstg)
Frees a stream group without modifying the corresponding AVFormatContext.
Definition: avformat.c:83
decoder
static const chunk_decoder decoder[8]
Definition: dfa.c:331
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: avformat.c:830
bsf.h
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:423
stream_params_copy
static int stream_params_copy(AVStream *dst, const AVStream *src)
Copy all stream parameters from source to destination stream, with the exception of the index field,...
Definition: avformat.c:257
samplefmt.h
av_iamf_audio_element_free
void av_iamf_audio_element_free(AVIAMFAudioElement **paudio_element)
Free an AVIAMFAudioElement and all its contents.
Definition: iamf.c:336
FFStream::avctx
struct AVCodecContext * avctx
The codec context used by avformat_find_stream_info, the parser, etc.
Definition: internal.h:227
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: defs.h:213
val
static double val(void *priv, double ch)
Definition: aeval.c:78
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
av_new_program
AVProgram * av_new_program(AVFormatContext *ac, int id)
Definition: avformat.c:311
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:900
AV_PTS_WRAP_IGNORE
#define AV_PTS_WRAP_IGNORE
Options for behavior on timestamp wrap detection.
Definition: avformat.h:830
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
codec.h
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVStream::attached_pic
AVPacket attached_pic
For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet will contain the attached pictu...
Definition: avformat.h:939
avassert.h
AVFormatContext::format_whitelist
char * format_whitelist
',' separated list of allowed demuxers.
Definition: avformat.h:1654
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVProgram::id
int id
Definition: avformat.h:1127
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:62
AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION
@ AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION
Definition: avformat.h:1022
FFFormatContext::parse_queue
PacketList parse_queue
Packets split by the parser get queued here.
Definition: internal.h:119
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
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:104
offsets
static const int offsets[]
Definition: hevc_pel.c:34
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:215
format
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
AVCodecParameters::sample_aspect_ratio
AVRational sample_aspect_ratio
Video only.
Definition: codec_par.h:131
AVFormatContext::nb_programs
unsigned int nb_programs
Definition: avformat.h:1369
bitrate
int64_t bitrate
Definition: av1_levels.c:47
g
const char * g
Definition: vf_curves.c:127
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:454
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:121
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
AVPacketSideData::data
uint8_t * data
Definition: packet.h:374
av_guess_sample_aspect_ratio
AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *stream, AVFrame *frame)
Guess the sample aspect ratio of a frame, based on both the stream and the frame aspect ratio.
Definition: avformat.c:704
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:398
ffofmt
static const FFOutputFormat * ffofmt(const AVOutputFormat *fmt)
Definition: mux.h:138
nb_streams
static int nb_streams
Definition: ffprobe.c:328
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:389
key
const char * key
Definition: hwcontext_opencl.c:174
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
frame
static AVFrame * frame
Definition: demux_decode.c:54
FFFormatContext
Definition: internal.h:70
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:219
AVFormatContext
Format I/O context.
Definition: avformat.h:1202
AV_CODEC_PROP_INTRA_ONLY
#define AV_CODEC_PROP_INTRA_ONLY
Codec uses only intra compression.
Definition: codec_desc.h:72
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:864
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
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:880
NULL
#define NULL
Definition: coverity.c:32
av_program_add_stream_index
void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
Definition: avformat.c:342
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:66
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:169
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVFormatContext::protocol_whitelist
char * protocol_whitelist
',' separated list of allowed protocols.
Definition: avformat.h:1739
ff_copy_whiteblacklists
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
Copies the whilelists from one context to the other.
Definition: avformat.c:875
AVPacketSideData::type
enum AVPacketSideDataType type
Definition: packet.h:376
FFOutputFormat::deinit
void(* deinit)(AVFormatContext *)
Deinitialize format.
Definition: mux.h:125
AVProgram::stream_index
unsigned int * stream_index
Definition: avformat.h:1130
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:921
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1719
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: avpacket.c:435
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:206
index
int index
Definition: gxfenc.c:89
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:171
AVStream::nb_frames
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:902
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:981
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1258
FFFormatContext::id3v2_meta
AVDictionary * id3v2_meta
ID3v2 tag useful for MP3 demuxing.
Definition: internal.h:176
AVOutputFormat::flags
int flags
can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:530
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:567
AVIOContext
Bytestream IO Context.
Definition: avio.h:166
AVMediaType
AVMediaType
Definition: avutil.h:199
avformat_match_stream_specifier
int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the stream st contained in s is matched by the stream specifier spec.
Definition: avformat.c:658
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:133
avpriv_packet_list_free
void avpriv_packet_list_free(PacketList *pkt_buf)
Wipe the list and unref all the packets in it.
Definition: avpacket.c:594
FFStream
Definition: internal.h:199
ff_free_stream
void ff_free_stream(AVStream **pst)
Frees a stream without modifying the corresponding AVFormatContext.
Definition: avformat.c:44
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition: avcodec.h:1821
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
ff_format_io_close_default
void ff_format_io_close_default(AVFormatContext *s, AVIOContext *pb)
size
int size
Definition: twinvq_data.h:10344
avio.h
copy_tb
int copy_tb
Definition: ffmpeg_opt.c:75
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AV_CODEC_PROP_FIELDS
#define AV_CODEC_PROP_FIELDS
Video codec supports separate coding of fields in interlaced frames.
Definition: codec_desc.h:97
AVStreamGroup::iamf_audio_element
struct AVIAMFAudioElement * iamf_audio_element
Definition: avformat.h:1061
AVStream::event_flags
int event_flags
Flags indicating events happening on the stream, a combination of AVSTREAM_EVENT_FLAG_*.
Definition: avformat.h:984
av_stream_get_codec_timebase
AVRational av_stream_get_codec_timebase(const AVStream *st)
Get the internal codec timebase from a stream.
Definition: avformat.c:825
ff_format_io_close
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: avformat.c:921
AVTimebaseSource
AVTimebaseSource
Definition: avformat.h:2985
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:919
frame.h
AV_DISPOSITION_HEARING_IMPAIRED
#define AV_DISPOSITION_HEARING_IMPAIRED
The stream is intended for hearing impaired audiences.
Definition: avformat.h:756
AVStreamGroup::params
union AVStreamGroup::@294 params
Group type-specific parameters.
FFFormatContext::raw_packet_buffer_size
int raw_packet_buffer_size
Sum of the size of packets in raw_packet_buffer, in bytes.
Definition: internal.h:144
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:225
AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT
@ AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT
Definition: avformat.h:1021
AVStreamGroup::streams
AVStream ** streams
A list of streams in the group.
Definition: avformat.h:1093
AVStreamGroup::iamf_mix_presentation
struct AVIAMFMixPresentation * iamf_mix_presentation
Definition: avformat.h:1062
FFStream::probe_data
AVProbeData probe_data
Definition: internal.h:376
FFStreamInfo::duration_error
double(* duration_error)[2][MAX_STD_TIMEBASES]
Definition: demux.h:35
FFFormatContext::raw_packet_buffer
PacketList raw_packet_buffer
Raw packets from the demuxer, prior to parsing and decoding.
Definition: internal.h:115
ff_is_intra_only
int ff_is_intra_only(enum AVCodecID id)
Definition: avformat.c:903
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
AVOutputFormat
Definition: avformat.h:510
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:245
AVCodecParameters::height
int height
Definition: codec_par.h:122
AVFormatContext::codec_whitelist
char * codec_whitelist
',' separated list of allowed decoders.
Definition: avformat.h:1646
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:205
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_find_default_stream_index
int av_find_default_stream_index(AVFormatContext *s)
Definition: avformat.c:384
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1126
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
demux.h
avcodec.h
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:910
match_stream_specifier
static int match_stream_specifier(const AVFormatContext *s, const AVStream *st, const char *spec, const char **indexptr, const AVStreamGroup **g, const AVProgram **p)
Matches a stream specifier (but ignores requested index).
Definition: avformat.c:495
AV_DISPOSITION_VISUAL_IMPAIRED
#define AV_DISPOSITION_VISUAL_IMPAIRED
The stream is intended for visually impaired audiences.
Definition: avformat.h:760
tag
uint32_t tag
Definition: movenc.c:1786
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:853
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:841
av_guess_frame_rate
AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame)
Guess the frame rate, based on both the container and codec information.
Definition: avformat.c:727
pixfmt.h
AVStreamGroup::metadata
AVDictionary * metadata
Metadata that applies to the whole group.
Definition: avformat.h:1073
avformat.h
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:447
id
enum AVCodecID id
Definition: dts2pts.c:364
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
U
#define U(x)
Definition: vpx_arith.h:37
FFStream::extract_extradata
struct FFStream::@314 extract_extradata
av_dynarray_add_nofree
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
Definition: mem.c:313
AVStreamGroup
Definition: avformat.h:1028
AVCodecContext
main external API structure.
Definition: avcodec.h:445
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:847
avformat_transfer_internal_stream_timing_info
int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, AVStream *ost, const AVStream *ist, enum AVTimebaseSource copy_tb)
Transfer internal timing information from one stream to another.
Definition: avformat.c:750
channel_layout.h
AVERROR_STREAM_NOT_FOUND
#define AVERROR_STREAM_NOT_FOUND
Stream not found.
Definition: error.h:67
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
ff_flush_packet_queue
void ff_flush_packet_queue(AVFormatContext *s)
Definition: avformat.c:118
av_match_name
int av_match_name(const char *name, const char *names)
Match instances of a name in a comma-separated list of names.
Definition: avstring.c:345
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: avformat.c:128
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:1007
AVCodecContext::ticks_per_frame
attribute_deprecated int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:583
AVPacketSideDataType
AVPacketSideDataType
Definition: packet.h:41
FFStream::info
struct FFStreamInfo * info
Stream information used internally by avformat_find_stream_info()
Definition: internal.h:253
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
FFStream::index_entries
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: internal.h:255
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
AVERROR_DECODER_NOT_FOUND
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
Definition: error.h:54
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:270
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
AVStreamGroup::type
enum AVStreamGroupParamsType type
Group type.
Definition: avformat.h:1055
packet_internal.h
FFFormatContext::pkt
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
Definition: internal.h:140
AVCodecParameters::format
int format
Definition: codec_par.h:79
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVDictionaryEntry
Definition: dict.h:89
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
ff_stream_clone
AVStream * ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src)
Create a new stream and copy to it all parameters from a source stream, with the exception of the ind...
Definition: avformat.c:293
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
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:239
d
d
Definition: ffmpeg_filter.c:424
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:84
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
FFStream::parser
struct AVCodecParserContext * parser
Definition: internal.h:393
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3736
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:890
avstring.h
av_strndup
char * av_strndup(const char *s, size_t len)
Duplicate a substring of a string.
Definition: mem.c:282
AVStream::pts_wrap_bits
int pts_wrap_bits
Number of bits in timestamps.
Definition: avformat.h:1016
codec_desc.h
AVStreamGroup::priv_data
void * priv_data
Definition: avformat.h:1034
ff_format_set_url
void ff_format_set_url(AVFormatContext *s, char *url)
Set AVFormatContext url field to the provided pointer.
Definition: avformat.c:914
avcodec_parameters_copy
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: codec_par.c:106
av_parser_close
void av_parser_close(AVCodecParserContext *s)
Definition: parser.c:193
mux.h