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/intreadwrite.h"
27 #include "libavutil/mem.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/pixfmt.h"
30 #include "libavutil/samplefmt.h"
31 #include "libavcodec/avcodec.h"
32 #include "libavcodec/bsf.h"
33 #include "libavcodec/codec_desc.h"
35 #include "avformat.h"
36 #include "avio.h"
37 #include "demux.h"
38 #include "internal.h"
39 
41 {
42  AVStream *st = *pst;
43  FFStream *const sti = ffstream(st);
44 
45  if (!st)
46  return;
47 
48  for (int i = 0; i < st->nb_side_data; i++)
49  av_freep(&st->side_data[i].data);
50  av_freep(&st->side_data);
51 
52  if (st->attached_pic.data)
54 
55  av_parser_close(sti->parser);
57  av_bsf_free(&sti->bsfc);
58  av_freep(&sti->priv_pts);
59  av_freep(&sti->index_entries);
60  av_freep(&sti->probe_data.buf);
61 
63 
64  if (sti->info) {
66  av_freep(&sti->info);
67  }
68 
69  av_dict_free(&st->metadata);
71  av_freep(&st->priv_data);
72 
73  av_freep(pst);
74 }
75 
77 {
78  av_assert0(s->nb_streams>0);
79  av_assert0(s->streams[ s->nb_streams - 1 ] == st);
80 
81  ff_free_stream(&s->streams[ --s->nb_streams ]);
82 }
83 
84 /* XXX: suppress the packet queue */
86 {
87  FFFormatContext *const si = ffformatcontext(s);
91 
92  si->raw_packet_buffer_size = 0;
93 }
94 
96 {
97  FFFormatContext *si;
98 
99  if (!s)
100  return;
101  si = ffformatcontext(s);
102 
103  if (s->oformat && s->oformat->deinit && si->initialized)
104  s->oformat->deinit(s);
105 
106  av_opt_free(s);
107  if (s->iformat && s->iformat->priv_class && s->priv_data)
108  av_opt_free(s->priv_data);
109  if (s->oformat && s->oformat->priv_class && s->priv_data)
110  av_opt_free(s->priv_data);
111 
112  for (unsigned i = 0; i < s->nb_streams; i++)
113  ff_free_stream(&s->streams[i]);
114  s->nb_streams = 0;
115 
116  for (unsigned i = 0; i < s->nb_programs; i++) {
117  av_dict_free(&s->programs[i]->metadata);
118  av_freep(&s->programs[i]->stream_index);
119  av_freep(&s->programs[i]);
120  }
121  s->nb_programs = 0;
122 
123  av_freep(&s->programs);
124  av_freep(&s->priv_data);
125  while (s->nb_chapters--) {
126  av_dict_free(&s->chapters[s->nb_chapters]->metadata);
127  av_freep(&s->chapters[s->nb_chapters]);
128  }
129  av_freep(&s->chapters);
130  av_dict_free(&s->metadata);
131  av_dict_free(&si->id3v2_meta);
132  av_packet_free(&si->pkt);
134  av_freep(&s->streams);
136  av_freep(&s->url);
137  av_free(s);
138 }
139 
141  enum AVPacketSideDataType type, size_t *size)
142 {
143  for (int i = 0; i < st->nb_side_data; i++) {
144  if (st->side_data[i].type == type) {
145  if (size)
146  *size = st->side_data[i].size;
147  return st->side_data[i].data;
148  }
149  }
150  if (size)
151  *size = 0;
152  return NULL;
153 }
154 
156  uint8_t *data, size_t size)
157 {
158  AVPacketSideData *sd, *tmp;
159 
160  for (int i = 0; i < st->nb_side_data; i++) {
161  sd = &st->side_data[i];
162 
163  if (sd->type == type) {
164  av_freep(&sd->data);
165  sd->data = data;
166  sd->size = size;
167  return 0;
168  }
169  }
170 
171  if (st->nb_side_data + 1U > FFMIN(INT_MAX, SIZE_MAX / sizeof(*tmp)))
172  return AVERROR(ERANGE);
173 
174  tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp));
175  if (!tmp) {
176  return AVERROR(ENOMEM);
177  }
178 
179  st->side_data = tmp;
180  st->nb_side_data++;
181 
182  sd = &st->side_data[st->nb_side_data - 1];
183  sd->type = type;
184  sd->data = data;
185  sd->size = size;
186 
187  return 0;
188 }
189 
191  size_t size)
192 {
193  int ret;
194  uint8_t *data = av_malloc(size);
195 
196  if (!data)
197  return NULL;
198 
200  if (ret < 0) {
201  av_freep(&data);
202  return NULL;
203  }
204 
205  return data;
206 }
207 
209 {
210  /* Free existing side data*/
211  for (int i = 0; i < dst->nb_side_data; i++)
212  av_free(dst->side_data[i].data);
213  av_freep(&dst->side_data);
214  dst->nb_side_data = 0;
215 
216  /* Copy side data if present */
217  if (src->nb_side_data) {
218  dst->side_data = av_calloc(src->nb_side_data,
219  sizeof(*dst->side_data));
220  if (!dst->side_data)
221  return AVERROR(ENOMEM);
222  dst->nb_side_data = src->nb_side_data;
223 
224  for (int i = 0; i < src->nb_side_data; i++) {
225  uint8_t *data = av_memdup(src->side_data[i].data,
226  src->side_data[i].size);
227  if (!data)
228  return AVERROR(ENOMEM);
229  dst->side_data[i].type = src->side_data[i].type;
230  dst->side_data[i].size = src->side_data[i].size;
231  dst->side_data[i].data = data;
232  }
233  }
234 
235  return 0;
236 }
237 
238 /**
239  * Copy all stream parameters from source to destination stream, with the
240  * exception of the index field, which is usually set by avformat_new_stream().
241  *
242  * @param dst pointer to destination AVStream
243  * @param src pointer to source AVStream
244  * @return >=0 on success, AVERROR code on error
245  */
246 static int stream_params_copy(AVStream *dst, const AVStream *src)
247 {
248  int ret;
249 
250  dst->id = src->id;
251  dst->time_base = src->time_base;
252  dst->start_time = src->start_time;
253  dst->duration = src->duration;
254  dst->nb_frames = src->nb_frames;
255  dst->disposition = src->disposition;
256  dst->discard = src->discard;
257  dst->sample_aspect_ratio = src->sample_aspect_ratio;
258  dst->avg_frame_rate = src->avg_frame_rate;
259  dst->event_flags = src->event_flags;
260  dst->r_frame_rate = src->r_frame_rate;
261  dst->pts_wrap_bits = src->pts_wrap_bits;
262 
263  av_dict_free(&dst->metadata);
264  ret = av_dict_copy(&dst->metadata, src->metadata, 0);
265  if (ret < 0)
266  return ret;
267 
268  ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
269  if (ret < 0)
270  return ret;
271 
273  if (ret < 0)
274  return ret;
275 
277  if (src->attached_pic.data) {
278  ret = av_packet_ref(&dst->attached_pic, &src->attached_pic);
279  if (ret < 0)
280  return ret;
281  }
282 
283  return 0;
284 }
285 
287 {
288  AVStream *st;
289  int ret;
290 
291  st = avformat_new_stream(dst_ctx, NULL);
292  if (!st)
293  return NULL;
294 
295  ret = stream_params_copy(st, src);
296  if (ret < 0) {
297  ff_remove_stream(dst_ctx, st);
298  return NULL;
299  }
300 
301  return st;
302 }
303 
305 {
307  int ret;
308 
309  av_log(ac, AV_LOG_TRACE, "new_program: id=0x%04x\n", id);
310 
311  for (unsigned i = 0; i < ac->nb_programs; i++)
312  if (ac->programs[i]->id == id)
313  program = ac->programs[i];
314 
315  if (!program) {
316  program = av_mallocz(sizeof(*program));
317  if (!program)
318  return NULL;
320  if (ret < 0) {
321  av_free(program);
322  return NULL;
323  }
324  program->discard = AVDISCARD_NONE;
325  program->pmt_version = -1;
326  program->id = id;
327  program->pts_wrap_reference = AV_NOPTS_VALUE;
328  program->pts_wrap_behavior = AV_PTS_WRAP_IGNORE;
329  program->start_time =
330  program->end_time = AV_NOPTS_VALUE;
331  }
332  return program;
333 }
334 
335 void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
336 {
338  void *tmp;
339 
340  if (idx >= ac->nb_streams) {
341  av_log(ac, AV_LOG_ERROR, "stream index %d is not valid\n", idx);
342  return;
343  }
344 
345  for (unsigned i = 0; i < ac->nb_programs; i++) {
346  if (ac->programs[i]->id != progid)
347  continue;
348  program = ac->programs[i];
349  for (unsigned j = 0; j < program->nb_stream_indexes; j++)
350  if (program->stream_index[j] == idx)
351  return;
352 
353  tmp = av_realloc_array(program->stream_index, program->nb_stream_indexes+1, sizeof(unsigned int));
354  if (!tmp)
355  return;
356  program->stream_index = tmp;
357  program->stream_index[program->nb_stream_indexes++] = idx;
358  return;
359  }
360 }
361 
363 {
364  for (unsigned i = 0; i < ic->nb_programs; i++) {
365  if (ic->programs[i] == last) {
366  last = NULL;
367  } else {
368  if (!last)
369  for (unsigned j = 0; j < ic->programs[i]->nb_stream_indexes; j++)
370  if (ic->programs[i]->stream_index[j] == s)
371  return ic->programs[i];
372  }
373  }
374  return NULL;
375 }
376 
378 {
379  int best_stream = 0;
380  int best_score = INT_MIN;
381 
382  if (s->nb_streams <= 0)
383  return -1;
384  for (unsigned i = 0; i < s->nb_streams; i++) {
385  const AVStream *const st = s->streams[i];
386  const FFStream *const sti = cffstream(st);
387  int score = 0;
388  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
390  score -= 400;
391  if (st->codecpar->width && st->codecpar->height)
392  score += 50;
393  score+= 25;
394  }
395  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
396  if (st->codecpar->sample_rate)
397  score += 50;
398  }
399  if (sti->codec_info_nb_frames)
400  score += 12;
401 
402  if (st->discard != AVDISCARD_ALL)
403  score += 200;
404 
405  if (score > best_score) {
406  best_score = score;
407  best_stream = i;
408  }
409  }
410  return best_stream;
411 }
412 
414  int wanted_stream_nb, int related_stream,
415  const AVCodec **decoder_ret, int flags)
416 {
417  int nb_streams = ic->nb_streams;
419  int best_count = -1, best_multiframe = -1, best_disposition = -1;
420  int count, multiframe, disposition;
421  int64_t best_bitrate = -1;
422  int64_t bitrate;
423  unsigned *program = NULL;
424  const AVCodec *decoder = NULL, *best_decoder = NULL;
425 
426  if (related_stream >= 0 && wanted_stream_nb < 0) {
427  AVProgram *p = av_find_program_from_stream(ic, NULL, related_stream);
428  if (p) {
429  program = p->stream_index;
431  }
432  }
433  for (unsigned i = 0; i < nb_streams; i++) {
434  int real_stream_index = program ? program[i] : i;
435  AVStream *st = ic->streams[real_stream_index];
436  AVCodecParameters *par = st->codecpar;
437  if (par->codec_type != type)
438  continue;
439  if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
440  continue;
441  if (type == AVMEDIA_TYPE_AUDIO && !(par->ch_layout.nb_channels && par->sample_rate))
442  continue;
443  if (decoder_ret) {
444  decoder = ff_find_decoder(ic, st, par->codec_id);
445  if (!decoder) {
446  if (ret < 0)
448  continue;
449  }
450  }
452  + !! (st->disposition & AV_DISPOSITION_DEFAULT);
453  count = ffstream(st)->codec_info_nb_frames;
454  bitrate = par->bit_rate;
455  multiframe = FFMIN(5, count);
456  if ((best_disposition > disposition) ||
457  (best_disposition == disposition && best_multiframe > multiframe) ||
458  (best_disposition == disposition && best_multiframe == multiframe && best_bitrate > bitrate) ||
459  (best_disposition == disposition && best_multiframe == multiframe && best_bitrate == bitrate && best_count >= count))
460  continue;
461  best_disposition = disposition;
462  best_count = count;
463  best_bitrate = bitrate;
464  best_multiframe = multiframe;
465  ret = real_stream_index;
466  best_decoder = decoder;
467  if (program && i == nb_streams - 1 && ret < 0) {
468  program = NULL;
469  nb_streams = ic->nb_streams;
470  /* no related stream found, try again with everything */
471  i = 0;
472  }
473  }
474  if (decoder_ret)
475  *decoder_ret = best_decoder;
476  return ret;
477 }
478 
479 /**
480  * Matches a stream specifier (but ignores requested index).
481  *
482  * @param indexptr set to point to the requested stream index if there is one
483  *
484  * @return <0 on error
485  * 0 if st is NOT a matching stream
486  * >0 if st is a matching stream
487  */
488 static int match_stream_specifier(const AVFormatContext *s, const AVStream *st,
489  const char *spec, const char **indexptr,
490  const AVProgram **p)
491 {
492  int match = 1; /* Stores if the specifier matches so far. */
493  while (*spec) {
494  if (*spec <= '9' && *spec >= '0') { /* opt:index */
495  if (indexptr)
496  *indexptr = spec;
497  return match;
498  } else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||
499  *spec == 't' || *spec == 'V') { /* opt:[vasdtV] */
500  enum AVMediaType type;
501  int nopic = 0;
502 
503  switch (*spec++) {
504  case 'v': type = AVMEDIA_TYPE_VIDEO; break;
505  case 'a': type = AVMEDIA_TYPE_AUDIO; break;
506  case 's': type = AVMEDIA_TYPE_SUBTITLE; break;
507  case 'd': type = AVMEDIA_TYPE_DATA; break;
508  case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
509  case 'V': type = AVMEDIA_TYPE_VIDEO; nopic = 1; break;
510  default: av_assert0(0);
511  }
512  if (*spec && *spec++ != ':') /* If we are not at the end, then another specifier must follow. */
513  return AVERROR(EINVAL);
514 
515  if (type != st->codecpar->codec_type)
516  match = 0;
517  if (nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC))
518  match = 0;
519  } else if (*spec == 'p' && *(spec + 1) == ':') {
520  int prog_id;
521  int found = 0;
522  char *endptr;
523  spec += 2;
524  prog_id = strtol(spec, &endptr, 0);
525  /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
526  if (spec == endptr || (*endptr && *endptr++ != ':'))
527  return AVERROR(EINVAL);
528  spec = endptr;
529  if (match) {
530  for (unsigned i = 0; i < s->nb_programs; i++) {
531  if (s->programs[i]->id != prog_id)
532  continue;
533 
534  for (unsigned j = 0; j < s->programs[i]->nb_stream_indexes; j++) {
535  if (st->index == s->programs[i]->stream_index[j]) {
536  found = 1;
537  if (p)
538  *p = s->programs[i];
539  i = s->nb_programs;
540  break;
541  }
542  }
543  }
544  }
545  if (!found)
546  match = 0;
547  } else if (*spec == '#' ||
548  (*spec == 'i' && *(spec + 1) == ':')) {
549  int stream_id;
550  char *endptr;
551  spec += 1 + (*spec == 'i');
552  stream_id = strtol(spec, &endptr, 0);
553  if (spec == endptr || *endptr) /* Disallow empty id and make sure we are at the end. */
554  return AVERROR(EINVAL);
555  return match && (stream_id == st->id);
556  } else if (*spec == 'm' && *(spec + 1) == ':') {
557  const AVDictionaryEntry *tag;
558  char *key, *val;
559  int ret;
560 
561  if (match) {
562  spec += 2;
563  val = strchr(spec, ':');
564 
565  key = val ? av_strndup(spec, val - spec) : av_strdup(spec);
566  if (!key)
567  return AVERROR(ENOMEM);
568 
569  tag = av_dict_get(st->metadata, key, NULL, 0);
570  if (tag) {
571  if (!val || !strcmp(tag->value, val + 1))
572  ret = 1;
573  else
574  ret = 0;
575  } else
576  ret = 0;
577 
578  av_freep(&key);
579  }
580  return match && ret;
581  } else if (*spec == 'u' && *(spec + 1) == '\0') {
582  const AVCodecParameters *par = st->codecpar;
583  int val;
584  switch (par->codec_type) {
585  case AVMEDIA_TYPE_AUDIO:
586  val = par->sample_rate && par->ch_layout.nb_channels;
587  if (par->format == AV_SAMPLE_FMT_NONE)
588  return 0;
589  break;
590  case AVMEDIA_TYPE_VIDEO:
591  val = par->width && par->height;
592  if (par->format == AV_PIX_FMT_NONE)
593  return 0;
594  break;
596  val = 0;
597  break;
598  default:
599  val = 1;
600  break;
601  }
602  return match && (par->codec_id != AV_CODEC_ID_NONE && val != 0);
603  } else {
604  return AVERROR(EINVAL);
605  }
606  }
607 
608  return match;
609 }
610 
612  const char *spec)
613 {
614  int ret, index;
615  char *endptr;
616  const char *indexptr = NULL;
617  const AVProgram *p = NULL;
618  int nb_streams;
619 
620  ret = match_stream_specifier(s, st, spec, &indexptr, &p);
621  if (ret < 0)
622  goto error;
623 
624  if (!indexptr)
625  return ret;
626 
627  index = strtol(indexptr, &endptr, 0);
628  if (*endptr) { /* We can't have anything after the requested index. */
629  ret = AVERROR(EINVAL);
630  goto error;
631  }
632 
633  /* This is not really needed but saves us a loop for simple stream index specifiers. */
634  if (spec == indexptr)
635  return (index == st->index);
636 
637  /* If we requested a matching stream index, we have to ensure st is that. */
638  nb_streams = p ? p->nb_stream_indexes : s->nb_streams;
639  for (int i = 0; i < nb_streams && index >= 0; i++) {
640  const AVStream *candidate = s->streams[p ? p->stream_index[i] : i];
641  ret = match_stream_specifier(s, candidate, spec, NULL, NULL);
642  if (ret < 0)
643  goto error;
644  if (ret > 0 && index-- == 0 && st == candidate)
645  return 1;
646  }
647  return 0;
648 
649 error:
650  if (ret == AVERROR(EINVAL))
651  av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
652  return ret;
653 }
654 
656 {
657  AVRational undef = {0, 1};
658  AVRational stream_sample_aspect_ratio = stream ? stream->sample_aspect_ratio : undef;
659  AVRational codec_sample_aspect_ratio = stream && stream->codecpar ? stream->codecpar->sample_aspect_ratio : undef;
660  AVRational frame_sample_aspect_ratio = frame ? frame->sample_aspect_ratio : codec_sample_aspect_ratio;
661 
662  av_reduce(&stream_sample_aspect_ratio.num, &stream_sample_aspect_ratio.den,
663  stream_sample_aspect_ratio.num, stream_sample_aspect_ratio.den, INT_MAX);
664  if (stream_sample_aspect_ratio.num <= 0 || stream_sample_aspect_ratio.den <= 0)
665  stream_sample_aspect_ratio = undef;
666 
667  av_reduce(&frame_sample_aspect_ratio.num, &frame_sample_aspect_ratio.den,
668  frame_sample_aspect_ratio.num, frame_sample_aspect_ratio.den, INT_MAX);
669  if (frame_sample_aspect_ratio.num <= 0 || frame_sample_aspect_ratio.den <= 0)
670  frame_sample_aspect_ratio = undef;
671 
672  if (stream_sample_aspect_ratio.num)
673  return stream_sample_aspect_ratio;
674  else
675  return frame_sample_aspect_ratio;
676 }
677 
679 {
680  AVRational fr = st->r_frame_rate;
681  AVCodecContext *const avctx = ffstream(st)->avctx;
682  AVRational codec_fr = avctx->framerate;
683  AVRational avg_fr = st->avg_frame_rate;
684 
685  if (avg_fr.num > 0 && avg_fr.den > 0 && fr.num > 0 && fr.den > 0 &&
686  av_q2d(avg_fr) < 70 && av_q2d(fr) > 210) {
687  fr = avg_fr;
688  }
689 
690  if (avctx->ticks_per_frame > 1) {
691  if ( codec_fr.num > 0 && codec_fr.den > 0 &&
692  (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))
693  fr = codec_fr;
694  }
695 
696  return fr;
697 }
698 
700  AVStream *ost, const AVStream *ist,
702 {
703  const AVCodecContext *const dec_ctx = cffstream(ist)->avctx;
704  AVCodecContext *const enc_ctx = ffstream(ost)->avctx;
705 
706  enc_ctx->time_base = ist->time_base;
707  /*
708  * Avi is a special case here because it supports variable fps but
709  * having the fps and timebase differe significantly adds quite some
710  * overhead
711  */
712  if (!strcmp(ofmt->name, "avi")) {
713 #if FF_API_R_FRAME_RATE
714  if (copy_tb == AVFMT_TBCF_AUTO && ist->r_frame_rate.num
715  && av_q2d(ist->r_frame_rate) >= av_q2d(ist->avg_frame_rate)
716  && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(ist->time_base)
717  && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(dec_ctx->time_base)
718  && av_q2d(ist->time_base) < 1.0/500 && av_q2d(dec_ctx->time_base) < 1.0/500
719  || copy_tb == AVFMT_TBCF_R_FRAMERATE) {
720  enc_ctx->time_base.num = ist->r_frame_rate.den;
721  enc_ctx->time_base.den = 2*ist->r_frame_rate.num;
722  enc_ctx->ticks_per_frame = 2;
723  } else
724 #endif
726  && av_q2d(ist->time_base) < 1.0/500
727  || copy_tb == AVFMT_TBCF_DECODER) {
728  enc_ctx->time_base = dec_ctx->time_base;
729  enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
730  enc_ctx->time_base.den *= 2;
731  enc_ctx->ticks_per_frame = 2;
732  }
733  } else if (!(ofmt->flags & AVFMT_VARIABLE_FPS)
734  && !av_match_name(ofmt->name, "mov,mp4,3gp,3g2,psp,ipod,ismv,f4v")) {
737  && av_q2d(ist->time_base) < 1.0/500
738  || copy_tb == AVFMT_TBCF_DECODER) {
739  enc_ctx->time_base = dec_ctx->time_base;
740  enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
741  }
742  }
743 
744  if ((enc_ctx->codec_tag == AV_RL32("tmcd") || ost->codecpar->codec_tag == AV_RL32("tmcd"))
746  && dec_ctx->time_base.num > 0
747  && 121LL*dec_ctx->time_base.num > dec_ctx->time_base.den) {
748  enc_ctx->time_base = dec_ctx->time_base;
749  }
750 
751  av_reduce(&enc_ctx->time_base.num, &enc_ctx->time_base.den,
752  enc_ctx->time_base.num, enc_ctx->time_base.den, INT_MAX);
753 
754  return 0;
755 }
756 
758 {
759  // See avformat_transfer_internal_stream_timing_info() TODO.
760  return cffstream(st)->avctx->time_base;
761 }
762 
763 void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits,
764  unsigned int pts_num, unsigned int pts_den)
765 {
766  FFStream *const sti = ffstream(st);
767  AVRational new_tb;
768  if (av_reduce(&new_tb.num, &new_tb.den, pts_num, pts_den, INT_MAX)) {
769  if (new_tb.num != pts_num)
771  "st:%d removing common factor %d from timebase\n",
772  st->index, pts_num / new_tb.num);
773  } else
775  "st:%d has too large timebase, reducing\n", st->index);
776 
777  if (new_tb.num <= 0 || new_tb.den <= 0) {
779  "Ignoring attempt to set invalid timebase %d/%d for st:%d\n",
780  new_tb.num, new_tb.den,
781  st->index);
782  return;
783  }
784  st->time_base = new_tb;
785  sti->avctx->pkt_timebase = new_tb;
786  st->pts_wrap_bits = pts_wrap_bits;
787 }
788 
790  enum AVCodecID codec_id)
791 {
792  switch (st->codecpar->codec_type) {
793  case AVMEDIA_TYPE_VIDEO:
794  if (s->video_codec) return s->video_codec;
795  break;
796  case AVMEDIA_TYPE_AUDIO:
797  if (s->audio_codec) return s->audio_codec;
798  break;
800  if (s->subtitle_codec) return s->subtitle_codec;
801  break;
802  }
803 
805 }
806 
808 {
809  av_assert0(!dst->codec_whitelist &&
810  !dst->format_whitelist &&
811  !dst->protocol_whitelist &&
812  !dst->protocol_blacklist);
813  dst-> codec_whitelist = av_strdup(src->codec_whitelist);
814  dst->format_whitelist = av_strdup(src->format_whitelist);
815  dst->protocol_whitelist = av_strdup(src->protocol_whitelist);
816  dst->protocol_blacklist = av_strdup(src->protocol_blacklist);
817  if ( (src-> codec_whitelist && !dst-> codec_whitelist)
818  || (src-> format_whitelist && !dst-> format_whitelist)
819  || (src->protocol_whitelist && !dst->protocol_whitelist)
820  || (src->protocol_blacklist && !dst->protocol_blacklist)) {
821  av_log(dst, AV_LOG_ERROR, "Failed to duplicate black/whitelist\n");
822  return AVERROR(ENOMEM);
823  }
824  return 0;
825 }
826 
828 {
830  if (!d)
831  return 0;
832  if ((d->type == AVMEDIA_TYPE_VIDEO || d->type == AVMEDIA_TYPE_AUDIO) &&
833  !(d->props & AV_CODEC_PROP_INTRA_ONLY))
834  return 0;
835  return 1;
836 }
837 
839 {
840  av_assert0(url);
841  av_freep(&s->url);
842  s->url = url;
843 }
844 
846 {
847  int ret = 0;
848  if (*pb) {
849  if (s->io_close == ff_format_io_close_default || s->io_close == NULL)
850  ret = s->io_close2(s, *pb);
851  else
852  s->io_close(s, *pb);
853  }
854  *pb = NULL;
855  return ret;
856 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:422
AVCodec
AVCodec.
Definition: codec.h:204
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
FFStream::extract_extradata
struct FFStream::@282 extract_extradata
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
program
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C program
Definition: undefined.txt:6
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
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: options.c:237
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:58
AVProgram::nb_stream_indexes
unsigned int nb_stream_indexes
Definition: avformat.h:1145
FFStream::bsfc
struct AVBSFContext * bsfc
bitstream filter to run on stream
Definition: internal.h:213
ff_find_decoder
const AVCodec * ff_find_decoder(AVFormatContext *s, const AVStream *st, enum AVCodecID codec_id)
Definition: avformat.c:789
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:54
FFStream::bsf
struct AVBSFContext * bsf
Definition: internal.h:233
ffformatcontext
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition: internal.h:191
AVStream::priv_data
void * priv_data
Definition: avformat.h:964
AVFMT_VARIABLE_FPS
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:484
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:879
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:1010
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:362
av_div_q
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition: rational.c:88
AVFormatContext::protocol_blacklist
char * protocol_blacklist
',' separated list of disallowed protocols.
Definition: avformat.h:1789
AVFMT_TBCF_DECODER
@ AVFMT_TBCF_DECODER
Definition: avformat.h:2902
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:826
AVFMT_TBCF_AUTO
@ AVFMT_TBCF_AUTO
Definition: avformat.h:2901
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
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:1284
AVPacketSideData
Definition: packet.h:315
AVPacket::data
uint8_t * data
Definition: packet.h:374
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:1028
data
const char data[16]
Definition: mxf.c:146
FFFormatContext::initialized
int initialized
Whether or not avformat_init_output has already been called.
Definition: internal.h:163
AVFormatContext::programs
AVProgram ** programs
Definition: avformat.h:1385
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:66
cffstream
static const av_always_inline FFStream * cffstream(const AVStream *st)
Definition: internal.h:418
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:311
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:53
ost
static AVStream * ost
Definition: vaapi_transcode.c:45
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: avpacket.c:73
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:312
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)
Find the "best" stream in the file.
Definition: avformat.c:413
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:1735
AVPacketSideData::size
size_t size
Definition: packet.h:317
ff_remove_stream
void ff_remove_stream(AVFormatContext *s, AVStream *st)
Remove a stream from its AVFormatContext and free it.
Definition: avformat.c:76
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:763
bsf.h
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:413
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:246
samplefmt.h
FFStream::avctx
struct AVCodecContext * avctx
The codec context used by avformat_find_stream_info, the parser, etc.
Definition: internal.h:223
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: defs.h:70
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:304
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:998
AV_PTS_WRAP_IGNORE
#define AV_PTS_WRAP_IGNORE
Options for behavior on timestamp wrap detection.
Definition: avformat.h:937
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
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:1037
FFStream::priv_pts
FFFrac * priv_pts
Definition: internal.h:244
avassert.h
AVFormatContext::format_whitelist
char * format_whitelist
',' separated list of allowed demuxers.
Definition: avformat.h:1669
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:655
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AVProgram::id
int id
Definition: avformat.h:1141
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
FFFormatContext::parse_queue
PacketList parse_queue
Packets split by the parser get queued here.
Definition: internal.h:120
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:256
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:105
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:225
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:138
AVFormatContext::nb_programs
unsigned int nb_programs
Definition: avformat.h:1384
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:455
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:128
AVCodecContext::ticks_per_frame
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:530
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:37
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
AVPacketSideData::data
uint8_t * data
Definition: packet.h:316
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:392
nb_streams
static int nb_streams
Definition: ffprobe.c:308
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:388
key
const char * key
Definition: hwcontext_opencl.c:174
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
FFFormatContext
Definition: internal.h:71
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:76
AVFormatContext
Format I/O context.
Definition: avformat.h:1216
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:1108
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:978
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:335
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:63
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
AVFormatContext::protocol_whitelist
char * protocol_whitelist
',' separated list of allowed protocols.
Definition: avformat.h:1754
ff_copy_whiteblacklists
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
Copies the whilelists from one context to the other.
Definition: avformat.c:807
AVPacketSideData::type
enum AVPacketSideDataType type
Definition: packet.h:318
av_stream_add_side_data
int av_stream_add_side_data(AVStream *st, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as stream side data.
Definition: avformat.c:155
AVProgram::stream_index
unsigned int * stream_index
Definition: avformat.h:1144
match_stream_specifier
static int match_stream_specifier(const AVFormatContext *s, const AVStream *st, const char *spec, const char **indexptr, const AVProgram **p)
Matches a stream specifier (but ignores requested index).
Definition: avformat.c:488
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:1019
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1719
av_packet_ref
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:430
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:213
index
int index
Definition: gxfenc.c:89
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:178
AVStream::nb_frames
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:1000
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:951
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1272
FFFormatContext::id3v2_meta
AVDictionary * id3v2_meta
ID3v2 tag useful for MP3 demuxing.
Definition: internal.h:173
AVOutputFormat::flags
int flags
can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:529
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:521
AVIOContext
Bytestream IO Context.
Definition: avio.h:166
AVMediaType
AVMediaType
Definition: avutil.h:199
avformat_match_stream_specifier
int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the stream st contained in s is matched by the stream specifier spec.
Definition: avformat.c:611
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:134
avpriv_packet_list_free
void avpriv_packet_list_free(PacketList *pkt_buf)
Wipe the list and unref all the packets in it.
Definition: avpacket.c:589
FFStream
Definition: internal.h:196
ff_free_stream
void ff_free_stream(AVStream **pst)
Frees a stream without modifying the corresponding AVFormatContext.
Definition: avformat.c:40
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
Definition: avcodec.h:1749
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
ff_format_io_close_default
void ff_format_io_close_default(AVFormatContext *s, AVIOContext *pb)
Definition: options.c:154
size
int size
Definition: twinvq_data.h:10344
avio.h
copy_tb
int copy_tb
Definition: ffmpeg_opt.c:78
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVStream::event_flags
int event_flags
Flags indicating events happening on the stream, a combination of AVSTREAM_EVENT_FLAG_*.
Definition: avformat.h:1074
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:678
av_stream_get_codec_timebase
AVRational av_stream_get_codec_timebase(const AVStream *st)
Get the internal codec timebase from a stream.
Definition: avformat.c:757
ff_format_io_close
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: avformat.c:845
AVTimebaseSource
AVTimebaseSource
Definition: avformat.h:2900
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:1017
AV_DISPOSITION_HEARING_IMPAIRED
#define AV_DISPOSITION_HEARING_IMPAIRED
The stream is intended for hearing impaired audiences.
Definition: avformat.h:863
AVPacketSideDataType
AVPacketSideDataType
Definition: packet.h:41
FFFormatContext::raw_packet_buffer_size
int raw_packet_buffer_size
Sum of the size of packets in raw_packet_buffer, in bytes.
Definition: internal.h:145
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
bitrate
int64_t bitrate
Definition: h264_levels.c:131
FFStream::probe_data
AVProbeData probe_data
Definition: internal.h:370
AVStream::side_data
AVPacketSideData * side_data
An array of side data that applies to the whole stream (i.e.
Definition: avformat.h:1057
FFStreamInfo::duration_error
double(* duration_error)[2][MAX_STD_TIMEBASES]
Definition: demux.h:35
FFFormatContext::raw_packet_buffer
PacketList raw_packet_buffer
Raw packets from the demuxer, prior to parsing and decoding.
Definition: internal.h:116
ff_is_intra_only
int ff_is_intra_only(enum AVCodecID id)
Definition: avformat.c:827
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:269
AVCodecParameters::height
int height
Definition: codec_par.h:129
AVFormatContext::codec_whitelist
char * codec_whitelist
',' separated list of allowed decoders.
Definition: avformat.h:1661
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:377
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:264
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1140
demux.h
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:272
avcodec.h
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:1008
AV_DISPOSITION_VISUAL_IMPAIRED
#define AV_DISPOSITION_VISUAL_IMPAIRED
The stream is intended for visually impaired audiences.
Definition: avformat.h:867
tag
uint32_t tag
Definition: movenc.c:1647
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:962
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:948
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
AVStream::nb_side_data
int nb_side_data
The number of elements in the AVStream.side_data array.
Definition: avformat.h:1061
avformat.h
av_stream_get_side_data
uint8_t * av_stream_get_side_data(const AVStream *st, enum AVPacketSideDataType type, size_t *size)
Get side information from stream.
Definition: avformat.c:140
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
id
enum AVCodecID id
Definition: dts2pts_bsf.c:362
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:323
AVCodecContext
main external API structure.
Definition: avcodec.h:398
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:956
avformat_transfer_internal_stream_timing_info
int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, AVStream *ost, const AVStream *ist, enum AVTimebaseSource copy_tb)
Transfer internal timing information from one stream to another.
Definition: avformat.c:699
channel_layout.h
ff_stream_side_data_copy
int ff_stream_side_data_copy(AVStream *dst, const AVStream *src)
Copy side data from source to destination stream.
Definition: avformat.c:208
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:65
ff_flush_packet_queue
void ff_flush_packet_queue(AVFormatContext *s)
Definition: avformat.c:85
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:356
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: avformat.c:95
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:1097
FFStream::info
struct FFStreamInfo * info
Stream information used internally by avformat_find_stream_info()
Definition: internal.h:249
FFStream::index_entries
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: internal.h:251
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:280
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
packet_internal.h
FFFormatContext::pkt
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
Definition: internal.h:141
AVCodecParameters::format
int format
Definition: codec_par.h:86
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:423
AVDictionaryEntry
Definition: dict.h:89
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:62
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:286
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
av_dict_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:237
av_stream_new_side_data
uint8_t * av_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type, size_t size)
Allocate new information from stream.
Definition: avformat.c:190
d
d
Definition: ffmpeg_filter.c:156
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:91
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
FFStream::parser
struct AVCodecParserContext * parser
Definition: internal.h:387
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3617
AVStream::start_time
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition: avformat.h:988
avstring.h
av_strndup
char * av_strndup(const char *s, size_t len)
Duplicate a substring of a string.
Definition: mem.c:292
AVStream::pts_wrap_bits
int pts_wrap_bits
Number of bits in timestamps.
Definition: avformat.h:1117
codec_desc.h
ff_format_set_url
void ff_format_set_url(AVFormatContext *s, char *url)
Set AVFormatContext url field to the provided pointer.
Definition: avformat.c:838
avcodec_parameters_copy
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: codec_par.c:74
dec_ctx
static AVCodecContext * dec_ctx
Definition: filtering_audio.c:44
av_parser_close
void av_parser_close(AVCodecParserContext *s)
Definition: parser.c:189