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/mem.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/pixfmt.h"
31 #include "libavutil/samplefmt.h"
32 #include "libavcodec/avcodec.h"
33 #include "libavcodec/codec.h"
34 #include "libavcodec/bsf.h"
35 #include "libavcodec/codec_desc.h"
36 #include "packet_internal.h"
37 #include "avformat.h"
38 #include "avformat_internal.h"
39 #include "avio.h"
40 #include "demux.h"
41 #include "mux.h"
42 #include "internal.h"
43 #include "url.h"
44 
46 {
47  AVStream *st = *pst;
48  FFStream *const sti = ffstream(st);
49 
50  if (!st)
51  return;
52 
53  if (st->attached_pic.data)
55 
56  av_parser_close(sti->parser);
58  av_bsf_free(&sti->bsfc);
59  av_freep(&sti->index_entries);
60  av_freep(&sti->probe_data.buf);
61 
63 
65 
66  if (sti->info) {
68  av_freep(&sti->info);
69  }
70 
71  av_dict_free(&st->metadata);
73  av_freep(&st->priv_data);
74 
75  av_freep(pst);
76 }
77 
79 {
80  AVStreamGroup *stg = *pstg;
81 
82  if (!stg)
83  return;
84 
85  av_freep(&stg->streams);
86  av_dict_free(&stg->metadata);
87  av_freep(&stg->priv_data);
88  switch (stg->type) {
91  break;
92  }
95  break;
96  }
102  av_freep(&stg->params.tile_grid);
103  break;
105  av_opt_free(stg->params.tref);
106  av_freep(&stg->params.tref);
107  break;
112  break;
113  default:
114  break;
115  }
116 
117  av_freep(pstg);
118 }
119 
121 {
122  av_assert0(s->nb_streams>0);
123  av_assert0(s->streams[ s->nb_streams - 1 ] == st);
124 
125  ff_free_stream(&s->streams[ --s->nb_streams ]);
126 }
127 
129 {
130  av_assert0(s->nb_stream_groups > 0);
131  av_assert0(s->stream_groups[ s->nb_stream_groups - 1 ] == stg);
132 
133  ff_free_stream_group(&s->stream_groups[ --s->nb_stream_groups ]);
134 }
135 
136 /* XXX: suppress the packet queue */
138 {
139  FormatContextInternal *const fci = ff_fc_internal(s);
140  FFFormatContext *const si = &fci->fc;
144 
145  fci->raw_packet_buffer_size = 0;
146 }
147 
149 {
151  FFFormatContext *si;
152 
153  if (!s)
154  return;
155  fci = ff_fc_internal(s);
156  si = &fci->fc;
157 
158  if (s->oformat && ffofmt(s->oformat)->deinit && fci->initialized)
159  ffofmt(s->oformat)->deinit(s);
160 
161  av_opt_free(s);
162  if (s->iformat && s->iformat->priv_class && s->priv_data)
163  av_opt_free(s->priv_data);
164  if (s->oformat && s->oformat->priv_class && s->priv_data)
165  av_opt_free(s->priv_data);
166 
167  for (unsigned i = 0; i < s->nb_streams; i++)
168  ff_free_stream(&s->streams[i]);
169  for (unsigned i = 0; i < s->nb_stream_groups; i++)
170  ff_free_stream_group(&s->stream_groups[i]);
171  s->nb_stream_groups = 0;
172  s->nb_streams = 0;
173 
174  for (unsigned i = 0; i < s->nb_programs; i++) {
175  av_dict_free(&s->programs[i]->metadata);
176  av_freep(&s->programs[i]->stream_index);
177  av_freep(&s->programs[i]);
178  }
179  s->nb_programs = 0;
180 
181  av_freep(&s->programs);
182  av_freep(&s->priv_data);
183  while (s->nb_chapters--) {
184  av_dict_free(&s->chapters[s->nb_chapters]->metadata);
185  av_freep(&s->chapters[s->nb_chapters]);
186  }
187  av_freep(&s->chapters);
188  av_dict_free(&s->metadata);
189  av_dict_free(&si->id3v2_meta);
190  av_packet_free(&si->pkt);
193  av_freep(&s->streams);
194  av_freep(&s->stream_groups);
195  if (s->iformat)
197  av_freep(&s->url);
198  av_freep(&s->name);
199  av_free(s);
200 }
201 
202 /**
203  * Copy all stream parameters from source to destination stream, with the
204  * exception of the index field, which is usually set by avformat_new_stream().
205  *
206  * @param dst pointer to destination AVStream
207  * @param src pointer to source AVStream
208  * @return >=0 on success, AVERROR code on error
209  */
211 {
212  int ret;
213 
214  dst->id = src->id;
215  dst->time_base = src->time_base;
216  dst->start_time = src->start_time;
217  dst->duration = src->duration;
218  dst->nb_frames = src->nb_frames;
219  dst->disposition = src->disposition;
220  dst->discard = src->discard;
221  dst->sample_aspect_ratio = src->sample_aspect_ratio;
222  dst->avg_frame_rate = src->avg_frame_rate;
223  dst->event_flags = src->event_flags;
224  dst->r_frame_rate = src->r_frame_rate;
225  dst->pts_wrap_bits = src->pts_wrap_bits;
226 
227  av_dict_free(&dst->metadata);
228  ret = av_dict_copy(&dst->metadata, src->metadata, 0);
229  if (ret < 0)
230  return ret;
231 
232  ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
233  if (ret < 0)
234  return ret;
235 
236  av_packet_unref(&dst->attached_pic);
237  if (src->attached_pic.data) {
238  ret = av_packet_ref(&dst->attached_pic, &src->attached_pic);
239  if (ret < 0)
240  return ret;
241  }
242 
243  return 0;
244 }
245 
247 {
248  AVStream *st;
249  int ret;
250 
251  st = avformat_new_stream(dst_ctx, NULL);
252  if (!st)
253  return NULL;
254 
255  ret = stream_params_copy(st, src);
256  if (ret < 0) {
257  ff_remove_stream(dst_ctx, st);
258  return NULL;
259  }
260 
261  return st;
262 }
263 
265 {
266  switch(type) {
267  case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: return "IAMF Audio Element";
268  case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: return "IAMF Mix Presentation";
269  case AV_STREAM_GROUP_PARAMS_TILE_GRID: return "Tile Grid";
270  case AV_STREAM_GROUP_PARAMS_LCEVC: return "LCEVC (Split video and enhancement)";
271  case AV_STREAM_GROUP_PARAMS_TREF: return "Track Reference";
272  case AV_STREAM_GROUP_PARAMS_DOLBY_VISION: return "Dolby Vision (Split base and enhancement layer)";
273  }
274  return NULL;
275 }
276 
278 {
280  int ret;
281 
282  av_log(ac, AV_LOG_TRACE, "new_program: id=0x%04x\n", id);
283 
284  for (unsigned i = 0; i < ac->nb_programs; i++)
285  if (ac->programs[i]->id == id)
286  program = ac->programs[i];
287 
288  if (!program) {
289  program = av_mallocz(sizeof(*program));
290  if (!program)
291  return NULL;
293  if (ret < 0) {
294  av_free(program);
295  return NULL;
296  }
297  program->discard = AVDISCARD_NONE;
298  program->pmt_version = -1;
299  program->id = id;
300  program->pts_wrap_reference = AV_NOPTS_VALUE;
301  program->pts_wrap_behavior = AV_PTS_WRAP_IGNORE;
302  program->start_time =
303  program->end_time = AV_NOPTS_VALUE;
304  }
305  return program;
306 }
307 
308 int av_program_add_stream_index2(AVFormatContext *ac, int progid, unsigned idx)
309 {
311  void *tmp;
312 
313  if (idx >= ac->nb_streams) {
314  av_log(ac, AV_LOG_ERROR, "stream index %d is greater than stream count %d\n", idx, ac->nb_streams);
315  return AVERROR(EINVAL);
316  }
317 
318  for (unsigned i = 0; i < ac->nb_programs; i++) {
319  if (ac->programs[i]->id != progid)
320  continue;
321  program = ac->programs[i];
322  for (unsigned j = 0; j < program->nb_stream_indexes; j++)
323  if (program->stream_index[j] == idx)
324  return 0;
325 
326  tmp = av_realloc_array(program->stream_index, program->nb_stream_indexes+1, sizeof(unsigned int));
327  if (!tmp)
328  return AVERROR(ENOMEM);
329  program->stream_index = tmp;
330  program->stream_index[program->nb_stream_indexes++] = idx;
331  return 0;
332  }
333 
334  av_log(ac, AV_LOG_ERROR, "no program with id %d found\n", progid);
335  return AVERROR(EINVAL);
336 }
337 
338 void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
339 {
340  av_program_add_stream_index2(ac, progid, idx);
341  return;
342 }
343 
345 {
346  const AVProgram *src_prog = NULL;
347  AVProgram *dst_prog = NULL;
348  int ret, idx = -1, match = -1;
349  int overwrite = flags & AVFMT_PROGCOPY_OVERWRITE;
350 
352  return AVERROR(EINVAL);
354  match = 0;
356  match = 1;
357 
358  for (unsigned i = 0; i < src->nb_programs; i++) {
359  if (src->programs[i]->id == progid) {
360  if (src_prog) {
361  av_log(dst, AV_LOG_ERROR, "multiple programs found in source with same id 0x%04x. Not copying.\n", progid);
362  return AVERROR(EINVAL);
363  } else {
364  src_prog = src->programs[i];
365  }
366  }
367  }
368 
369  if (!src_prog) {
370  av_log(dst, AV_LOG_ERROR, "source program not found: id=0x%04x\n", progid);
371  return AVERROR(EINVAL);
372  }
373 
374  for (unsigned i = 0; i < dst->nb_programs; i++) {
375  if (dst->programs[i]->id == progid) {
376  if (idx > -1) {
377  av_log(dst, AV_LOG_ERROR, "multiple programs found in target with same id 0x%04x. Not copying.\n", progid);
378  return AVERROR(EINVAL);
379  } else {
380  idx = i;
381  }
382  }
383  }
384 
385  if (idx >= 0 && !overwrite)
386  return AVERROR(EEXIST);
387 
388  av_log(dst, AV_LOG_TRACE, "%s program: id=0x%04x\n", idx >= 0 ? "overwriting" : "copying", progid);
389 
390  if (idx >= 0) {
391  dst_prog = dst->programs[idx];
392  av_dict_free(&dst_prog->metadata);
393  av_freep(&dst_prog->stream_index);
394  dst_prog->nb_stream_indexes = 0;
395  } else {
396  dst_prog = av_new_program(dst, progid);
397  if (!dst_prog)
398  return AVERROR(ENOMEM);
399  }
400 
401  /* public fields */
402  dst_prog->id = src_prog->id;
403  dst_prog->flags = src_prog->flags;
404  dst_prog->discard = src_prog->discard;
405  dst_prog->program_num = src_prog->program_num;
406  dst_prog->pmt_pid = src_prog->pmt_pid;
407  dst_prog->pcr_pid = src_prog->pcr_pid;
408  dst_prog->pmt_version = src_prog->pmt_version;
409 
410  if (match == -1 && src->nb_streams) {
411  match = 0;
412  for (unsigned i = 0; i < src->nb_streams && !match; i++) {
413  int src_id = src->streams[i]->id;
414  if (!src_id) {
415  match = 1;
416  break;
417  }
418  for (unsigned j=i+1; j < src->nb_streams; j++) {
419  int sib_id = src->streams[j]->id;
420  if (src_id == sib_id) {
421  match = 1;
422  break;
423  }
424  }
425  }
426  }
427 
428  for (unsigned i = 0; i < dst->nb_streams; i++) {
429  int dst_val = match ? i : dst->streams[i]->id;
430 
431  for (unsigned j = 0; j < src_prog->nb_stream_indexes; j++) {
432  int src_val = match ? src_prog->stream_index[j] : src->streams[src_prog->stream_index[j]]->id;
433 
434  if (dst_val == src_val) {
435  ret = av_program_add_stream_index2(dst, dst_prog->id, i);
436  if (ret < 0)
437  return ret;
438  }
439  }
440  }
441 
442  ret = av_dict_copy(&dst_prog->metadata, src_prog->metadata, 0);
443  if (ret < 0)
444  return ret;
445 
446  return 0;
447 }
448 
450 {
451  for (unsigned i = 0; i < ic->nb_programs; i++) {
452  if (ic->programs[i] == last) {
453  last = NULL;
454  } else {
455  if (!last)
456  for (unsigned j = 0; j < ic->programs[i]->nb_stream_indexes; j++)
457  if (ic->programs[i]->stream_index[j] == s)
458  return ic->programs[i];
459  }
460  }
461  return NULL;
462 }
463 
465 {
466  int best_stream = 0;
467  int best_score = INT_MIN;
468 
469  if (s->nb_streams <= 0)
470  return -1;
471  for (unsigned i = 0; i < s->nb_streams; i++) {
472  const AVStream *const st = s->streams[i];
473  const FFStream *const sti = cffstream(st);
474  int score = 0;
475  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
477  score -= 400;
478  if (st->codecpar->width && st->codecpar->height)
479  score += 50;
480  score+= 25;
481  }
482  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
483  if (st->codecpar->sample_rate)
484  score += 50;
485  }
486  if (sti->codec_info_nb_frames)
487  score += 12;
488 
489  if (st->discard != AVDISCARD_ALL)
490  score += 200;
491 
492  if (score > best_score) {
493  best_score = score;
494  best_stream = i;
495  }
496  }
497  return best_stream;
498 }
499 
501  int wanted_stream_nb, int related_stream,
502  const AVCodec **decoder_ret, int flags)
503 {
504  int nb_streams = ic->nb_streams;
506  int best_count = -1, best_multiframe = -1, best_disposition = -1;
507  int count, multiframe, disposition;
508  int64_t best_bitrate = -1;
510  unsigned *program = NULL;
511  const AVCodec *decoder = NULL, *best_decoder = NULL;
512 
513  if (related_stream >= 0 && wanted_stream_nb < 0) {
514  AVProgram *p = av_find_program_from_stream(ic, NULL, related_stream);
515  if (p) {
516  program = p->stream_index;
517  nb_streams = p->nb_stream_indexes;
518  }
519  }
520  for (unsigned i = 0; i < nb_streams; i++) {
521  int real_stream_index = program ? program[i] : i;
522  AVStream *st = ic->streams[real_stream_index];
523  AVCodecParameters *par = st->codecpar;
524  if (par->codec_type != type)
525  continue;
526  if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
527  continue;
528  if (type == AVMEDIA_TYPE_AUDIO && !(par->ch_layout.nb_channels && par->sample_rate))
529  continue;
530  if (decoder_ret) {
531  decoder = ff_find_decoder(ic, st, par->codec_id);
532  if (!decoder) {
533  if (ret < 0)
535  continue;
536  }
537  }
539  + !! (st->disposition & AV_DISPOSITION_DEFAULT);
540  count = ffstream(st)->codec_info_nb_frames;
541  bitrate = par->bit_rate;
542  multiframe = FFMIN(5, count);
543  if ((best_disposition > disposition) ||
544  (best_disposition == disposition && best_multiframe > multiframe) ||
545  (best_disposition == disposition && best_multiframe == multiframe && best_bitrate > bitrate) ||
546  (best_disposition == disposition && best_multiframe == multiframe && best_bitrate == bitrate && best_count >= count))
547  continue;
548  best_disposition = disposition;
549  best_count = count;
550  best_bitrate = bitrate;
551  best_multiframe = multiframe;
552  ret = real_stream_index;
553  best_decoder = decoder;
554  if (program && i == nb_streams - 1 && ret < 0) {
555  program = NULL;
556  nb_streams = ic->nb_streams;
557  /* no related stream found, try again with everything */
558  i = 0;
559  }
560  }
561  if (decoder_ret)
562  *decoder_ret = best_decoder;
563  return ret;
564 }
565 
566 /**
567  * Matches a stream specifier (but ignores requested index).
568  *
569  * @param indexptr set to point to the requested stream index if there is one
570  *
571  * @return <0 on error
572  * 0 if st is NOT a matching stream
573  * >0 if st is a matching stream
574  */
575 static int match_stream_specifier(const AVFormatContext *s, const AVStream *st,
576  const char *spec, const char **indexptr,
577  const AVStreamGroup **g, const AVProgram **p)
578 {
579  int match = 1; /* Stores if the specifier matches so far. */
580  while (*spec) {
581  if (*spec <= '9' && *spec >= '0') { /* opt:index */
582  if (indexptr)
583  *indexptr = spec;
584  return match;
585  } else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||
586  *spec == 't' || *spec == 'V') { /* opt:[vasdtV] */
587  enum AVMediaType type;
588  int nopic = 0;
589 
590  switch (*spec++) {
591  case 'v': type = AVMEDIA_TYPE_VIDEO; break;
592  case 'a': type = AVMEDIA_TYPE_AUDIO; break;
593  case 's': type = AVMEDIA_TYPE_SUBTITLE; break;
594  case 'd': type = AVMEDIA_TYPE_DATA; break;
595  case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
596  case 'V': type = AVMEDIA_TYPE_VIDEO; nopic = 1; break;
597  default: av_assert0(0);
598  }
599  if (*spec && *spec++ != ':') /* If we are not at the end, then another specifier must follow. */
600  return AVERROR(EINVAL);
601 
602  if (type != st->codecpar->codec_type)
603  match = 0;
604  if (nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC))
605  match = 0;
606  } else if (*spec == 'g' && *(spec + 1) == ':') {
607  int64_t group_idx = -1, group_id = -1;
608  int found = 0;
609  char *endptr;
610  spec += 2;
611  if (*spec == '#' || (*spec == 'i' && *(spec + 1) == ':')) {
612  spec += 1 + (*spec == 'i');
613  group_id = strtol(spec, &endptr, 0);
614  if (spec == endptr || (*endptr && *endptr++ != ':'))
615  return AVERROR(EINVAL);
616  spec = endptr;
617  } else {
618  group_idx = strtol(spec, &endptr, 0);
619  /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
620  if (spec == endptr || (*endptr && *endptr++ != ':'))
621  return AVERROR(EINVAL);
622  spec = endptr;
623  }
624  if (match) {
625  if (group_id > 0) {
626  for (unsigned i = 0; i < s->nb_stream_groups; i++) {
627  if (group_id == s->stream_groups[i]->id) {
628  group_idx = i;
629  break;
630  }
631  }
632  }
633  if (group_idx < 0 || group_idx >= s->nb_stream_groups)
634  return AVERROR(EINVAL);
635  for (unsigned j = 0; j < s->stream_groups[group_idx]->nb_streams; j++) {
636  if (st->index == s->stream_groups[group_idx]->streams[j]->index) {
637  found = 1;
638  if (g)
639  *g = s->stream_groups[group_idx];
640  break;
641  }
642  }
643  }
644  if (!found)
645  match = 0;
646  } else if (*spec == 'p' && *(spec + 1) == ':') {
647  int prog_id;
648  int found = 0;
649  char *endptr;
650  spec += 2;
651  prog_id = strtol(spec, &endptr, 0);
652  /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
653  if (spec == endptr || (*endptr && *endptr++ != ':'))
654  return AVERROR(EINVAL);
655  spec = endptr;
656  if (match) {
657  for (unsigned i = 0; i < s->nb_programs; i++) {
658  if (s->programs[i]->id != prog_id)
659  continue;
660 
661  for (unsigned j = 0; j < s->programs[i]->nb_stream_indexes; j++) {
662  if (st->index == s->programs[i]->stream_index[j]) {
663  found = 1;
664  if (p)
665  *p = s->programs[i];
666  i = s->nb_programs;
667  break;
668  }
669  }
670  }
671  }
672  if (!found)
673  match = 0;
674  } else if (*spec == '#' ||
675  (*spec == 'i' && *(spec + 1) == ':')) {
676  int stream_id;
677  char *endptr;
678  spec += 1 + (*spec == 'i');
679  stream_id = strtol(spec, &endptr, 0);
680  if (spec == endptr || *endptr) /* Disallow empty id and make sure we are at the end. */
681  return AVERROR(EINVAL);
682  return match && (stream_id == st->id);
683  } else if (*spec == 'm' && *(spec + 1) == ':') {
684  const AVDictionaryEntry *tag;
685  char *key, *val;
686  int ret;
687 
688  if (match) {
689  spec += 2;
690  val = strchr(spec, ':');
691 
692  key = val ? av_strndup(spec, val - spec) : av_strdup(spec);
693  if (!key)
694  return AVERROR(ENOMEM);
695 
696  tag = av_dict_get(st->metadata, key, NULL, 0);
697  if (tag) {
698  if (!val || !strcmp(tag->value, val + 1))
699  ret = 1;
700  else
701  ret = 0;
702  } else
703  ret = 0;
704 
705  av_freep(&key);
706  }
707  return match && ret;
708  } else if (*spec == 'u' && *(spec + 1) == '\0') {
709  const AVCodecParameters *par = st->codecpar;
710  int val;
711  switch (par->codec_type) {
712  case AVMEDIA_TYPE_AUDIO:
713  val = par->sample_rate && par->ch_layout.nb_channels;
714  if (par->format == AV_SAMPLE_FMT_NONE)
715  return 0;
716  break;
717  case AVMEDIA_TYPE_VIDEO:
718  val = par->width && par->height;
719  if (par->format == AV_PIX_FMT_NONE)
720  return 0;
721  break;
723  val = 0;
724  break;
725  default:
726  val = 1;
727  break;
728  }
729  return match && (par->codec_id != AV_CODEC_ID_NONE && val != 0);
730  } else {
731  return AVERROR(EINVAL);
732  }
733  }
734 
735  return match;
736 }
737 
739  const char *spec)
740 {
741  int ret, index;
742  char *endptr;
743  const char *indexptr = NULL;
744  const AVStreamGroup *g = NULL;
745  const AVProgram *p = NULL;
746  int nb_streams;
747 
748  ret = match_stream_specifier(s, st, spec, &indexptr, &g, &p);
749  if (ret < 0)
750  goto error;
751 
752  if (!indexptr)
753  return ret;
754 
755  index = strtol(indexptr, &endptr, 0);
756  if (*endptr) { /* We can't have anything after the requested index. */
757  ret = AVERROR(EINVAL);
758  goto error;
759  }
760 
761  /* This is not really needed but saves us a loop for simple stream index specifiers. */
762  if (spec == indexptr)
763  return (index == st->index);
764 
765  /* If we requested a matching stream index, we have to ensure st is that. */
766  nb_streams = g ? g->nb_streams : (p ? p->nb_stream_indexes : s->nb_streams);
767  for (int i = 0; i < nb_streams && index >= 0; i++) {
768  unsigned idx = g ? g->streams[i]->index : (p ? p->stream_index[i] : i);
769  const AVStream *candidate = s->streams[idx];
770  ret = match_stream_specifier(s, candidate, spec, NULL, NULL, NULL);
771  if (ret < 0)
772  goto error;
773  if (ret > 0 && index-- == 0 && st == candidate)
774  return 1;
775  }
776  return 0;
777 
778 error:
779  if (ret == AVERROR(EINVAL))
780  av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
781  return ret;
782 }
783 
785 {
786  AVRational undef = {0, 1};
787  AVRational stream_sample_aspect_ratio = stream ? stream->sample_aspect_ratio : undef;
788  AVRational codec_sample_aspect_ratio = stream && stream->codecpar ? stream->codecpar->sample_aspect_ratio : undef;
789  AVRational frame_sample_aspect_ratio = frame ? frame->sample_aspect_ratio : codec_sample_aspect_ratio;
790 
791  av_reduce(&stream_sample_aspect_ratio.num, &stream_sample_aspect_ratio.den,
792  stream_sample_aspect_ratio.num, stream_sample_aspect_ratio.den, INT_MAX);
793  if (stream_sample_aspect_ratio.num <= 0 || stream_sample_aspect_ratio.den <= 0)
794  stream_sample_aspect_ratio = undef;
795 
796  av_reduce(&frame_sample_aspect_ratio.num, &frame_sample_aspect_ratio.den,
797  frame_sample_aspect_ratio.num, frame_sample_aspect_ratio.den, INT_MAX);
798  if (frame_sample_aspect_ratio.num <= 0 || frame_sample_aspect_ratio.den <= 0)
799  frame_sample_aspect_ratio = undef;
800 
801  if (stream_sample_aspect_ratio.num)
802  return stream_sample_aspect_ratio;
803  else
804  return frame_sample_aspect_ratio;
805 }
806 
808 {
809  AVRational fr = st->r_frame_rate;
811  AVRational avg_fr = st->avg_frame_rate;
812 
813  if (avg_fr.num > 0 && avg_fr.den > 0 && fr.num > 0 && fr.den > 0 &&
814  av_q2d(avg_fr) < 70 && av_q2d(fr) > 210) {
815  fr = avg_fr;
816  }
817 
818  if (desc && (desc->props & AV_CODEC_PROP_FIELDS)) {
819  const AVCodecContext *const avctx = ffstream(st)->avctx;
820  AVRational codec_fr = avctx->framerate;
821 
822  if ( codec_fr.num > 0 && codec_fr.den > 0 &&
823  (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))
824  fr = codec_fr;
825  }
826 
827  return fr;
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) &&
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  URLComponents uc;
924  av_assert0(url);
925  char proto[64];
926 
927  int ret = ff_url_decompose(&uc, url, NULL);
928  if (ret < 0)
929  return ret;
930  av_strlcpy(proto, uc.scheme, FFMIN(sizeof(proto), uc.url_component_end_scheme - uc.scheme));
931 
932  if (s->protocol_whitelist && av_match_list(proto, s->protocol_whitelist, ',') <= 0) {
933  av_log(s, AV_LOG_ERROR, "Protocol '%s' not on whitelist '%s'!\n", proto, s->protocol_whitelist);
934  return AVERROR(EINVAL);
935  }
936 
937  if (s->protocol_blacklist && av_match_list(proto, s->protocol_blacklist, ',') > 0) {
938  av_log(s, AV_LOG_ERROR, "Protocol '%s' on blacklist '%s'!\n", proto, s->protocol_blacklist);
939  return AVERROR(EINVAL);
940  }
941 
942  char *urldup = av_strdup(url);
943  if (!urldup)
944  return AVERROR(ENOMEM);
945 
946  av_freep(&s->url);
947  s->url = urldup;
948  return 0;
949 }
950 
951 
953 {
954  int ret = 0;
955  if (*pb)
956  ret = s->io_close2(s, *pb);
957  *pb = NULL;
958  return ret;
959 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
flags
const SwsFlags flags[]
Definition: swscale.c:85
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:1127
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
AVStreamGroup::params
union AVStreamGroup::@455 params
Group type-specific parameters.
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:1175
AV_STREAM_GROUP_PARAMS_LCEVC
@ AV_STREAM_GROUP_PARAMS_LCEVC
Definition: avformat.h:1132
AVProgram::nb_stream_indexes
unsigned int nb_stream_indexes
Definition: avformat.h:1243
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:500
FFStream::bsfc
struct AVBSFContext * bsfc
bitstream filter to run on stream
Definition: internal.h:146
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:49
FFStream::bsf
struct AVBSFContext * bsf
Definition: internal.h:166
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:772
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:673
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:818
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:449
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:1249
int64_t
long long int64_t
Definition: coverity.c:34
URLComponents
Definition: url.h:359
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:620
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:466
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1382
AVPacket::data
uint8_t * data
Definition: packet.h:603
AVStreamGroupTileGrid::offsets
struct AVStreamGroupTileGrid::@454 * offsets
An nb_tiles sized array of offsets in pixels from the topleft edge of the canvas, indicating where ea...
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:836
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:1512
AVStreamGroup::tref
struct AVStreamGroupTREF * tref
Definition: avformat.h:1184
AVProgram::flags
int flags
Definition: avformat.h:1240
cffstream
static const av_always_inline FFStream * cffstream(const AVStream *st)
Definition: internal.h:363
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:329
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
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:1247
FFStream::codec_desc
const struct AVCodecDescriptor * codec_desc
Definition: internal.h:355
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:120
ff_free_stream_group
void ff_free_stream_group(AVStreamGroup **pstg)
Frees a stream group without modifying the corresponding AVFormatContext.
Definition: avformat.c:78
AVFMT_PROGCOPY_OVERWRITE
#define AVFMT_PROGCOPY_OVERWRITE
overwrite pre-existing program having same ID
Definition: avformat.h:2129
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:358
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:210
avformat_stream_group_name
const char * avformat_stream_group_name(enum AVStreamGroupParamsType type)
Definition: avformat.c:264
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:1241
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:156
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:277
AV_PTS_WRAP_IGNORE
#define AV_PTS_WRAP_IGNORE
Options for behavior on timestamp wrap detection.
Definition: avformat.h:736
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:1134
AVFMT_PROGCOPY_MATCH_BY_INDEX
#define AVFMT_PROGCOPY_MATCH_BY_INDEX
match streams using stream index
Definition: avformat.h:2128
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:845
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:1239
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
AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION
@ AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION
Definition: avformat.h:1130
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:921
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:1511
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:454
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:784
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:335
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:344
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:308
key
const char * key
Definition: hwcontext_opencl.c:189
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:1176
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:1314
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:770
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:786
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:445
av_program_add_stream_index
void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
Definition: avformat.c:338
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:1057
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:875
FFOutputFormat::deinit
void(* deinit)(AVFormatContext *)
Deinitialize format.
Definition: mux.h:154
AVProgram::stream_index
unsigned int * stream_index
Definition: avformat.h:1242
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:827
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:2127
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:989
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1370
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:1131
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:738
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:1133
FFStream
Definition: internal.h:128
ff_free_stream
void ff_free_stream(AVStream **pst)
Frees a stream without modifying the corresponding AVFormatContext.
Definition: avformat.c:45
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:1173
ff_format_io_close
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: avformat.c:952
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:1246
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:825
frame.h
AV_DISPOSITION_HEARING_IMPAIRED
#define AV_DISPOSITION_HEARING_IMPAIRED
The stream is intended for hearing impaired audiences.
Definition: avformat.h:657
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:1129
AVStreamGroup::streams
AVStream ** streams
A list of streams in the group.
Definition: avformat.h:1215
AVStreamGroup::iamf_mix_presentation
struct AVIAMFMixPresentation * iamf_mix_presentation
Definition: avformat.h:1174
avformat_internal.h
FFStream::probe_data
AVProbeData probe_data
Definition: internal.h:298
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:1062
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: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:1244
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:464
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1238
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:816
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:575
AV_DISPOSITION_VISUAL_IMPAIRED
#define AV_DISPOSITION_VISUAL_IMPAIRED
The stream is intended for visually impaired audiences.
Definition: avformat.h:661
tag
uint32_t tag
Definition: movenc.c:2073
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:759
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:747
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:807
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:1195
avformat.h
id
enum AVCodecID id
Definition: dts2pts.c:578
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:315
URLComponents::scheme
const char * scheme
possibly including lavf-specific options
Definition: url.h:361
AVStreamGroup
Definition: avformat.h:1140
AVCodecContext
main external API structure.
Definition: avcodec.h:443
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:753
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:137
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:128
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: avformat.c:148
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:881
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:330
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
FFStream::extract_extradata
struct FFStream::@485 extract_extradata
FFStream::info
struct FFStreamInfo * info
Stream information used internally by avformat_find_stream_info()
Definition: internal.h:182
FFStream::index_entries
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: internal.h:184
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:1167
av_strdup
#define av_strdup(s)
Definition: ops_asmgen.c:47
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
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:246
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:315
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3878
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:890
codec_desc.h
AVStreamGroup::priv_data
void * priv_data
Definition: avformat.h:1146
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:1248
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
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