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 "config_components.h"
23 
24 #include <math.h>
25 #include "libavutil/avassert.h"
26 #include "libavutil/avstring.h"
28 #include "libavutil/frame.h"
29 #include "libavutil/iamf.h"
30 #include "libavutil/mem.h"
31 #include "libavutil/opt.h"
32 #include "libavutil/pixfmt.h"
33 #include "libavutil/samplefmt.h"
34 #include "libavcodec/avcodec.h"
35 #include "libavcodec/codec.h"
36 #include "libavcodec/bsf.h"
37 #include "libavcodec/codec_desc.h"
38 #include "packet_internal.h"
39 #include "avformat.h"
40 #include "avformat_internal.h"
41 #include "avio.h"
42 #include "demux.h"
43 #include "mux.h"
44 #include "internal.h"
45 #include "url.h"
46 
48 {
49  AVStream *st = *pst;
50  FFStream *const sti = ffstream(st);
51 
52  if (!st)
53  return;
54 
55  if (st->attached_pic.data)
57 
58  av_parser_close(sti->parser);
60  av_bsf_free(&sti->bsfc);
61  av_freep(&sti->index_entries);
62  av_freep(&sti->probe_data.buf);
63 
65 
67 
68  if (sti->info) {
70  av_freep(&sti->info);
71  }
72 
73  av_dict_free(&st->metadata);
75  av_freep(&st->priv_data);
76 
77  av_freep(pst);
78 }
79 
81 {
82  AVStreamGroup *stg = *pstg;
83 
84  if (!stg)
85  return;
86 
87  av_freep(&stg->streams);
88  av_dict_free(&stg->metadata);
89  av_freep(&stg->priv_data);
90  switch (stg->type) {
93  break;
94  }
97  break;
98  }
104  av_freep(&stg->params.tile_grid);
105  break;
107  av_opt_free(stg->params.tref);
108  av_freep(&stg->params.tref);
109  break;
114  break;
115  default:
116  break;
117  }
118 
119  av_freep(pstg);
120 }
121 
123 {
124  av_assert0(s->nb_streams>0);
125  av_assert0(s->streams[ s->nb_streams - 1 ] == st);
126 
127  ff_free_stream(&s->streams[ --s->nb_streams ]);
128 }
129 
131 {
132  av_assert0(s->nb_stream_groups > 0);
133  av_assert0(s->stream_groups[ s->nb_stream_groups - 1 ] == stg);
134 
135  ff_free_stream_group(&s->stream_groups[ --s->nb_stream_groups ]);
136 }
137 
138 /* XXX: suppress the packet queue */
140 {
141  FormatContextInternal *const fci = ff_fc_internal(s);
142  FFFormatContext *const si = &fci->fc;
146 
147  fci->raw_packet_buffer_size = 0;
148 }
149 
151 {
153  FFFormatContext *si;
154 
155  if (!s)
156  return;
157  fci = ff_fc_internal(s);
158  si = &fci->fc;
159 
160  if (s->oformat && ffofmt(s->oformat)->deinit && fci->initialized)
161  ffofmt(s->oformat)->deinit(s);
162 
163  av_opt_free(s);
164  if (s->iformat && s->iformat->priv_class && s->priv_data)
165  av_opt_free(s->priv_data);
166  if (s->oformat && s->oformat->priv_class && s->priv_data)
167  av_opt_free(s->priv_data);
168 
169  for (unsigned i = 0; i < s->nb_streams; i++)
170  ff_free_stream(&s->streams[i]);
171  for (unsigned i = 0; i < s->nb_stream_groups; i++)
172  ff_free_stream_group(&s->stream_groups[i]);
173  s->nb_stream_groups = 0;
174  s->nb_streams = 0;
175 
176  for (unsigned i = 0; i < s->nb_programs; i++) {
177  av_dict_free(&s->programs[i]->metadata);
178  av_freep(&s->programs[i]->stream_index);
179  av_freep(&s->programs[i]);
180  }
181  s->nb_programs = 0;
182 
183  av_freep(&s->programs);
184  av_freep(&s->priv_data);
185  while (s->nb_chapters--) {
186  av_dict_free(&s->chapters[s->nb_chapters]->metadata);
187  av_freep(&s->chapters[s->nb_chapters]);
188  }
189  av_freep(&s->chapters);
190  av_dict_free(&s->metadata);
191  av_dict_free(&si->id3v2_meta);
192 #if CONFIG_LIBCURL_PROTOCOL
194 #endif
195  av_packet_free(&si->pkt);
198  av_freep(&s->streams);
199  av_freep(&s->stream_groups);
200  if (s->iformat)
202  av_freep(&s->url);
203  av_freep(&s->name);
204  av_free(s);
205 }
206 
207 /**
208  * Copy all stream parameters from source to destination stream, with the
209  * exception of the index field, which is usually set by avformat_new_stream().
210  *
211  * @param dst pointer to destination AVStream
212  * @param src pointer to source AVStream
213  * @return >=0 on success, AVERROR code on error
214  */
216 {
217  int ret;
218 
219  dst->id = src->id;
220  dst->time_base = src->time_base;
221  dst->start_time = src->start_time;
222  dst->duration = src->duration;
223  dst->nb_frames = src->nb_frames;
224  dst->disposition = src->disposition;
225  dst->discard = src->discard;
226  dst->sample_aspect_ratio = src->sample_aspect_ratio;
227  dst->avg_frame_rate = src->avg_frame_rate;
228  dst->event_flags = src->event_flags;
229  dst->r_frame_rate = src->r_frame_rate;
230  dst->pts_wrap_bits = src->pts_wrap_bits;
231 
232  av_dict_free(&dst->metadata);
233  ret = av_dict_copy(&dst->metadata, src->metadata, 0);
234  if (ret < 0)
235  return ret;
236 
237  ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
238  if (ret < 0)
239  return ret;
240 
241  av_packet_unref(&dst->attached_pic);
242  if (src->attached_pic.data) {
243  ret = av_packet_ref(&dst->attached_pic, &src->attached_pic);
244  if (ret < 0)
245  return ret;
246  }
247 
248  return 0;
249 }
250 
252 {
253  AVStream *st;
254  int ret;
255 
256  st = avformat_new_stream(dst_ctx, NULL);
257  if (!st)
258  return NULL;
259 
260  ret = stream_params_copy(st, src);
261  if (ret < 0) {
262  ff_remove_stream(dst_ctx, st);
263  return NULL;
264  }
265 
266  return st;
267 }
268 
270 {
271  switch(type) {
272  case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: return "IAMF Audio Element";
273  case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: return "IAMF Mix Presentation";
274  case AV_STREAM_GROUP_PARAMS_TILE_GRID: return "Tile Grid";
275  case AV_STREAM_GROUP_PARAMS_LCEVC: return "LCEVC (Split video and enhancement)";
276  case AV_STREAM_GROUP_PARAMS_TREF: return "Track Reference";
277  case AV_STREAM_GROUP_PARAMS_DOLBY_VISION: return "Dolby Vision (Split base and enhancement layer)";
278  }
279  return NULL;
280 }
281 
283 {
285  int ret;
286 
287  av_log(ac, AV_LOG_TRACE, "new_program: id=0x%04x\n", id);
288 
289  for (unsigned i = 0; i < ac->nb_programs; i++)
290  if (ac->programs[i]->id == id)
291  program = ac->programs[i];
292 
293  if (!program) {
294  program = av_mallocz(sizeof(*program));
295  if (!program)
296  return NULL;
298  if (ret < 0) {
299  av_free(program);
300  return NULL;
301  }
302  program->discard = AVDISCARD_NONE;
303  program->pmt_version = -1;
304  program->id = id;
305  program->pts_wrap_reference = AV_NOPTS_VALUE;
306  program->pts_wrap_behavior = AV_PTS_WRAP_IGNORE;
307  program->start_time =
308  program->end_time = AV_NOPTS_VALUE;
309  }
310  return program;
311 }
312 
313 int av_program_add_stream_index2(AVFormatContext *ac, int progid, unsigned idx)
314 {
316  void *tmp;
317 
318  if (idx >= ac->nb_streams) {
319  av_log(ac, AV_LOG_ERROR, "stream index %d is greater than stream count %d\n", idx, ac->nb_streams);
320  return AVERROR(EINVAL);
321  }
322 
323  for (unsigned i = 0; i < ac->nb_programs; i++) {
324  if (ac->programs[i]->id != progid)
325  continue;
326  program = ac->programs[i];
327  for (unsigned j = 0; j < program->nb_stream_indexes; j++)
328  if (program->stream_index[j] == idx)
329  return 0;
330 
331  tmp = av_realloc_array(program->stream_index, program->nb_stream_indexes+1, sizeof(unsigned int));
332  if (!tmp)
333  return AVERROR(ENOMEM);
334  program->stream_index = tmp;
335  program->stream_index[program->nb_stream_indexes++] = idx;
336  return 0;
337  }
338 
339  av_log(ac, AV_LOG_ERROR, "no program with id %d found\n", progid);
340  return AVERROR(EINVAL);
341 }
342 
343 void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
344 {
345  av_program_add_stream_index2(ac, progid, idx);
346  return;
347 }
348 
350 {
351  const AVProgram *src_prog = NULL;
352  AVProgram *dst_prog = NULL;
353  int ret, idx = -1, match = -1;
354  int overwrite = flags & AVFMT_PROGCOPY_OVERWRITE;
355 
357  return AVERROR(EINVAL);
359  match = 0;
361  match = 1;
362 
363  for (unsigned i = 0; i < src->nb_programs; i++) {
364  if (src->programs[i]->id == progid) {
365  if (src_prog) {
366  av_log(dst, AV_LOG_ERROR, "multiple programs found in source with same id 0x%04x. Not copying.\n", progid);
367  return AVERROR(EINVAL);
368  } else {
369  src_prog = src->programs[i];
370  }
371  }
372  }
373 
374  if (!src_prog) {
375  av_log(dst, AV_LOG_ERROR, "source program not found: id=0x%04x\n", progid);
376  return AVERROR(EINVAL);
377  }
378 
379  for (unsigned i = 0; i < dst->nb_programs; i++) {
380  if (dst->programs[i]->id == progid) {
381  if (idx > -1) {
382  av_log(dst, AV_LOG_ERROR, "multiple programs found in target with same id 0x%04x. Not copying.\n", progid);
383  return AVERROR(EINVAL);
384  } else {
385  idx = i;
386  }
387  }
388  }
389 
390  if (idx >= 0 && !overwrite)
391  return AVERROR(EEXIST);
392 
393  av_log(dst, AV_LOG_TRACE, "%s program: id=0x%04x\n", idx >= 0 ? "overwriting" : "copying", progid);
394 
395  if (idx >= 0) {
396  dst_prog = dst->programs[idx];
397  av_dict_free(&dst_prog->metadata);
398  av_freep(&dst_prog->stream_index);
399  dst_prog->nb_stream_indexes = 0;
400  } else {
401  dst_prog = av_new_program(dst, progid);
402  if (!dst_prog)
403  return AVERROR(ENOMEM);
404  }
405 
406  /* public fields */
407  dst_prog->id = src_prog->id;
408  dst_prog->flags = src_prog->flags;
409  dst_prog->discard = src_prog->discard;
410  dst_prog->program_num = src_prog->program_num;
411  dst_prog->pmt_pid = src_prog->pmt_pid;
412  dst_prog->pcr_pid = src_prog->pcr_pid;
413  dst_prog->pmt_version = src_prog->pmt_version;
414 
415  if (match == -1 && src->nb_streams) {
416  match = 0;
417  for (unsigned i = 0; i < src->nb_streams && !match; i++) {
418  int src_id = src->streams[i]->id;
419  if (!src_id) {
420  match = 1;
421  break;
422  }
423  for (unsigned j=i+1; j < src->nb_streams; j++) {
424  int sib_id = src->streams[j]->id;
425  if (src_id == sib_id) {
426  match = 1;
427  break;
428  }
429  }
430  }
431  }
432 
433  for (unsigned i = 0; i < dst->nb_streams; i++) {
434  int dst_val = match ? i : dst->streams[i]->id;
435 
436  for (unsigned j = 0; j < src_prog->nb_stream_indexes; j++) {
437  int src_val = match ? src_prog->stream_index[j] : src->streams[src_prog->stream_index[j]]->id;
438 
439  if (dst_val == src_val) {
440  ret = av_program_add_stream_index2(dst, dst_prog->id, i);
441  if (ret < 0)
442  return ret;
443  }
444  }
445  }
446 
447  ret = av_dict_copy(&dst_prog->metadata, src_prog->metadata, 0);
448  if (ret < 0)
449  return ret;
450 
451  return 0;
452 }
453 
455 {
456  for (unsigned i = 0; i < ic->nb_programs; i++) {
457  if (ic->programs[i] == last) {
458  last = NULL;
459  } else {
460  if (!last)
461  for (unsigned j = 0; j < ic->programs[i]->nb_stream_indexes; j++)
462  if (ic->programs[i]->stream_index[j] == s)
463  return ic->programs[i];
464  }
465  }
466  return NULL;
467 }
468 
470 {
471  int best_stream = 0;
472  int best_score = INT_MIN;
473 
474  if (s->nb_streams <= 0)
475  return -1;
476  for (unsigned i = 0; i < s->nb_streams; i++) {
477  const AVStream *const st = s->streams[i];
478  const FFStream *const sti = cffstream(st);
479  int score = 0;
480  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
482  score -= 400;
483  if (st->codecpar->width && st->codecpar->height)
484  score += 50;
485  score+= 25;
486  }
487  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
488  if (st->codecpar->sample_rate)
489  score += 50;
490  }
491  if (sti->codec_info_nb_frames)
492  score += 12;
493 
494  if (st->discard != AVDISCARD_ALL)
495  score += 200;
496 
497  if (score > best_score) {
498  best_score = score;
499  best_stream = i;
500  }
501  }
502  return best_stream;
503 }
504 
506  int wanted_stream_nb, int related_stream,
507  const AVCodec **decoder_ret, int flags)
508 {
509  int nb_streams = ic->nb_streams;
511  int best_count = -1, best_multiframe = -1, best_disposition = -1;
512  int count, multiframe, disposition;
513  int64_t best_bitrate = -1;
515  unsigned *program = NULL;
516  const AVCodec *decoder = NULL, *best_decoder = NULL;
517 
518  if (related_stream >= 0 && wanted_stream_nb < 0) {
519  AVProgram *p = av_find_program_from_stream(ic, NULL, related_stream);
520  if (p) {
521  program = p->stream_index;
522  nb_streams = p->nb_stream_indexes;
523  }
524  }
525  for (unsigned i = 0; i < nb_streams; i++) {
526  int real_stream_index = program ? program[i] : i;
527  AVStream *st = ic->streams[real_stream_index];
528  AVCodecParameters *par = st->codecpar;
529  if (par->codec_type != type)
530  continue;
531  if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
532  continue;
533  if (type == AVMEDIA_TYPE_AUDIO && !(par->ch_layout.nb_channels && par->sample_rate))
534  continue;
535  if (decoder_ret) {
536  decoder = ff_find_decoder(ic, st, par->codec_id);
537  if (!decoder) {
538  if (ret < 0)
540  continue;
541  }
542  }
544  + !! (st->disposition & AV_DISPOSITION_DEFAULT);
545  count = ffstream(st)->codec_info_nb_frames;
546  bitrate = par->bit_rate;
547  multiframe = FFMIN(5, count);
548  if ((best_disposition > disposition) ||
549  (best_disposition == disposition && best_multiframe > multiframe) ||
550  (best_disposition == disposition && best_multiframe == multiframe && best_bitrate > bitrate) ||
551  (best_disposition == disposition && best_multiframe == multiframe && best_bitrate == bitrate && best_count >= count))
552  continue;
553  best_disposition = disposition;
554  best_count = count;
555  best_bitrate = bitrate;
556  best_multiframe = multiframe;
557  ret = real_stream_index;
558  best_decoder = decoder;
559  if (program && i == nb_streams - 1 && ret < 0) {
560  program = NULL;
561  nb_streams = ic->nb_streams;
562  /* no related stream found, try again with everything */
563  i = 0;
564  }
565  }
566  if (decoder_ret)
567  *decoder_ret = best_decoder;
568  return ret;
569 }
570 
571 /**
572  * Matches a stream specifier (but ignores requested index).
573  *
574  * @param indexptr set to point to the requested stream index if there is one
575  *
576  * @return <0 on error
577  * 0 if st is NOT a matching stream
578  * >0 if st is a matching stream
579  */
580 static int match_stream_specifier(const AVFormatContext *s, const AVStream *st,
581  const char *spec, const char **indexptr,
582  const AVStreamGroup **g, const AVProgram **p)
583 {
584  int match = 1; /* Stores if the specifier matches so far. */
585  while (*spec) {
586  if (*spec <= '9' && *spec >= '0') { /* opt:index */
587  if (indexptr)
588  *indexptr = spec;
589  return match;
590  } else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||
591  *spec == 't' || *spec == 'V') { /* opt:[vasdtV] */
592  enum AVMediaType type;
593  int nopic = 0;
594 
595  switch (*spec++) {
596  case 'v': type = AVMEDIA_TYPE_VIDEO; break;
597  case 'a': type = AVMEDIA_TYPE_AUDIO; break;
598  case 's': type = AVMEDIA_TYPE_SUBTITLE; break;
599  case 'd': type = AVMEDIA_TYPE_DATA; break;
600  case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
601  case 'V': type = AVMEDIA_TYPE_VIDEO; nopic = 1; break;
602  default: av_assert0(0);
603  }
604  if (*spec && *spec++ != ':') /* If we are not at the end, then another specifier must follow. */
605  return AVERROR(EINVAL);
606 
607  if (type != st->codecpar->codec_type)
608  match = 0;
609  if (nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC))
610  match = 0;
611  } else if (*spec == 'g' && *(spec + 1) == ':') {
612  int64_t group_idx = -1, group_id = -1;
613  int found = 0;
614  char *endptr;
615  spec += 2;
616  if (*spec == '#' || (*spec == 'i' && *(spec + 1) == ':')) {
617  spec += 1 + (*spec == 'i');
618  group_id = strtol(spec, &endptr, 0);
619  if (spec == endptr || (*endptr && *endptr++ != ':'))
620  return AVERROR(EINVAL);
621  spec = endptr;
622  } else {
623  group_idx = strtol(spec, &endptr, 0);
624  /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
625  if (spec == endptr || (*endptr && *endptr++ != ':'))
626  return AVERROR(EINVAL);
627  spec = endptr;
628  }
629  if (match) {
630  if (group_id > 0) {
631  for (unsigned i = 0; i < s->nb_stream_groups; i++) {
632  if (group_id == s->stream_groups[i]->id) {
633  group_idx = i;
634  break;
635  }
636  }
637  }
638  if (group_idx < 0 || group_idx >= s->nb_stream_groups)
639  return AVERROR(EINVAL);
640  for (unsigned j = 0; j < s->stream_groups[group_idx]->nb_streams; j++) {
641  if (st->index == s->stream_groups[group_idx]->streams[j]->index) {
642  found = 1;
643  if (g)
644  *g = s->stream_groups[group_idx];
645  break;
646  }
647  }
648  }
649  if (!found)
650  match = 0;
651  } else if (*spec == 'p' && *(spec + 1) == ':') {
652  int prog_id;
653  int found = 0;
654  char *endptr;
655  spec += 2;
656  prog_id = strtol(spec, &endptr, 0);
657  /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
658  if (spec == endptr || (*endptr && *endptr++ != ':'))
659  return AVERROR(EINVAL);
660  spec = endptr;
661  if (match) {
662  for (unsigned i = 0; i < s->nb_programs; i++) {
663  if (s->programs[i]->id != prog_id)
664  continue;
665 
666  for (unsigned j = 0; j < s->programs[i]->nb_stream_indexes; j++) {
667  if (st->index == s->programs[i]->stream_index[j]) {
668  found = 1;
669  if (p)
670  *p = s->programs[i];
671  i = s->nb_programs;
672  break;
673  }
674  }
675  }
676  }
677  if (!found)
678  match = 0;
679  } else if (*spec == '#' ||
680  (*spec == 'i' && *(spec + 1) == ':')) {
681  int stream_id;
682  char *endptr;
683  spec += 1 + (*spec == 'i');
684  stream_id = strtol(spec, &endptr, 0);
685  if (spec == endptr || *endptr) /* Disallow empty id and make sure we are at the end. */
686  return AVERROR(EINVAL);
687  return match && (stream_id == st->id);
688  } else if (*spec == 'm' && *(spec + 1) == ':') {
689  const AVDictionaryEntry *tag;
690  int ret;
691 
692  if (match) {
693  spec += 2;
694  const char *val = strchr(spec, ':');
695 
696  char *key = val ? av_strndup(spec, val - spec) : av_strdup(spec);
697  if (!key)
698  return AVERROR(ENOMEM);
699 
700  tag = av_dict_get(st->metadata, key, NULL, 0);
701  if (tag) {
702  if (!val || !strcmp(tag->value, val + 1))
703  ret = 1;
704  else
705  ret = 0;
706  } else
707  ret = 0;
708 
709  av_freep(&key);
710  }
711  return match && ret;
712  } else if (*spec == 'u' && *(spec + 1) == '\0') {
713  const AVCodecParameters *par = st->codecpar;
714  int val;
715  switch (par->codec_type) {
716  case AVMEDIA_TYPE_AUDIO:
717  val = par->sample_rate && par->ch_layout.nb_channels;
718  if (par->format == AV_SAMPLE_FMT_NONE)
719  return 0;
720  break;
721  case AVMEDIA_TYPE_VIDEO:
722  val = par->width && par->height;
723  if (par->format == AV_PIX_FMT_NONE)
724  return 0;
725  break;
727  val = 0;
728  break;
729  default:
730  val = 1;
731  break;
732  }
733  return match && (par->codec_id != AV_CODEC_ID_NONE && val != 0);
734  } else {
735  return AVERROR(EINVAL);
736  }
737  }
738 
739  return match;
740 }
741 
743  const char *spec)
744 {
745  int ret, index;
746  char *endptr;
747  const char *indexptr = NULL;
748  const AVStreamGroup *g = NULL;
749  const AVProgram *p = NULL;
750  int nb_streams;
751 
752  ret = match_stream_specifier(s, st, spec, &indexptr, &g, &p);
753  if (ret < 0)
754  goto error;
755 
756  if (!indexptr)
757  return ret;
758 
759  index = strtol(indexptr, &endptr, 0);
760  if (*endptr) { /* We can't have anything after the requested index. */
761  ret = AVERROR(EINVAL);
762  goto error;
763  }
764 
765  /* This is not really needed but saves us a loop for simple stream index specifiers. */
766  if (spec == indexptr)
767  return (index == st->index);
768 
769  /* If we requested a matching stream index, we have to ensure st is that. */
770  nb_streams = g ? g->nb_streams : (p ? p->nb_stream_indexes : s->nb_streams);
771  for (int i = 0; i < nb_streams && index >= 0; i++) {
772  unsigned idx = g ? g->streams[i]->index : (p ? p->stream_index[i] : i);
773  const AVStream *candidate = s->streams[idx];
774  ret = match_stream_specifier(s, candidate, spec, NULL, NULL, NULL);
775  if (ret < 0)
776  goto error;
777  if (ret > 0 && index-- == 0 && st == candidate)
778  return 1;
779  }
780  return 0;
781 
782 error:
783  if (ret == AVERROR(EINVAL))
784  av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
785  return ret;
786 }
787 
789 {
790  AVRational undef = {0, 1};
791  AVRational stream_sample_aspect_ratio = stream ? stream->sample_aspect_ratio : undef;
792  AVRational codec_sample_aspect_ratio = stream && stream->codecpar ? stream->codecpar->sample_aspect_ratio : undef;
793  AVRational frame_sample_aspect_ratio = frame ? frame->sample_aspect_ratio : codec_sample_aspect_ratio;
794 
795  av_reduce(&stream_sample_aspect_ratio.num, &stream_sample_aspect_ratio.den,
796  stream_sample_aspect_ratio.num, stream_sample_aspect_ratio.den, INT_MAX);
797  if (stream_sample_aspect_ratio.num <= 0 || stream_sample_aspect_ratio.den <= 0)
798  stream_sample_aspect_ratio = undef;
799 
800  av_reduce(&frame_sample_aspect_ratio.num, &frame_sample_aspect_ratio.den,
801  frame_sample_aspect_ratio.num, frame_sample_aspect_ratio.den, INT_MAX);
802  if (frame_sample_aspect_ratio.num <= 0 || frame_sample_aspect_ratio.den <= 0)
803  frame_sample_aspect_ratio = undef;
804 
805  if (stream_sample_aspect_ratio.num)
806  return stream_sample_aspect_ratio;
807  else
808  return frame_sample_aspect_ratio;
809 }
810 
812 {
813  AVRational fr = st->r_frame_rate;
815  AVRational avg_fr = st->avg_frame_rate;
816 
817  if (avg_fr.num > 0 && avg_fr.den > 0 && fr.num > 0 && fr.den > 0 &&
818  av_q2d(avg_fr) < 70 && av_q2d(fr) > 210) {
819  fr = avg_fr;
820  }
821 
822  if (desc && (desc->props & AV_CODEC_PROP_FIELDS)) {
823  const AVCodecContext *const avctx = ffstream(st)->avctx;
824  AVRational codec_fr = avctx->framerate;
825 
826  if ( codec_fr.num > 0 && codec_fr.den > 0 &&
827  (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))
828  fr = codec_fr;
829  }
830 
831  return fr;
832 }
833 
834 void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits,
835  unsigned int pts_num, unsigned int pts_den)
836 {
837  FFStream *const sti = ffstream(st);
838  AVRational new_tb;
839  if (av_reduce(&new_tb.num, &new_tb.den, pts_num, pts_den, INT_MAX)) {
840  if (new_tb.num != pts_num)
842  "st:%d removing common factor %d from timebase\n",
843  st->index, pts_num / new_tb.num);
844  } else
846  "st:%d has too large timebase, reducing\n", st->index);
847 
848  if (new_tb.num <= 0 || new_tb.den <= 0) {
850  "Ignoring attempt to set invalid timebase %d/%d for st:%d\n",
851  new_tb.num, new_tb.den,
852  st->index);
853  return;
854  }
855  st->time_base = new_tb;
856  if (sti->avctx)
857  sti->avctx->pkt_timebase = new_tb;
858  st->pts_wrap_bits = pts_wrap_bits;
859 }
860 
862  enum AVCodecID codec_id)
863 {
864  switch (st->codecpar->codec_type) {
865  case AVMEDIA_TYPE_VIDEO:
866  if (s->video_codec) return s->video_codec;
867  break;
868  case AVMEDIA_TYPE_AUDIO:
869  if (s->audio_codec) return s->audio_codec;
870  break;
872  if (s->subtitle_codec) return s->subtitle_codec;
873  break;
874  }
875 
877 }
878 
880 {
881 #define OFF(field) offsetof(AVFormatContext, field)
882  static const unsigned offsets[] = {
883  OFF(codec_whitelist), OFF(format_whitelist),
884  OFF(protocol_whitelist), OFF(protocol_blacklist),
885  };
886 #undef OFF
887  av_assert0(!dst->codec_whitelist &&
888  !dst->format_whitelist &&
889  !dst->protocol_whitelist &&
890  !dst->protocol_blacklist);
891  for (unsigned i = 0; i < FF_ARRAY_ELEMS(offsets); i++) {
892  const char *src_str = *(char *const*)((const char*)src + offsets[i]);
893 
894  if (src_str) {
895  char *dst_str = av_strdup(src_str);
896  if (!dst_str) {
897  av_log(dst, AV_LOG_ERROR, "Failed to duplicate black/whitelist\n");
898  return AVERROR(ENOMEM);
899  }
900 
901  *(char **)((char*)dst + offsets[i]) = dst_str;
902  }
903  }
904  if (src->recursion_limit <= 0) {
905  av_log(dst, AV_LOG_ERROR, "Too deep recursion\n");
906  return AVERROR_INVALIDDATA;
907  }
908  dst->recursion_limit = src->recursion_limit - 1;
909  return 0;
910 }
911 
913 {
915  if (!d)
916  return 0;
917  if ((d->type == AVMEDIA_TYPE_VIDEO || d->type == AVMEDIA_TYPE_AUDIO) &&
919  return 0;
920  return 1;
921 }
922 
924 {
925  av_assert0(url);
926  av_freep(&s->url);
927  s->url = url;
928 }
929 
931 {
932  URLComponents uc;
933  av_assert0(url);
934  char proto[64];
935 
936  int ret = ff_url_decompose(&uc, url, NULL);
937  if (ret < 0)
938  return ret;
939  av_strlcpy(proto, uc.scheme, FFMIN(sizeof(proto), uc.url_component_end_scheme - uc.scheme));
940 
941  if (s->protocol_whitelist && av_match_list(proto, s->protocol_whitelist, ',') <= 0) {
942  av_log(s, AV_LOG_ERROR, "Protocol '%s' not on whitelist '%s'!\n", proto, s->protocol_whitelist);
943  return AVERROR(EINVAL);
944  }
945 
946  if (s->protocol_blacklist && av_match_list(proto, s->protocol_blacklist, ',') > 0) {
947  av_log(s, AV_LOG_ERROR, "Protocol '%s' on blacklist '%s'!\n", proto, s->protocol_blacklist);
948  return AVERROR(EINVAL);
949  }
950 
951  char *urldup = av_strdup(url);
952  if (!urldup)
953  return AVERROR(ENOMEM);
954 
955  av_freep(&s->url);
956  s->url = urldup;
957  return 0;
958 }
959 
960 
962 {
963  int ret = 0;
964  if (*pb)
965  ret = s->io_close2(s, *pb);
966  *pb = NULL;
967  return ret;
968 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
av_strdup
#define av_strdup(s)
Definition: ops_static.c:47
iamf.h
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:434
AVCodec
AVCodec.
Definition: codec.h:169
AVStreamGroupParamsType
AVStreamGroupParamsType
Definition: avformat.h:1146
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:203
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
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
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:53
AVStreamGroup::tile_grid
struct AVStreamGroupTileGrid * tile_grid
Definition: avformat.h:1194
AV_STREAM_GROUP_PARAMS_LCEVC
@ AV_STREAM_GROUP_PARAMS_LCEVC
Definition: avformat.h:1151
AVProgram::nb_stream_indexes
unsigned int nb_stream_indexes
Definition: avformat.h:1262
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:505
FFStream::bsfc
struct AVBSFContext * bsfc
bitstream filter to run on stream
Definition: internal.h:153
ff_find_decoder
const AVCodec * ff_find_decoder(AVFormatContext *s, const AVStream *st, enum AVCodecID codec_id)
Definition: avformat.c:861
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:49
FFStream::bsf
struct AVBSFContext * bsf
Definition: internal.h:173
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:791
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:692
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:837
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:454
ff_packet_list_free
void ff_packet_list_free(PacketList *list)
Wipe the list and unref all the packets in it.
Definition: packet_list.c:103
av_div_q
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition: rational.c:88
AVProgram::pmt_version
int pmt_version
Definition: avformat.h:1268
int64_t
long long int64_t
Definition: coverity.c:34
URLComponents
Definition: url.h:361
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:639
FormatContextInternal::raw_packet_buffer
PacketList raw_packet_buffer
Raw packets from the demuxer, prior to parsing and decoding.
Definition: avformat_internal.h:75
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:472
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1401
AVStreamGroup::params
union AVStreamGroup::@462 params
Group type-specific parameters.
AVPacket::data
uint8_t * data
Definition: packet.h:603
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:855
av_iamf_mix_presentation_free
void av_iamf_mix_presentation_free(AVIAMFMixPresentation **pmix_presentation)
Free an AVIAMFMixPresentation and all its contents.
Definition: iamf.c:536
nb_streams
static unsigned int nb_streams
Definition: ffprobe.c:352
AVFormatContext::programs
AVProgram ** programs
Definition: avformat.h:1531
AVStreamGroup::tref
struct AVStreamGroupTREF * tref
Definition: avformat.h:1203
AVProgram::flags
int flags
Definition: avformat.h:1259
cffstream
static const av_always_inline FFStream * cffstream(const AVStream *st)
Definition: internal.h:370
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:329
key
const char * key
Definition: ffmpeg_mux_init.c:2971
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:47
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: packet.c:74
FormatContextInternal
Definition: avformat_internal.h:33
AVProgram::pmt_pid
int pmt_pid
Definition: avformat.h:1266
FFStream::codec_desc
const struct AVCodecDescriptor * codec_desc
Definition: internal.h:362
OFF
#define OFF(field)
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:563
ff_remove_stream
void ff_remove_stream(AVFormatContext *s, AVStream *st)
Remove a stream from its AVFormatContext and free it.
Definition: avformat.c:122
ff_free_stream_group
void ff_free_stream_group(AVStreamGroup **pstg)
Frees a stream group without modifying the corresponding AVFormatContext.
Definition: avformat.c:80
AVFMT_PROGCOPY_OVERWRITE
#define AVFMT_PROGCOPY_OVERWRITE
overwrite pre-existing program having same ID
Definition: avformat.h:2157
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:834
bsf.h
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:365
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:215
avformat_stream_group_name
const char * avformat_stream_group_name(enum AVStreamGroupParamsType type)
Definition: avformat.c:269
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:338
AVProgram::discard
enum AVDiscard discard
selects which program to discard and which to feed to the caller
Definition: avformat.h:1260
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1942
FFStream::avctx
struct AVCodecContext * avctx
The codec context used by avformat_find_stream_info, the parser, etc.
Definition: internal.h:163
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: defs.h:226
val
static double val(void *priv, double ch)
Definition: aeval.c:77
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:282
AV_PTS_WRAP_IGNORE
#define AV_PTS_WRAP_IGNORE
Options for behavior on timestamp wrap detection.
Definition: avformat.h:755
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
AV_STREAM_GROUP_PARAMS_DOLBY_VISION
@ AV_STREAM_GROUP_PARAMS_DOLBY_VISION
Definition: avformat.h:1153
AVFMT_PROGCOPY_MATCH_BY_INDEX
#define AVFMT_PROGCOPY_MATCH_BY_INDEX
match streams using stream index
Definition: avformat.h:2156
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:864
avassert.h
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:236
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVProgram::id
int id
Definition: avformat.h:1258
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:60
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:504
AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION
@ AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION
Definition: avformat.h:1149
AVCodecDescriptor
This struct describes the properties of a single codec described by an AVCodecID.
Definition: codec_desc.h:38
ff_format_check_set_url
int ff_format_check_set_url(AVFormatContext *s, const char *url)
Set AVFormatContext url field to a av_strdup of the provided pointer.
Definition: avformat.c:930
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
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:217
AVCodecParameters::sample_aspect_ratio
AVRational sample_aspect_ratio
The aspect ratio (width/height) which a single pixel should have when displayed.
Definition: codec_par.h:161
AVFormatContext::nb_programs
unsigned int nb_programs
Definition: avformat.h:1530
bitrate
int64_t bitrate
Definition: av1_levels.c:47
g
const char * g
Definition: vf_curves.c:128
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:473
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:201
AVCodecParameters::width
int width
The width of the video frame in pixels.
Definition: codec_par.h:143
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:42
AVCodecDescriptor::type
enum AVMediaType type
Definition: codec_desc.h:40
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
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:788
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:342
ffofmt
static const FFOutputFormat * ffofmt(const AVOutputFormat *fmt)
Definition: mux.h:167
av_program_copy
int av_program_copy(AVFormatContext *dst, const AVFormatContext *src, int progid, int flags)
Copy an AVProgram from one AVFormatContext to another.
Definition: avformat.c:349
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
av_program_add_stream_index2
int av_program_add_stream_index2(AVFormatContext *ac, int progid, unsigned idx)
Definition: avformat.c:313
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_packet_side_data_free
void av_packet_side_data_free(AVPacketSideData **psd, int *pnb_sd)
Convenience function to free all the side data stored in an array, and the array itself.
Definition: packet.c:658
AVStreamGroup::layered_video
struct AVStreamGroupLayeredVideo * layered_video
Definition: avformat.h:1195
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
AVCodecDescriptor::props
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: codec_desc.h:54
FFFormatContext
Definition: internal.h:64
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:232
AVFormatContext
Format I/O context.
Definition: avformat.h:1333
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:789
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:805
NULL
#define NULL
Definition: coverity.c:32
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:440
av_program_add_stream_index
void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
Definition: avformat.c:343
format
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image format
Definition: swscale-v2.txt:14
AVStreamGroupTileGrid::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the grid.
Definition: avformat.h:1076
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
ff_copy_whiteblacklists
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
Copies the whilelists from one context to the other.
Definition: avformat.c:879
FFOutputFormat::deinit
void(* deinit)(AVFormatContext *)
Deinitialize format.
Definition: mux.h:154
AVProgram::stream_index
unsigned int * stream_index
Definition: avformat.h:1261
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:846
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:442
FormatContextInternal::fc
FFFormatContext fc
Definition: avformat_internal.h:34
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition: codec_par.h:207
AVFMT_PROGCOPY_MATCH_BY_ID
#define AVFMT_PROGCOPY_MATCH_BY_ID
match streams using stream id
Definition: avformat.h:2155
index
int index
Definition: gxfenc.c:90
AVCodecParameters::sample_rate
int sample_rate
The number of audio samples per second.
Definition: codec_par.h:213
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:47
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:990
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1389
FFFormatContext::id3v2_meta
AVDictionary * id3v2_meta
ID3v2 tag useful for MP3 demuxing.
Definition: internal.h:118
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_STREAM_GROUP_PARAMS_TILE_GRID
@ AV_STREAM_GROUP_PARAMS_TILE_GRID
Definition: avformat.h:1150
ff_curl_loop_free
void ff_curl_loop_free(struct CurlLoop **loop)
Release a libcurl event loop and set *loop to NULL.
Definition: libcurl.c:759
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
AVMediaType
AVMediaType
Definition: avutil.h:198
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:742
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
AV_STREAM_GROUP_PARAMS_TREF
@ AV_STREAM_GROUP_PARAMS_TREF
Definition: avformat.h:1152
FFStream
Definition: internal.h:135
ff_free_stream
void ff_free_stream(AVStream **pst)
Frees a stream without modifying the corresponding AVFormatContext.
Definition: avformat.c:47
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition: avcodec.h:554
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
avio.h
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
AVStreamGroup::iamf_audio_element
struct AVIAMFAudioElement * iamf_audio_element
Definition: avformat.h:1192
ff_format_io_close
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: avformat.c:961
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:199
AVProgram::program_num
int program_num
Definition: avformat.h:1265
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:844
frame.h
AV_DISPOSITION_HEARING_IMPAIRED
#define AV_DISPOSITION_HEARING_IMPAIRED
The stream is intended for hearing impaired audiences.
Definition: avformat.h:676
packet_internal.h
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
AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT
@ AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT
Definition: avformat.h:1148
AVStreamGroup::streams
AVStream ** streams
A list of streams in the group.
Definition: avformat.h:1234
AVStreamGroup::iamf_mix_presentation
struct AVIAMFMixPresentation * iamf_mix_presentation
Definition: avformat.h:1193
avformat_internal.h
FFStream::probe_data
AVProbeData probe_data
Definition: internal.h:305
FFStreamInfo::duration_error
double(* duration_error)[2][MAX_STD_TIMEBASES]
Definition: demux.h:197
AVStreamGroupTileGrid::nb_coded_side_data
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition: avformat.h:1081
ff_is_intra_only
int ff_is_intra_only(enum AVCodecID id)
Definition: avformat.c:912
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:48
AVCodecParameters::height
int height
The height of the video frame in pixels.
Definition: codec_par.h:150
AVProgram::metadata
AVDictionary * metadata
Definition: avformat.h:1263
s
uint8_t s
Definition: llvidencdsp.c:39
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:204
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
url.h
av_find_default_stream_index
int av_find_default_stream_index(AVFormatContext *s)
Definition: avformat.c:469
AVStreamGroupTileGrid::offsets
struct AVStreamGroupTileGrid::@461 * offsets
An nb_tiles sized array of offsets in pixels from the topleft edge of the canvas, indicating where ea...
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1257
demux.h
avcodec.h
AVCodecParameters::avcodec_parameters_copy
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: codec_par.c:107
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:835
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:580
AV_DISPOSITION_VISUAL_IMPAIRED
#define AV_DISPOSITION_VISUAL_IMPAIRED
The stream is intended for visually impaired audiences.
Definition: avformat.h:680
tag
uint32_t tag
Definition: movenc.c:2073
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:778
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:766
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:811
pixfmt.h
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
AVStreamGroup::metadata
AVDictionary * metadata
Metadata that applies to the whole group.
Definition: avformat.h:1214
avformat.h
FFFormatContext::curl_loop
struct CurlLoop * curl_loop
Shared libcurl event loop, created on demand on the first use.
Definition: internal.h:127
id
enum AVCodecID id
Definition: dts2pts.c:607
AVCodecParameters::avcodec_parameters_free
void avcodec_parameters_free(AVCodecParameters **par)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
Definition: codec_par.c:67
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
URLComponents::scheme
const char * scheme
possibly including lavf-specific options
Definition: url.h:363
AVStreamGroup
Definition: avformat.h:1159
AVCodecContext
main external API structure.
Definition: avcodec.h:443
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:772
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:139
ff_remove_stream_group
void ff_remove_stream_group(AVFormatContext *s, AVStreamGroup *stg)
Remove a stream group from its AVFormatContext and free it.
Definition: avformat.c:130
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: avformat.c:150
ff_fc_internal
static av_always_inline FormatContextInternal * ff_fc_internal(AVFormatContext *s)
Definition: avformat_internal.h:100
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:900
FFStream::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:337
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:189
FFStream::index_entries
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: internal.h:191
AVERROR_DECODER_NOT_FOUND
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
Definition: error.h:54
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
mem.h
AVStreamGroup::type
enum AVStreamGroupParamsType type
Group type.
Definition: avformat.h:1186
FFFormatContext::pkt
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
Definition: internal.h:111
AVCodecParameters::format
int format
Definition: codec_par.h:94
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:90
FFStream::extract_extradata
struct FFStream::@492 extract_extradata
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:57
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:251
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
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
av_strlcpy
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:85
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:99
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
FFStream::parser
struct AVCodecParserContext * parser
Definition: internal.h:322
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3891
avstring.h
av_strndup
char * av_strndup(const char *s, size_t len)
Duplicate a substring of a string.
Definition: mem.c:284
AVStream::pts_wrap_bits
int pts_wrap_bits
Number of bits in timestamps.
Definition: avformat.h:909
codec_desc.h
AVStreamGroup::priv_data
void * priv_data
Definition: avformat.h:1165
ff_url_decompose
int ff_url_decompose(URLComponents *uc, const char *url, const char *end)
Parse an URL to find the components.
Definition: url.c:91
AVProgram::pcr_pid
int pcr_pid
Definition: avformat.h:1267
ff_format_set_url
void ff_format_set_url(AVFormatContext *s, char *url)
Set AVFormatContext url field to the provided pointer.
Definition: avformat.c:923
src
#define src
Definition: vp8dsp.c:248
FormatContextInternal::parse_queue
PacketList parse_queue
Packets split by the parser get queued here.
Definition: avformat_internal.h:85
FormatContextInternal::initialized
int initialized
Whether or not avformat_init_output has already been called.
Definition: avformat_internal.h:42
av_parser_close
void av_parser_close(AVCodecParserContext *s)
Definition: parser.c:203
mux.h