FFmpeg
avformat.c
Go to the documentation of this file.
1 /*
2  * Various functions used by both muxers and demuxers
3  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <math.h>
23 #include "libavutil/avassert.h"
24 #include "libavutil/avstring.h"
26 #include "libavutil/frame.h"
27 #include "libavutil/iamf.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/mem.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/pixfmt.h"
32 #include "libavutil/samplefmt.h"
33 #include "libavcodec/avcodec.h"
34 #include "libavcodec/codec.h"
35 #include "libavcodec/bsf.h"
36 #include "libavcodec/codec_desc.h"
38 #include "avformat.h"
39 #include "avformat_internal.h"
40 #include "avio.h"
41 #include "demux.h"
42 #include "mux.h"
43 #include "internal.h"
44 
46 {
47  AVStream *st = *pst;
48  FFStream *const sti = ffstream(st);
49 
50  if (!st)
51  return;
52 
53 #if FF_API_AVSTREAM_SIDE_DATA
55  for (int i = 0; i < st->nb_side_data; i++)
56  av_freep(&st->side_data[i].data);
57  av_freep(&st->side_data);
59 #endif
60 
61  if (st->attached_pic.data)
63 
64  av_parser_close(sti->parser);
66  av_bsf_free(&sti->bsfc);
67  av_freep(&sti->index_entries);
68  av_freep(&sti->probe_data.buf);
69 
71 
72  if (sti->info) {
74  av_freep(&sti->info);
75  }
76 
77  av_dict_free(&st->metadata);
79  av_freep(&st->priv_data);
80 
81  av_freep(pst);
82 }
83 
85 {
86  AVStreamGroup *stg = *pstg;
87 
88  if (!stg)
89  return;
90 
91  av_freep(&stg->streams);
92  av_dict_free(&stg->metadata);
93  av_freep(&stg->priv_data);
94  switch (stg->type) {
97  break;
98  }
101  break;
102  }
108  av_freep(&stg->params.tile_grid);
109  break;
111  av_opt_free(stg->params.lcevc);
112  av_freep(&stg->params.lcevc);
113  break;
114  default:
115  break;
116  }
117 
118  av_freep(pstg);
119 }
120 
122 {
123  av_assert0(s->nb_streams>0);
124  av_assert0(s->streams[ s->nb_streams - 1 ] == st);
125 
126  ff_free_stream(&s->streams[ --s->nb_streams ]);
127 }
128 
130 {
131  av_assert0(s->nb_stream_groups > 0);
132  av_assert0(s->stream_groups[ s->nb_stream_groups - 1 ] == stg);
133 
134  ff_free_stream_group(&s->stream_groups[ --s->nb_stream_groups ]);
135 }
136 
137 /* XXX: suppress the packet queue */
139 {
140  FormatContextInternal *const fci = ff_fc_internal(s);
141  FFFormatContext *const si = &fci->fc;
145 
146  fci->raw_packet_buffer_size = 0;
147 }
148 
150 {
152  FFFormatContext *si;
153 
154  if (!s)
155  return;
156  fci = ff_fc_internal(s);
157  si = &fci->fc;
158 
159  if (s->oformat && ffofmt(s->oformat)->deinit && fci->initialized)
160  ffofmt(s->oformat)->deinit(s);
161 
162  av_opt_free(s);
163  if (s->iformat && s->iformat->priv_class && s->priv_data)
164  av_opt_free(s->priv_data);
165  if (s->oformat && s->oformat->priv_class && s->priv_data)
166  av_opt_free(s->priv_data);
167 
168  for (unsigned i = 0; i < s->nb_streams; i++)
169  ff_free_stream(&s->streams[i]);
170  for (unsigned i = 0; i < s->nb_stream_groups; i++)
171  ff_free_stream_group(&s->stream_groups[i]);
172  s->nb_stream_groups = 0;
173  s->nb_streams = 0;
174 
175  for (unsigned i = 0; i < s->nb_programs; i++) {
176  av_dict_free(&s->programs[i]->metadata);
177  av_freep(&s->programs[i]->stream_index);
178  av_freep(&s->programs[i]);
179  }
180  s->nb_programs = 0;
181 
182  av_freep(&s->programs);
183  av_freep(&s->priv_data);
184  while (s->nb_chapters--) {
185  av_dict_free(&s->chapters[s->nb_chapters]->metadata);
186  av_freep(&s->chapters[s->nb_chapters]);
187  }
188  av_freep(&s->chapters);
189  av_dict_free(&s->metadata);
190  av_dict_free(&si->id3v2_meta);
191  av_packet_free(&si->pkt);
194  av_freep(&s->streams);
195  av_freep(&s->stream_groups);
196  if (s->iformat)
198  av_freep(&s->url);
199  av_free(s);
200 }
201 
202 #if FF_API_AVSTREAM_SIDE_DATA
204 uint8_t *av_stream_get_side_data(const AVStream *st,
205  enum AVPacketSideDataType type, size_t *size)
206 {
207  for (int i = 0; i < st->nb_side_data; i++) {
208  if (st->side_data[i].type == type) {
209  if (size)
210  *size = st->side_data[i].size;
211  return st->side_data[i].data;
212  }
213  }
214  if (size)
215  *size = 0;
216  return NULL;
217 }
218 
219 int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type,
220  uint8_t *data, size_t size)
221 {
222  AVPacketSideData *sd, *tmp;
223 
224  for (int i = 0; i < st->nb_side_data; i++) {
225  sd = &st->side_data[i];
226 
227  if (sd->type == type) {
228  av_freep(&sd->data);
229  sd->data = data;
230  sd->size = size;
231  return 0;
232  }
233  }
234 
235  if (st->nb_side_data + 1U > FFMIN(INT_MAX, SIZE_MAX / sizeof(*tmp)))
236  return AVERROR(ERANGE);
237 
238  tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp));
239  if (!tmp) {
240  return AVERROR(ENOMEM);
241  }
242 
243  st->side_data = tmp;
244  st->nb_side_data++;
245 
246  sd = &st->side_data[st->nb_side_data - 1];
247  sd->type = type;
248  sd->data = data;
249  sd->size = size;
250 
251  return 0;
252 }
253 
254 uint8_t *av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
255  size_t size)
256 {
257  int ret;
258  uint8_t *data = av_malloc(size);
259 
260  if (!data)
261  return NULL;
262 
263  ret = av_stream_add_side_data(st, type, data, size);
264  if (ret < 0) {
265  av_freep(&data);
266  return NULL;
267  }
268 
269  return data;
270 }
272 #endif
273 
274 /**
275  * Copy all stream parameters from source to destination stream, with the
276  * exception of the index field, which is usually set by avformat_new_stream().
277  *
278  * @param dst pointer to destination AVStream
279  * @param src pointer to source AVStream
280  * @return >=0 on success, AVERROR code on error
281  */
283 {
284  int ret;
285 
286  dst->id = src->id;
287  dst->time_base = src->time_base;
288  dst->start_time = src->start_time;
289  dst->duration = src->duration;
290  dst->nb_frames = src->nb_frames;
291  dst->disposition = src->disposition;
292  dst->discard = src->discard;
293  dst->sample_aspect_ratio = src->sample_aspect_ratio;
294  dst->avg_frame_rate = src->avg_frame_rate;
295  dst->event_flags = src->event_flags;
296  dst->r_frame_rate = src->r_frame_rate;
297  dst->pts_wrap_bits = src->pts_wrap_bits;
298 
299  av_dict_free(&dst->metadata);
300  ret = av_dict_copy(&dst->metadata, src->metadata, 0);
301  if (ret < 0)
302  return ret;
303 
304  ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
305  if (ret < 0)
306  return ret;
307 
308  av_packet_unref(&dst->attached_pic);
309  if (src->attached_pic.data) {
310  ret = av_packet_ref(&dst->attached_pic, &src->attached_pic);
311  if (ret < 0)
312  return ret;
313  }
314 
315  return 0;
316 }
317 
319 {
320  AVStream *st;
321  int ret;
322 
323  st = avformat_new_stream(dst_ctx, NULL);
324  if (!st)
325  return NULL;
326 
327  ret = stream_params_copy(st, src);
328  if (ret < 0) {
329  ff_remove_stream(dst_ctx, st);
330  return NULL;
331  }
332 
333  return st;
334 }
335 
337 {
338  switch(type) {
339  case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: return "IAMF Audio Element";
340  case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: return "IAMF Mix Presentation";
341  case AV_STREAM_GROUP_PARAMS_TILE_GRID: return "Tile Grid";
342  case AV_STREAM_GROUP_PARAMS_LCEVC: return "LCEVC (Split video and enhancement)";
343  }
344  return NULL;
345 }
346 
348 {
350  int ret;
351 
352  av_log(ac, AV_LOG_TRACE, "new_program: id=0x%04x\n", id);
353 
354  for (unsigned i = 0; i < ac->nb_programs; i++)
355  if (ac->programs[i]->id == id)
356  program = ac->programs[i];
357 
358  if (!program) {
359  program = av_mallocz(sizeof(*program));
360  if (!program)
361  return NULL;
363  if (ret < 0) {
364  av_free(program);
365  return NULL;
366  }
367  program->discard = AVDISCARD_NONE;
368  program->pmt_version = -1;
369  program->id = id;
370  program->pts_wrap_reference = AV_NOPTS_VALUE;
371  program->pts_wrap_behavior = AV_PTS_WRAP_IGNORE;
372  program->start_time =
373  program->end_time = AV_NOPTS_VALUE;
374  }
375  return program;
376 }
377 
378 void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
379 {
381  void *tmp;
382 
383  if (idx >= ac->nb_streams) {
384  av_log(ac, AV_LOG_ERROR, "stream index %d is not valid\n", idx);
385  return;
386  }
387 
388  for (unsigned i = 0; i < ac->nb_programs; i++) {
389  if (ac->programs[i]->id != progid)
390  continue;
391  program = ac->programs[i];
392  for (unsigned j = 0; j < program->nb_stream_indexes; j++)
393  if (program->stream_index[j] == idx)
394  return;
395 
396  tmp = av_realloc_array(program->stream_index, program->nb_stream_indexes+1, sizeof(unsigned int));
397  if (!tmp)
398  return;
399  program->stream_index = tmp;
400  program->stream_index[program->nb_stream_indexes++] = idx;
401  return;
402  }
403 }
404 
406 {
407  for (unsigned i = 0; i < ic->nb_programs; i++) {
408  if (ic->programs[i] == last) {
409  last = NULL;
410  } else {
411  if (!last)
412  for (unsigned j = 0; j < ic->programs[i]->nb_stream_indexes; j++)
413  if (ic->programs[i]->stream_index[j] == s)
414  return ic->programs[i];
415  }
416  }
417  return NULL;
418 }
419 
421 {
422  int best_stream = 0;
423  int best_score = INT_MIN;
424 
425  if (s->nb_streams <= 0)
426  return -1;
427  for (unsigned i = 0; i < s->nb_streams; i++) {
428  const AVStream *const st = s->streams[i];
429  const FFStream *const sti = cffstream(st);
430  int score = 0;
431  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
433  score -= 400;
434  if (st->codecpar->width && st->codecpar->height)
435  score += 50;
436  score+= 25;
437  }
438  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
439  if (st->codecpar->sample_rate)
440  score += 50;
441  }
442  if (sti->codec_info_nb_frames)
443  score += 12;
444 
445  if (st->discard != AVDISCARD_ALL)
446  score += 200;
447 
448  if (score > best_score) {
449  best_score = score;
450  best_stream = i;
451  }
452  }
453  return best_stream;
454 }
455 
457  int wanted_stream_nb, int related_stream,
458  const AVCodec **decoder_ret, int flags)
459 {
460  int nb_streams = ic->nb_streams;
462  int best_count = -1, best_multiframe = -1, best_disposition = -1;
463  int count, multiframe, disposition;
464  int64_t best_bitrate = -1;
466  unsigned *program = NULL;
467  const AVCodec *decoder = NULL, *best_decoder = NULL;
468 
469  if (related_stream >= 0 && wanted_stream_nb < 0) {
470  AVProgram *p = av_find_program_from_stream(ic, NULL, related_stream);
471  if (p) {
472  program = p->stream_index;
474  }
475  }
476  for (unsigned i = 0; i < nb_streams; i++) {
477  int real_stream_index = program ? program[i] : i;
478  AVStream *st = ic->streams[real_stream_index];
479  AVCodecParameters *par = st->codecpar;
480  if (par->codec_type != type)
481  continue;
482  if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
483  continue;
484  if (type == AVMEDIA_TYPE_AUDIO && !(par->ch_layout.nb_channels && par->sample_rate))
485  continue;
486  if (decoder_ret) {
487  decoder = ff_find_decoder(ic, st, par->codec_id);
488  if (!decoder) {
489  if (ret < 0)
491  continue;
492  }
493  }
495  + !! (st->disposition & AV_DISPOSITION_DEFAULT);
496  count = ffstream(st)->codec_info_nb_frames;
497  bitrate = par->bit_rate;
498  multiframe = FFMIN(5, count);
499  if ((best_disposition > disposition) ||
500  (best_disposition == disposition && best_multiframe > multiframe) ||
501  (best_disposition == disposition && best_multiframe == multiframe && best_bitrate > bitrate) ||
502  (best_disposition == disposition && best_multiframe == multiframe && best_bitrate == bitrate && best_count >= count))
503  continue;
504  best_disposition = disposition;
505  best_count = count;
506  best_bitrate = bitrate;
507  best_multiframe = multiframe;
508  ret = real_stream_index;
509  best_decoder = decoder;
510  if (program && i == nb_streams - 1 && ret < 0) {
511  program = NULL;
512  nb_streams = ic->nb_streams;
513  /* no related stream found, try again with everything */
514  i = 0;
515  }
516  }
517  if (decoder_ret)
518  *decoder_ret = best_decoder;
519  return ret;
520 }
521 
522 /**
523  * Matches a stream specifier (but ignores requested index).
524  *
525  * @param indexptr set to point to the requested stream index if there is one
526  *
527  * @return <0 on error
528  * 0 if st is NOT a matching stream
529  * >0 if st is a matching stream
530  */
531 static int match_stream_specifier(const AVFormatContext *s, const AVStream *st,
532  const char *spec, const char **indexptr,
533  const AVStreamGroup **g, const AVProgram **p)
534 {
535  int match = 1; /* Stores if the specifier matches so far. */
536  while (*spec) {
537  if (*spec <= '9' && *spec >= '0') { /* opt:index */
538  if (indexptr)
539  *indexptr = spec;
540  return match;
541  } else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||
542  *spec == 't' || *spec == 'V') { /* opt:[vasdtV] */
543  enum AVMediaType type;
544  int nopic = 0;
545 
546  switch (*spec++) {
547  case 'v': type = AVMEDIA_TYPE_VIDEO; break;
548  case 'a': type = AVMEDIA_TYPE_AUDIO; break;
549  case 's': type = AVMEDIA_TYPE_SUBTITLE; break;
550  case 'd': type = AVMEDIA_TYPE_DATA; break;
551  case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
552  case 'V': type = AVMEDIA_TYPE_VIDEO; nopic = 1; break;
553  default: av_assert0(0);
554  }
555  if (*spec && *spec++ != ':') /* If we are not at the end, then another specifier must follow. */
556  return AVERROR(EINVAL);
557 
558  if (type != st->codecpar->codec_type)
559  match = 0;
560  if (nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC))
561  match = 0;
562  } else if (*spec == 'g' && *(spec + 1) == ':') {
563  int64_t group_idx = -1, group_id = -1;
564  int found = 0;
565  char *endptr;
566  spec += 2;
567  if (*spec == '#' || (*spec == 'i' && *(spec + 1) == ':')) {
568  spec += 1 + (*spec == 'i');
569  group_id = strtol(spec, &endptr, 0);
570  if (spec == endptr || (*endptr && *endptr++ != ':'))
571  return AVERROR(EINVAL);
572  spec = endptr;
573  } else {
574  group_idx = strtol(spec, &endptr, 0);
575  /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
576  if (spec == endptr || (*endptr && *endptr++ != ':'))
577  return AVERROR(EINVAL);
578  spec = endptr;
579  }
580  if (match) {
581  if (group_id > 0) {
582  for (unsigned i = 0; i < s->nb_stream_groups; i++) {
583  if (group_id == s->stream_groups[i]->id) {
584  group_idx = i;
585  break;
586  }
587  }
588  }
589  if (group_idx < 0 || group_idx >= s->nb_stream_groups)
590  return AVERROR(EINVAL);
591  for (unsigned j = 0; j < s->stream_groups[group_idx]->nb_streams; j++) {
592  if (st->index == s->stream_groups[group_idx]->streams[j]->index) {
593  found = 1;
594  if (g)
595  *g = s->stream_groups[group_idx];
596  break;
597  }
598  }
599  }
600  if (!found)
601  match = 0;
602  } else if (*spec == 'p' && *(spec + 1) == ':') {
603  int prog_id;
604  int found = 0;
605  char *endptr;
606  spec += 2;
607  prog_id = strtol(spec, &endptr, 0);
608  /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
609  if (spec == endptr || (*endptr && *endptr++ != ':'))
610  return AVERROR(EINVAL);
611  spec = endptr;
612  if (match) {
613  for (unsigned i = 0; i < s->nb_programs; i++) {
614  if (s->programs[i]->id != prog_id)
615  continue;
616 
617  for (unsigned j = 0; j < s->programs[i]->nb_stream_indexes; j++) {
618  if (st->index == s->programs[i]->stream_index[j]) {
619  found = 1;
620  if (p)
621  *p = s->programs[i];
622  i = s->nb_programs;
623  break;
624  }
625  }
626  }
627  }
628  if (!found)
629  match = 0;
630  } else if (*spec == '#' ||
631  (*spec == 'i' && *(spec + 1) == ':')) {
632  int stream_id;
633  char *endptr;
634  spec += 1 + (*spec == 'i');
635  stream_id = strtol(spec, &endptr, 0);
636  if (spec == endptr || *endptr) /* Disallow empty id and make sure we are at the end. */
637  return AVERROR(EINVAL);
638  return match && (stream_id == st->id);
639  } else if (*spec == 'm' && *(spec + 1) == ':') {
640  const AVDictionaryEntry *tag;
641  char *key, *val;
642  int ret;
643 
644  if (match) {
645  spec += 2;
646  val = strchr(spec, ':');
647 
648  key = val ? av_strndup(spec, val - spec) : av_strdup(spec);
649  if (!key)
650  return AVERROR(ENOMEM);
651 
652  tag = av_dict_get(st->metadata, key, NULL, 0);
653  if (tag) {
654  if (!val || !strcmp(tag->value, val + 1))
655  ret = 1;
656  else
657  ret = 0;
658  } else
659  ret = 0;
660 
661  av_freep(&key);
662  }
663  return match && ret;
664  } else if (*spec == 'u' && *(spec + 1) == '\0') {
665  const AVCodecParameters *par = st->codecpar;
666  int val;
667  switch (par->codec_type) {
668  case AVMEDIA_TYPE_AUDIO:
669  val = par->sample_rate && par->ch_layout.nb_channels;
670  if (par->format == AV_SAMPLE_FMT_NONE)
671  return 0;
672  break;
673  case AVMEDIA_TYPE_VIDEO:
674  val = par->width && par->height;
675  if (par->format == AV_PIX_FMT_NONE)
676  return 0;
677  break;
679  val = 0;
680  break;
681  default:
682  val = 1;
683  break;
684  }
685  return match && (par->codec_id != AV_CODEC_ID_NONE && val != 0);
686  } else {
687  return AVERROR(EINVAL);
688  }
689  }
690 
691  return match;
692 }
693 
695  const char *spec)
696 {
697  int ret, index;
698  char *endptr;
699  const char *indexptr = NULL;
700  const AVStreamGroup *g = NULL;
701  const AVProgram *p = NULL;
702  int nb_streams;
703 
704  ret = match_stream_specifier(s, st, spec, &indexptr, &g, &p);
705  if (ret < 0)
706  goto error;
707 
708  if (!indexptr)
709  return ret;
710 
711  index = strtol(indexptr, &endptr, 0);
712  if (*endptr) { /* We can't have anything after the requested index. */
713  ret = AVERROR(EINVAL);
714  goto error;
715  }
716 
717  /* This is not really needed but saves us a loop for simple stream index specifiers. */
718  if (spec == indexptr)
719  return (index == st->index);
720 
721  /* If we requested a matching stream index, we have to ensure st is that. */
722  nb_streams = g ? g->nb_streams : (p ? p->nb_stream_indexes : s->nb_streams);
723  for (int i = 0; i < nb_streams && index >= 0; i++) {
724  unsigned idx = g ? g->streams[i]->index : (p ? p->stream_index[i] : i);
725  const AVStream *candidate = s->streams[idx];
726  ret = match_stream_specifier(s, candidate, spec, NULL, NULL, NULL);
727  if (ret < 0)
728  goto error;
729  if (ret > 0 && index-- == 0 && st == candidate)
730  return 1;
731  }
732  return 0;
733 
734 error:
735  if (ret == AVERROR(EINVAL))
736  av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
737  return ret;
738 }
739 
741 {
742  AVRational undef = {0, 1};
743  AVRational stream_sample_aspect_ratio = stream ? stream->sample_aspect_ratio : undef;
744  AVRational codec_sample_aspect_ratio = stream && stream->codecpar ? stream->codecpar->sample_aspect_ratio : undef;
745  AVRational frame_sample_aspect_ratio = frame ? frame->sample_aspect_ratio : codec_sample_aspect_ratio;
746 
747  av_reduce(&stream_sample_aspect_ratio.num, &stream_sample_aspect_ratio.den,
748  stream_sample_aspect_ratio.num, stream_sample_aspect_ratio.den, INT_MAX);
749  if (stream_sample_aspect_ratio.num <= 0 || stream_sample_aspect_ratio.den <= 0)
750  stream_sample_aspect_ratio = undef;
751 
752  av_reduce(&frame_sample_aspect_ratio.num, &frame_sample_aspect_ratio.den,
753  frame_sample_aspect_ratio.num, frame_sample_aspect_ratio.den, INT_MAX);
754  if (frame_sample_aspect_ratio.num <= 0 || frame_sample_aspect_ratio.den <= 0)
755  frame_sample_aspect_ratio = undef;
756 
757  if (stream_sample_aspect_ratio.num)
758  return stream_sample_aspect_ratio;
759  else
760  return frame_sample_aspect_ratio;
761 }
762 
764 {
765  AVRational fr = st->r_frame_rate;
767  AVRational avg_fr = st->avg_frame_rate;
768 
769  if (avg_fr.num > 0 && avg_fr.den > 0 && fr.num > 0 && fr.den > 0 &&
770  av_q2d(avg_fr) < 70 && av_q2d(fr) > 210) {
771  fr = avg_fr;
772  }
773 
774  if (desc && (desc->props & AV_CODEC_PROP_FIELDS)) {
775  const AVCodecContext *const avctx = ffstream(st)->avctx;
776  AVRational codec_fr = avctx->framerate;
777 
778  if ( codec_fr.num > 0 && codec_fr.den > 0 &&
779  (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))
780  fr = codec_fr;
781  }
782 
783  return fr;
784 }
785 
786 #if FF_API_INTERNAL_TIMING
787 int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt,
788  AVStream *ost, const AVStream *ist,
789  enum AVTimebaseSource copy_tb)
790 {
792  const AVCodecContext *const dec_ctx = cffstream(ist)->avctx;
793 
794  AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 };
795  AVRational dec_ctx_framerate = dec_ctx ? dec_ctx->framerate : (AVRational){ 0, 0 };
796  AVRational dec_ctx_tb = dec_ctx_framerate.num ? av_inv_q(av_mul_q(dec_ctx_framerate, mul))
797  : (ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ? (AVRational){0, 1}
798  : ist->time_base);
799  AVRational enc_tb = ist->time_base;
800 #if FF_API_TICKS_PER_FRAME
802  int ticks_per_frame = dec_ctx ? dec_ctx->ticks_per_frame : 1;
804 #endif
805 
806  /*
807  * Avi is a special case here because it supports variable fps but
808  * having the fps and timebase differe significantly adds quite some
809  * overhead
810  */
811  if (!strcmp(ofmt->name, "avi")) {
812 #if FF_API_R_FRAME_RATE
813  if (copy_tb == AVFMT_TBCF_AUTO && ist->r_frame_rate.num
814  && av_q2d(ist->r_frame_rate) >= av_q2d(ist->avg_frame_rate)
815  && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(ist->time_base)
816  && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(dec_ctx_tb)
817  && av_q2d(ist->time_base) < 1.0/500 && av_q2d(dec_ctx_tb) < 1.0/500
818  || copy_tb == AVFMT_TBCF_R_FRAMERATE) {
819  enc_tb.num = ist->r_frame_rate.den;
820  enc_tb.den = 2*ist->r_frame_rate.num;
821  } else
822 #endif
823  if (copy_tb == AVFMT_TBCF_AUTO && dec_ctx_framerate.num &&
824  av_q2d(av_inv_q(dec_ctx_framerate)) > 2*av_q2d(ist->time_base)
825  && av_q2d(ist->time_base) < 1.0/500
826  || (copy_tb == AVFMT_TBCF_DECODER &&
827  (dec_ctx_framerate.num || ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))) {
828  enc_tb = dec_ctx_tb;
829  enc_tb.den *= 2;
830 #if FF_API_TICKS_PER_FRAME
831  enc_tb.num *= ticks_per_frame;
832 #endif
833  }
834  } else if (!(ofmt->flags & AVFMT_VARIABLE_FPS)
835  && !av_match_name(ofmt->name, "mov,mp4,3gp,3g2,psp,ipod,ismv,f4v")) {
836  if (copy_tb == AVFMT_TBCF_AUTO && dec_ctx_framerate.num
837  && av_q2d(av_inv_q(dec_ctx_framerate)) > av_q2d(ist->time_base)
838  && av_q2d(ist->time_base) < 1.0/500
839  || (copy_tb == AVFMT_TBCF_DECODER &&
840  (dec_ctx_framerate.num || ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))) {
841  enc_tb = dec_ctx_tb;
842 #if FF_API_TICKS_PER_FRAME
843  enc_tb.num *= ticks_per_frame;
844 #endif
845  }
846  }
847 
848  if (ost->codecpar->codec_tag == AV_RL32("tmcd")
849  && dec_ctx_tb.num < dec_ctx_tb.den
850  && dec_ctx_tb.num > 0
851  && 121LL*dec_ctx_tb.num > dec_ctx_tb.den) {
852  enc_tb = dec_ctx_tb;
853  }
854 
855  av_reduce(&ffstream(ost)->transferred_mux_tb.num,
856  &ffstream(ost)->transferred_mux_tb.den,
857  enc_tb.num, enc_tb.den, INT_MAX);
858 
859  return 0;
860 }
861 
862 AVRational av_stream_get_codec_timebase(const AVStream *st)
863 {
864  return cffstream(st)->avctx ? cffstream(st)->avctx->time_base : cffstream(st)->transferred_mux_tb;
865 }
866 #endif
867 
868 void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits,
869  unsigned int pts_num, unsigned int pts_den)
870 {
871  FFStream *const sti = ffstream(st);
872  AVRational new_tb;
873  if (av_reduce(&new_tb.num, &new_tb.den, pts_num, pts_den, INT_MAX)) {
874  if (new_tb.num != pts_num)
876  "st:%d removing common factor %d from timebase\n",
877  st->index, pts_num / new_tb.num);
878  } else
880  "st:%d has too large timebase, reducing\n", st->index);
881 
882  if (new_tb.num <= 0 || new_tb.den <= 0) {
884  "Ignoring attempt to set invalid timebase %d/%d for st:%d\n",
885  new_tb.num, new_tb.den,
886  st->index);
887  return;
888  }
889  st->time_base = new_tb;
890  if (sti->avctx)
891  sti->avctx->pkt_timebase = new_tb;
892  st->pts_wrap_bits = pts_wrap_bits;
893 }
894 
896  enum AVCodecID codec_id)
897 {
898  switch (st->codecpar->codec_type) {
899  case AVMEDIA_TYPE_VIDEO:
900  if (s->video_codec) return s->video_codec;
901  break;
902  case AVMEDIA_TYPE_AUDIO:
903  if (s->audio_codec) return s->audio_codec;
904  break;
906  if (s->subtitle_codec) return s->subtitle_codec;
907  break;
908  }
909 
911 }
912 
914 {
915 #define OFF(field) offsetof(AVFormatContext, field)
916  static const unsigned offsets[] = {
917  OFF(codec_whitelist), OFF(format_whitelist),
918  OFF(protocol_whitelist), OFF(protocol_blacklist),
919  };
920 #undef OFF
921  av_assert0(!dst->codec_whitelist &&
922  !dst->format_whitelist &&
923  !dst->protocol_whitelist &&
924  !dst->protocol_blacklist);
925  for (unsigned i = 0; i < FF_ARRAY_ELEMS(offsets); i++) {
926  const char *src_str = *(char *const*)((const char*)src + offsets[i]);
927 
928  if (src_str) {
929  char *dst_str = av_strdup(src_str);
930  if (!dst_str) {
931  av_log(dst, AV_LOG_ERROR, "Failed to duplicate black/whitelist\n");
932  return AVERROR(ENOMEM);
933  }
934 
935  *(char **)((char*)dst + offsets[i]) = dst_str;
936  }
937  }
938  return 0;
939 }
940 
942 {
944  if (!d)
945  return 0;
946  if ((d->type == AVMEDIA_TYPE_VIDEO || d->type == AVMEDIA_TYPE_AUDIO) &&
948  return 0;
949  return 1;
950 }
951 
953 {
954  av_assert0(url);
955  av_freep(&s->url);
956  s->url = url;
957 }
958 
960 {
961  int ret = 0;
962  if (*pb)
963  ret = s->io_close2(s, *pb);
964  *pb = NULL;
965  return ret;
966 }
AVStreamGroup::params
union AVStreamGroup::@366 params
Group type-specific parameters.
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
iamf.h
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:430
AVCodec
AVCodec.
Definition: codec.h:187
AVStreamGroupParamsType
AVStreamGroupParamsType
Definition: avformat.h:1123
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
program
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C program
Definition: undefined.txt:6
dec_ctx
static AVCodecContext * dec_ctx
Definition: decode_filter_audio.c:47
AVOutputFormat::name
const char * name
Definition: avformat.h:510
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
AVStreamGroup::tile_grid
struct AVStreamGroupTileGrid * tile_grid
Definition: avformat.h:1169
AV_STREAM_GROUP_PARAMS_LCEVC
@ AV_STREAM_GROUP_PARAMS_LCEVC
Definition: avformat.h:1128
AVProgram::nb_stream_indexes
unsigned int nb_stream_indexes
Definition: avformat.h:1229
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:456
FFStream::bsfc
struct AVBSFContext * bsfc
bitstream filter to run on stream
Definition: internal.h:150
ff_find_decoder
const AVCodec * ff_find_decoder(AVFormatContext *s, const AVStream *st, enum AVCodecID codec_id)
Definition: avformat.c:895
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
FFStream::bsf
struct AVBSFContext * bsf
Definition: internal.h:170
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:773
AVFMT_VARIABLE_FPS
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:482
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:674
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:819
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:405
av_div_q
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition: rational.c:88
int64_t
long long int64_t
Definition: coverity.c:34
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:621
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:403
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1368
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:390
AVPacket::data
uint8_t * data
Definition: packet.h:539
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:837
data
const char data[16]
Definition: mxf.c:149
av_iamf_mix_presentation_free
void av_iamf_mix_presentation_free(AVIAMFMixPresentation **pmix_presentation)
Free an AVIAMFMixPresentation and all its contents.
Definition: iamf.c:534
AVFormatContext::programs
AVProgram ** programs
Definition: avformat.h:1501
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:59
cffstream
static const av_always_inline FFStream * cffstream(const AVStream *st)
Definition: internal.h:363
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:329
codec_type
enum AVMediaType codec_type
Definition: rtp.c:37
av_bsf_free
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
Definition: bsf.c:52
ost
static AVStream * ost
Definition: vaapi_transcode.c:42
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: packet.c:75
FormatContextInternal
Definition: avformat_internal.h:33
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
FFStream::codec_desc
const struct AVCodecDescriptor * codec_desc
Definition: internal.h:351
OFF
#define OFF(field)
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:574
AVPacketSideData::size
size_t size
Definition: packet.h:392
ff_remove_stream
void ff_remove_stream(AVFormatContext *s, AVStream *st)
Remove a stream from its AVFormatContext and free it.
Definition: avformat.c:121
ff_free_stream_group
void ff_free_stream_group(AVStreamGroup **pstg)
Frees a stream group without modifying the corresponding AVFormatContext.
Definition: avformat.c:84
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:868
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:282
avformat_stream_group_name
const char * avformat_stream_group_name(enum AVStreamGroupParamsType type)
Definition: avformat.c:336
samplefmt.h
av_iamf_audio_element_free
void av_iamf_audio_element_free(AVIAMFAudioElement **paudio_element)
Free an AVIAMFAudioElement and all its contents.
Definition: iamf.c:336
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1949
FFStream::avctx
struct AVCodecContext * avctx
The codec context used by avformat_find_stream_info, the parser, etc.
Definition: internal.h:160
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: defs.h:215
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:347
AV_PTS_WRAP_IGNORE
#define AV_PTS_WRAP_IGNORE
Options for behavior on timestamp wrap detection.
Definition: avformat.h:737
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
codec.h
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVStream::attached_pic
AVPacket attached_pic
For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet will contain the attached pictu...
Definition: avformat.h:846
avassert.h
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:235
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVProgram::id
int id
Definition: avformat.h:1225
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:62
AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION
@ AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION
Definition: avformat.h:1126
AVCodecDescriptor
This struct describes the properties of a single codec described by an AVCodecID.
Definition: codec_desc.h:38
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
FFFormatContext::packet_buffer
PacketList packet_buffer
This buffer is only needed when packets were already buffered but not decoded, for example to get the...
Definition: internal.h: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
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
AVCodecParameters::sample_aspect_ratio
AVRational sample_aspect_ratio
Video only.
Definition: codec_par.h:144
AVFormatContext::nb_programs
unsigned int nb_programs
Definition: avformat.h:1500
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:453
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:134
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
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:230
AVPacketSideData::data
uint8_t * data
Definition: packet.h:391
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:740
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:331
ffofmt
static const FFOutputFormat * ffofmt(const AVOutputFormat *fmt)
Definition: mux.h:167
nb_streams
static int nb_streams
Definition: ffprobe.c:385
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
key
const char * key
Definition: hwcontext_opencl.c:189
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
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:745
AVCodecDescriptor::props
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: codec_desc.h:54
FFFormatContext
Definition: internal.h:64
avpriv_packet_list_free
void avpriv_packet_list_free(PacketList *pkt_buf)
Wipe the list and unref all the packets in it.
Definition: packet.c:597
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:221
AVFormatContext
Format I/O context.
Definition: avformat.h:1300
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:771
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:787
NULL
#define NULL
Definition: coverity.c:32
av_program_add_stream_index
void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
Definition: avformat.c:378
avcodec_parameters_free
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
Definition: codec_par.c:66
AVStreamGroupTileGrid::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the grid.
Definition: avformat.h:1090
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:913
AVPacketSideData::type
enum AVPacketSideDataType type
Definition: packet.h:393
FFOutputFormat::deinit
void(* deinit)(AVFormatContext *)
Deinitialize format.
Definition: mux.h:154
AVProgram::stream_index
unsigned int * stream_index
Definition: avformat.h:1228
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:828
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:438
FormatContextInternal::fc
FFFormatContext fc
Definition: avformat_internal.h:34
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:180
index
int index
Definition: gxfenc.c:90
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:184
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:1015
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1356
FFFormatContext::id3v2_meta
AVDictionary * id3v2_meta
ID3v2 tag useful for MP3 demuxing.
Definition: internal.h:122
AVOutputFormat::flags
int flags
can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:529
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:1127
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:558
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
AVMediaType
AVMediaType
Definition: avutil.h:199
avformat_match_stream_specifier
int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the stream st contained in s is matched by the stream specifier spec.
Definition: avformat.c:694
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
FFStream
Definition: internal.h:132
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:83
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are expressed.
Definition: avcodec.h:565
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
size
int size
Definition: twinvq_data.h:10344
avio.h
copy_tb
int copy_tb
Definition: ffmpeg_opt.c:69
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AV_CODEC_PROP_FIELDS
#define AV_CODEC_PROP_FIELDS
Video codec supports separate coding of fields in interlaced frames.
Definition: codec_desc.h:97
AVStreamGroup::iamf_audio_element
struct AVIAMFAudioElement * iamf_audio_element
Definition: avformat.h:1167
ff_format_io_close
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: avformat.c:959
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:826
frame.h
AV_DISPOSITION_HEARING_IMPAIRED
#define AV_DISPOSITION_HEARING_IMPAIRED
The stream is intended for hearing impaired audiences.
Definition: avformat.h:658
AVStreamGroup::lcevc
struct AVStreamGroupLCEVC * lcevc
Definition: avformat.h:1170
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:223
AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT
@ AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT
Definition: avformat.h:1125
AVStreamGroup::streams
AVStream ** streams
A list of streams in the group.
Definition: avformat.h:1201
AVStreamGroupTileGrid::offsets
struct AVStreamGroupTileGrid::@365 * offsets
An nb_tiles sized array of offsets in pixels from the topleft edge of the canvas, indicating where ea...
AVStreamGroup::iamf_mix_presentation
struct AVIAMFMixPresentation * iamf_mix_presentation
Definition: avformat.h:1168
avformat_internal.h
FFStream::probe_data
AVProbeData probe_data
Definition: internal.h:309
FFStreamInfo::duration_error
double(* duration_error)[2][MAX_STD_TIMEBASES]
Definition: demux.h:149
AVStreamGroupTileGrid::nb_coded_side_data
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition: avformat.h:1095
ff_is_intra_only
int ff_is_intra_only(enum AVCodecID id)
Definition: avformat.c:941
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
AVOutputFormat
Definition: avformat.h:509
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVCodecParameters::height
int height
Definition: codec_par.h:135
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:205
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_find_default_stream_index
int av_find_default_stream_index(AVFormatContext *s)
Definition: avformat.c:420
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1224
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
demux.h
avcodec.h
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:817
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:531
AV_DISPOSITION_VISUAL_IMPAIRED
#define AV_DISPOSITION_VISUAL_IMPAIRED
The stream is intended for visually impaired audiences.
Definition: avformat.h:662
tag
uint32_t tag
Definition: movenc.c:1879
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:760
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:748
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:763
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:264
AVStreamGroup::metadata
AVDictionary * metadata
Metadata that applies to the whole group.
Definition: avformat.h:1181
avformat.h
id
enum AVCodecID id
Definition: dts2pts.c:367
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
U
#define U(x)
Definition: vpx_arith.h:37
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
AVStreamGroup
Definition: avformat.h:1134
AVCodecContext
main external API structure.
Definition: avcodec.h:451
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:754
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:138
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:129
av_match_name
int av_match_name(const char *name, const char *names)
Match instances of a name in a comma-separated list of names.
Definition: avstring.c:345
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: avformat.c:149
ff_fc_internal
static av_always_inline FormatContextInternal * ff_fc_internal(AVFormatContext *s)
Definition: avformat_internal.h:107
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:914
AVCodecContext::ticks_per_frame
attribute_deprecated int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:590
AVPacketSideDataType
AVPacketSideDataType
Definition: packet.h:41
FFStream::info
struct FFStreamInfo * info
Stream information used internally by avformat_find_stream_info()
Definition: internal.h:186
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
FFStream::index_entries
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: internal.h:188
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
AVERROR_DECODER_NOT_FOUND
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
Definition: error.h:54
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
AVStreamGroup::type
enum AVStreamGroupParamsType type
Group type.
Definition: avformat.h:1161
packet_internal.h
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:92
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVDictionaryEntry
Definition: dict.h:89
FFStream::extract_extradata
struct FFStream::@396 extract_extradata
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
ff_stream_clone
AVStream * ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src)
Create a new stream and copy to it all parameters from a source stream, with the exception of the ind...
Definition: avformat.c:318
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
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:237
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:97
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
FFStream::parser
struct AVCodecParserContext * parser
Definition: internal.h:326
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3774
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:923
codec_desc.h
AVStreamGroup::priv_data
void * priv_data
Definition: avformat.h:1140
ff_format_set_url
void ff_format_set_url(AVFormatContext *s, char *url)
Set AVFormatContext url field to the provided pointer.
Definition: avformat.c:952
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
avcodec_parameters_copy
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: codec_par.c:106
av_parser_close
void av_parser_close(AVCodecParserContext *s)
Definition: parser.c:193
mux.h