FFmpeg
utils.c
Go to the documentation of this file.
1 /*
2  * various utility functions for use within FFmpeg
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 <stdint.h>
23 
24 #include "config.h"
25 
26 #include "libavutil/avassert.h"
27 #include "libavutil/avstring.h"
28 #include "libavutil/bprint.h"
29 #include "libavutil/dict.h"
30 #include "libavutil/internal.h"
31 #include "libavutil/intmath.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/parseutils.h"
34 #include "libavutil/pixfmt.h"
35 #include "libavutil/thread.h"
36 #include "libavutil/time.h"
37 
38 #include "libavcodec/bsf.h"
39 #include "libavcodec/bytestream.h"
40 #include "libavcodec/internal.h"
42 
43 #include "avformat.h"
44 #include "avio_internal.h"
45 #include "internal.h"
46 #if CONFIG_NETWORK
47 #include "network.h"
48 #endif
49 
50 #include "libavutil/ffversion.h"
51 const char av_format_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
52 
54 
55 /**
56  * @file
57  * various utility functions for use within FFmpeg
58  */
59 
60 unsigned avformat_version(void)
61 {
64 }
65 
66 const char *avformat_configuration(void)
67 {
68  return FFMPEG_CONFIGURATION;
69 }
70 
71 const char *avformat_license(void)
72 {
73 #define LICENSE_PREFIX "libavformat license: "
74  return &LICENSE_PREFIX FFMPEG_LICENSE[sizeof(LICENSE_PREFIX) - 1];
75 }
76 
78 {
79  return ff_mutex_lock(&avformat_mutex) ? -1 : 0;
80 }
81 
83 {
84  return ff_mutex_unlock(&avformat_mutex) ? -1 : 0;
85 }
86 
87 int64_t av_stream_get_end_pts(const AVStream *st)
88 {
89  if (cffstream(st)->priv_pts) {
90  return cffstream(st)->priv_pts->val;
91  } else
92  return AV_NOPTS_VALUE;
93 }
94 
96 {
97  return cffstream(st)->parser;
98 }
99 
101 {
102  ffstream(st)->need_parsing = type;
103 }
104 
106 {
107  FFFormatContext *const si = ffformatcontext(s);
108  si->inject_global_side_data = 1;
109  for (unsigned i = 0; i < s->nb_streams; i++) {
110  AVStream *st = s->streams[i];
112  }
113 }
114 
116 {
117  av_assert0(!dst->codec_whitelist &&
118  !dst->format_whitelist &&
119  !dst->protocol_whitelist &&
120  !dst->protocol_blacklist);
121  dst-> codec_whitelist = av_strdup(src->codec_whitelist);
122  dst->format_whitelist = av_strdup(src->format_whitelist);
123  dst->protocol_whitelist = av_strdup(src->protocol_whitelist);
124  dst->protocol_blacklist = av_strdup(src->protocol_blacklist);
125  if ( (src-> codec_whitelist && !dst-> codec_whitelist)
126  || (src-> format_whitelist && !dst-> format_whitelist)
127  || (src->protocol_whitelist && !dst->protocol_whitelist)
128  || (src->protocol_blacklist && !dst->protocol_blacklist)) {
129  av_log(dst, AV_LOG_ERROR, "Failed to duplicate black/whitelist\n");
130  return AVERROR(ENOMEM);
131  }
132  return 0;
133 }
134 
136  enum AVCodecID codec_id)
137 {
138  switch (st->codecpar->codec_type) {
139  case AVMEDIA_TYPE_VIDEO:
140  if (s->video_codec) return s->video_codec;
141  break;
142  case AVMEDIA_TYPE_AUDIO:
143  if (s->audio_codec) return s->audio_codec;
144  break;
146  if (s->subtitle_codec) return s->subtitle_codec;
147  break;
148  }
149 
151 }
152 
153 /* an arbitrarily chosen "sane" max packet size -- 50M */
154 #define SANE_CHUNK_SIZE (50000000)
155 
156 /* Read the data in sane-sized chunks and append to pkt.
157  * Return the number of bytes read or an error. */
159 {
160  int orig_size = pkt->size;
161  int ret;
162 
163  do {
164  int prev_size = pkt->size;
165  int read_size;
166 
167  /* When the caller requests a lot of data, limit it to the amount
168  * left in file or SANE_CHUNK_SIZE when it is not known. */
169  read_size = size;
170  if (read_size > SANE_CHUNK_SIZE/10) {
171  read_size = ffio_limit(s, read_size);
172  // If filesize/maxsize is unknown, limit to SANE_CHUNK_SIZE
173  if (ffiocontext(s)->maxsize < 0)
174  read_size = FFMIN(read_size, SANE_CHUNK_SIZE);
175  }
176 
177  ret = av_grow_packet(pkt, read_size);
178  if (ret < 0)
179  break;
180 
181  ret = avio_read(s, pkt->data + prev_size, read_size);
182  if (ret != read_size) {
183  av_shrink_packet(pkt, prev_size + FFMAX(ret, 0));
184  break;
185  }
186 
187  size -= read_size;
188  } while (size > 0);
189  if (size > 0)
191 
192  if (!pkt->size)
194  return pkt->size > orig_size ? pkt->size - orig_size : ret;
195 }
196 
198 {
199 #if FF_API_INIT_PACKET
202  pkt->data = NULL;
203  pkt->size = 0;
205 #else
207 #endif
208  pkt->pos = avio_tell(s);
209 
210  return append_packet_chunked(s, pkt, size);
211 }
212 
214 {
215  if (!pkt->size)
216  return av_get_packet(s, pkt, size);
217  return append_packet_chunked(s, pkt, size);
218 }
219 
220 int av_filename_number_test(const char *filename)
221 {
222  char buf[1024];
223  return filename &&
224  (av_get_frame_filename(buf, sizeof(buf), filename, 1) >= 0);
225 }
226 
228 {
229  FFFormatContext *const si = ffformatcontext(s);
230  int ret;
231  for (unsigned i = 0; i < s->nb_streams; i++)
232  if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC &&
233  s->streams[i]->discard < AVDISCARD_ALL) {
234  if (s->streams[i]->attached_pic.size <= 0) {
236  "Attached picture on stream %d has invalid size, "
237  "ignoring\n", i);
238  continue;
239  }
240 
242  &s->streams[i]->attached_pic,
243  av_packet_ref, 0);
244  if (ret < 0)
245  return ret;
246  }
247  return 0;
248 }
249 
251  AVBufferRef **buf, int size)
252 {
253  AVStream *st = st0;
254  AVPacket *pkt;
255  int ret;
256 
257  if (!st && !(st = avformat_new_stream(s, NULL)))
258  return AVERROR(ENOMEM);
259  pkt = &st->attached_pic;
260  if (buf) {
261  av_assert1(*buf);
263  pkt->buf = *buf;
264  pkt->data = (*buf)->data;
265  pkt->size = (*buf)->size - AV_INPUT_BUFFER_PADDING_SIZE;
266  *buf = NULL;
267  } else {
268  ret = av_get_packet(pb, pkt, size);
269  if (ret < 0)
270  goto fail;
271  }
274 
275  pkt->stream_index = st->index;
277 
278  return 0;
279 fail:
280  if (!st0)
281  ff_free_stream(s, st);
282  return ret;
283 }
284 
285 /**********************************************************/
286 
288 {
290  if (!d)
291  return 0;
292  if ((d->type == AVMEDIA_TYPE_VIDEO || d->type == AVMEDIA_TYPE_AUDIO) &&
293  !(d->props & AV_CODEC_PROP_INTRA_ONLY))
294  return 0;
295  return 1;
296 }
297 
298 /* XXX: suppress the packet queue */
300 {
301  FFFormatContext *const si = ffformatcontext(s);
305 
306  si->raw_packet_buffer_size = 0;
307 }
308 
310 {
311  int best_stream = 0;
312  int best_score = INT_MIN;
313 
314  if (s->nb_streams <= 0)
315  return -1;
316  for (unsigned i = 0; i < s->nb_streams; i++) {
317  const AVStream *const st = s->streams[i];
318  const FFStream *const sti = cffstream(st);
319  int score = 0;
320  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
322  score -= 400;
323  if (st->codecpar->width && st->codecpar->height)
324  score += 50;
325  score+= 25;
326  }
327  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
328  if (st->codecpar->sample_rate)
329  score += 50;
330  }
331  if (sti->codec_info_nb_frames)
332  score += 12;
333 
334  if (st->discard != AVDISCARD_ALL)
335  score += 200;
336 
337  if (score > best_score) {
338  best_score = score;
339  best_stream = i;
340  }
341  }
342  return best_stream;
343 }
344 
345 /*******************************************************/
346 
347 unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id)
348 {
349  while (tags->id != AV_CODEC_ID_NONE) {
350  if (tags->id == id)
351  return tags->tag;
352  tags++;
353  }
354  return 0;
355 }
356 
357 enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
358 {
359  for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++)
360  if (tag == tags[i].tag)
361  return tags[i].id;
362  for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++)
363  if (ff_toupper4(tag) == ff_toupper4(tags[i].tag))
364  return tags[i].id;
365  return AV_CODEC_ID_NONE;
366 }
367 
368 enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags)
369 {
370  if (bps <= 0 || bps > 64)
371  return AV_CODEC_ID_NONE;
372 
373  if (flt) {
374  switch (bps) {
375  case 32:
377  case 64:
379  default:
380  return AV_CODEC_ID_NONE;
381  }
382  } else {
383  bps += 7;
384  bps >>= 3;
385  if (sflags & (1 << (bps - 1))) {
386  switch (bps) {
387  case 1:
388  return AV_CODEC_ID_PCM_S8;
389  case 2:
391  case 3:
393  case 4:
395  case 8:
397  default:
398  return AV_CODEC_ID_NONE;
399  }
400  } else {
401  switch (bps) {
402  case 1:
403  return AV_CODEC_ID_PCM_U8;
404  case 2:
406  case 3:
408  case 4:
410  default:
411  return AV_CODEC_ID_NONE;
412  }
413  }
414  }
415 }
416 
417 unsigned int av_codec_get_tag(const AVCodecTag *const *tags, enum AVCodecID id)
418 {
419  unsigned int tag;
420  if (!av_codec_get_tag2(tags, id, &tag))
421  return 0;
422  return tag;
423 }
424 
425 int av_codec_get_tag2(const AVCodecTag * const *tags, enum AVCodecID id,
426  unsigned int *tag)
427 {
428  for (int i = 0; tags && tags[i]; i++) {
429  const AVCodecTag *codec_tags = tags[i];
430  while (codec_tags->id != AV_CODEC_ID_NONE) {
431  if (codec_tags->id == id) {
432  *tag = codec_tags->tag;
433  return 1;
434  }
435  codec_tags++;
436  }
437  }
438  return 0;
439 }
440 
441 enum AVCodecID av_codec_get_id(const AVCodecTag *const *tags, unsigned int tag)
442 {
443  for (int i = 0; tags && tags[i]; i++) {
444  enum AVCodecID id = ff_codec_get_id(tags[i], tag);
445  if (id != AV_CODEC_ID_NONE)
446  return id;
447  }
448  return AV_CODEC_ID_NONE;
449 }
450 
452 {
453  av_freep(&par->extradata);
454  par->extradata_size = 0;
455 
456  if (size < 0 || size >= INT32_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
457  return AVERROR(EINVAL);
458 
460  if (!par->extradata)
461  return AVERROR(ENOMEM);
462 
463  memset(par->extradata + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
464  par->extradata_size = size;
465 
466  return 0;
467 }
468 
470 {
471  int ret = ff_alloc_extradata(par, size);
472  if (ret < 0)
473  return ret;
474  ret = ffio_read_size(pb, par->extradata, size);
475  if (ret < 0) {
476  av_freep(&par->extradata);
477  par->extradata_size = 0;
478  av_log(s, AV_LOG_ERROR, "Failed to read extradata of size %d\n", size);
479  return ret;
480  }
481 
482  return ret;
483 }
484 
486 {
487  for (unsigned i = 0; i < ic->nb_programs; i++) {
488  if (ic->programs[i] == last) {
489  last = NULL;
490  } else {
491  if (!last)
492  for (unsigned j = 0; j < ic->programs[i]->nb_stream_indexes; j++)
493  if (ic->programs[i]->stream_index[j] == s)
494  return ic->programs[i];
495  }
496  }
497  return NULL;
498 }
499 
501  int wanted_stream_nb, int related_stream,
502  const AVCodec **decoder_ret, int flags)
503 {
504  int nb_streams = ic->nb_streams;
506  int best_count = -1, best_multiframe = -1, best_disposition = -1;
507  int count, multiframe, disposition;
508  int64_t best_bitrate = -1;
509  int64_t bitrate;
510  unsigned *program = NULL;
511  const AVCodec *decoder = NULL, *best_decoder = NULL;
512 
513  if (related_stream >= 0 && wanted_stream_nb < 0) {
514  AVProgram *p = av_find_program_from_stream(ic, NULL, related_stream);
515  if (p) {
516  program = p->stream_index;
518  }
519  }
520  for (unsigned i = 0; i < nb_streams; i++) {
521  int real_stream_index = program ? program[i] : i;
522  AVStream *st = ic->streams[real_stream_index];
523  AVCodecParameters *par = st->codecpar;
524  if (par->codec_type != type)
525  continue;
526  if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
527  continue;
528  if (type == AVMEDIA_TYPE_AUDIO && !(par->channels && par->sample_rate))
529  continue;
530  if (decoder_ret) {
531  decoder = ff_find_decoder(ic, st, par->codec_id);
532  if (!decoder) {
533  if (ret < 0)
535  continue;
536  }
537  }
539  + !! (st->disposition & AV_DISPOSITION_DEFAULT);
540  count = ffstream(st)->codec_info_nb_frames;
541  bitrate = par->bit_rate;
542  multiframe = FFMIN(5, count);
543  if ((best_disposition > disposition) ||
544  (best_disposition == disposition && best_multiframe > multiframe) ||
545  (best_disposition == disposition && best_multiframe == multiframe && best_bitrate > bitrate) ||
546  (best_disposition == disposition && best_multiframe == multiframe && best_bitrate == bitrate && best_count >= count))
547  continue;
548  best_disposition = disposition;
549  best_count = count;
550  best_bitrate = bitrate;
551  best_multiframe = multiframe;
552  ret = real_stream_index;
553  best_decoder = decoder;
554  if (program && i == nb_streams - 1 && ret < 0) {
555  program = NULL;
556  nb_streams = ic->nb_streams;
557  /* no related stream found, try again with everything */
558  i = 0;
559  }
560  }
561  if (decoder_ret)
562  *decoder_ret = best_decoder;
563  return ret;
564 }
565 
566 /*******************************************************/
567 
569 {
570  if (s->iformat->read_play)
571  return s->iformat->read_play(s);
572  if (s->pb)
573  return avio_pause(s->pb, 0);
574  return AVERROR(ENOSYS);
575 }
576 
578 {
579  if (s->iformat->read_pause)
580  return s->iformat->read_pause(s);
581  if (s->pb)
582  return avio_pause(s->pb, 1);
583  return AVERROR(ENOSYS);
584 }
585 
587 {
588  int ret;
589 
590  dst->id = src->id;
591  dst->time_base = src->time_base;
592  dst->nb_frames = src->nb_frames;
593  dst->disposition = src->disposition;
594  dst->sample_aspect_ratio = src->sample_aspect_ratio;
595  dst->avg_frame_rate = src->avg_frame_rate;
596  dst->r_frame_rate = src->r_frame_rate;
597 
598  av_dict_free(&dst->metadata);
599  ret = av_dict_copy(&dst->metadata, src->metadata, 0);
600  if (ret < 0)
601  return ret;
602 
603  ret = avcodec_parameters_copy(dst->codecpar, src->codecpar);
604  if (ret < 0)
605  return ret;
606 
608  if (ret < 0)
609  return ret;
610 
611  return 0;
612 }
613 
615 {
616  /* Free existing side data*/
617  for (int i = 0; i < dst->nb_side_data; i++)
618  av_free(dst->side_data[i].data);
619  av_freep(&dst->side_data);
620  dst->nb_side_data = 0;
621 
622  /* Copy side data if present */
623  if (src->nb_side_data) {
624  dst->side_data = av_calloc(src->nb_side_data,
625  sizeof(*dst->side_data));
626  if (!dst->side_data)
627  return AVERROR(ENOMEM);
628  dst->nb_side_data = src->nb_side_data;
629 
630  for (int i = 0; i < src->nb_side_data; i++) {
631  uint8_t *data = av_memdup(src->side_data[i].data,
632  src->side_data[i].size);
633  if (!data)
634  return AVERROR(ENOMEM);
635  dst->side_data[i].type = src->side_data[i].type;
636  dst->side_data[i].size = src->side_data[i].size;
637  dst->side_data[i].data = data;
638  }
639  }
640 
641  return 0;
642 }
643 
644 static void free_stream(AVStream **pst)
645 {
646  AVStream *st = *pst;
647  FFStream *const sti = ffstream(st);
648 
649  if (!st)
650  return;
651 
652  for (int i = 0; i < st->nb_side_data; i++)
653  av_freep(&st->side_data[i].data);
654  av_freep(&st->side_data);
655 
656  if (st->attached_pic.data)
658 
659  av_parser_close(sti->parser);
661  av_bsf_free(&sti->bsfc);
662  av_freep(&sti->priv_pts);
663  av_freep(&sti->index_entries);
664  av_freep(&sti->probe_data.buf);
665 
667 
668  if (sti->info) {
669  av_freep(&sti->info->duration_error);
670  av_freep(&sti->info);
671  }
672 
673  av_dict_free(&st->metadata);
675  av_freep(&st->priv_data);
676 
677  av_freep(pst);
678 }
679 
681 {
682  av_assert0(s->nb_streams>0);
683  av_assert0(s->streams[ s->nb_streams - 1 ] == st);
684 
685  free_stream(&s->streams[ --s->nb_streams ]);
686 }
687 
689 {
690  FFFormatContext *si;
691 
692  if (!s)
693  return;
694  si = ffformatcontext(s);
695 
696  if (s->oformat && s->oformat->deinit && si->initialized)
697  s->oformat->deinit(s);
698 
699  av_opt_free(s);
700  if (s->iformat && s->iformat->priv_class && s->priv_data)
701  av_opt_free(s->priv_data);
702  if (s->oformat && s->oformat->priv_class && s->priv_data)
703  av_opt_free(s->priv_data);
704 
705  for (unsigned i = 0; i < s->nb_streams; i++)
706  free_stream(&s->streams[i]);
707  s->nb_streams = 0;
708 
709  for (unsigned i = 0; i < s->nb_programs; i++) {
710  av_dict_free(&s->programs[i]->metadata);
711  av_freep(&s->programs[i]->stream_index);
712  av_freep(&s->programs[i]);
713  }
714  s->nb_programs = 0;
715 
716  av_freep(&s->programs);
717  av_freep(&s->priv_data);
718  while (s->nb_chapters--) {
719  av_dict_free(&s->chapters[s->nb_chapters]->metadata);
720  av_freep(&s->chapters[s->nb_chapters]);
721  }
722  av_freep(&s->chapters);
723  av_dict_free(&s->metadata);
724  av_dict_free(&si->id3v2_meta);
725  av_packet_free(&si->pkt);
727  av_freep(&s->streams);
729  av_freep(&s->url);
730  av_free(s);
731 }
732 
733 static const AVOption stream_options[] = {
734  { "disposition", NULL, offsetof(AVStream, disposition), AV_OPT_TYPE_FLAGS, { .i64 = 0 },
735  .flags = AV_OPT_FLAG_ENCODING_PARAM, .unit = "disposition" },
736  { "default", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEFAULT }, .unit = "disposition" },
737  { "dub", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DUB }, .unit = "disposition" },
738  { "original", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ORIGINAL }, .unit = "disposition" },
739  { "comment", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_COMMENT }, .unit = "disposition" },
740  { "lyrics", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_LYRICS }, .unit = "disposition" },
741  { "karaoke", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_KARAOKE }, .unit = "disposition" },
742  { "forced", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_FORCED }, .unit = "disposition" },
743  { "hearing_impaired", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_HEARING_IMPAIRED }, .unit = "disposition" },
744  { "visual_impaired", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_VISUAL_IMPAIRED }, .unit = "disposition" },
745  { "clean_effects", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CLEAN_EFFECTS }, .unit = "disposition" },
746  { "attached_pic", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ATTACHED_PIC }, .unit = "disposition" },
747  { "timed_thumbnails", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_TIMED_THUMBNAILS }, .unit = "disposition" },
748  { "captions", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CAPTIONS }, .unit = "disposition" },
749  { "descriptions", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DESCRIPTIONS }, .unit = "disposition" },
750  { "metadata", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_METADATA }, .unit = "disposition" },
751  { "dependent", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEPENDENT }, .unit = "disposition" },
752  { "still_image", .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_STILL_IMAGE }, .unit = "disposition" },
753  { NULL }
754 };
755 
756 static const AVClass stream_class = {
757  .class_name = "AVStream",
758  .item_name = av_default_item_name,
759  .version = LIBAVUTIL_VERSION_INT,
760  .option = stream_options,
761 };
762 
764 {
765  return &stream_class;
766 }
767 
769 {
770  FFFormatContext *const si = ffformatcontext(s);
771  FFStream *sti;
772  AVStream *st;
773  AVStream **streams;
774 
775  if (s->nb_streams >= s->max_streams) {
776  av_log(s, AV_LOG_ERROR, "Number of streams exceeds max_streams parameter"
777  " (%d), see the documentation if you wish to increase it\n",
778  s->max_streams);
779  return NULL;
780  }
781  streams = av_realloc_array(s->streams, s->nb_streams + 1, sizeof(*streams));
782  if (!streams)
783  return NULL;
784  s->streams = streams;
785 
786 
787  sti = av_mallocz(sizeof(*sti));
788  if (!sti)
789  return NULL;
790  st = &sti->pub;
791 
792 #if FF_API_AVSTREAM_CLASS
793  st->av_class = &stream_class;
794 #endif
795 
797  if (!st->codecpar)
798  goto fail;
799 
801  if (!sti->avctx)
802  goto fail;
803 
804  if (s->iformat) {
805  sti->info = av_mallocz(sizeof(*sti->info));
806  if (!sti->info)
807  goto fail;
808 
809 #if FF_API_R_FRAME_RATE
810  sti->info->last_dts = AV_NOPTS_VALUE;
811 #endif
814 
815  /* default pts setting is MPEG-like */
816  avpriv_set_pts_info(st, 33, 1, 90000);
817  /* we set the current DTS to 0 so that formats without any timestamps
818  * but durations get some timestamps, formats with some unknown
819  * timestamps have their first few packets buffered and the
820  * timestamps corrected before they are returned to the user */
821  sti->cur_dts = RELATIVE_TS_BASE;
822  } else {
823  sti->cur_dts = AV_NOPTS_VALUE;
824  }
825 
826  st->index = s->nb_streams;
828  st->duration = AV_NOPTS_VALUE;
829  sti->first_dts = AV_NOPTS_VALUE;
830  sti->probe_packets = s->max_probe_packets;
833 
836  for (int i = 0; i < MAX_REORDER_DELAY + 1; i++)
837  sti->pts_buffer[i] = AV_NOPTS_VALUE;
838 
839  st->sample_aspect_ratio = (AVRational) { 0, 1 };
840 
842 
843  sti->need_context_update = 1;
844 
845  s->streams[s->nb_streams++] = st;
846  return st;
847 fail:
848  free_stream(&st);
849  return NULL;
850 }
851 
853 {
855  int ret;
856 
857  av_log(ac, AV_LOG_TRACE, "new_program: id=0x%04x\n", id);
858 
859  for (unsigned i = 0; i < ac->nb_programs; i++)
860  if (ac->programs[i]->id == id)
861  program = ac->programs[i];
862 
863  if (!program) {
864  program = av_mallocz(sizeof(AVProgram));
865  if (!program)
866  return NULL;
868  if (ret < 0) {
869  av_free(program);
870  return NULL;
871  }
872  program->discard = AVDISCARD_NONE;
873  program->pmt_version = -1;
874  program->id = id;
875  program->pts_wrap_reference = AV_NOPTS_VALUE;
876  program->pts_wrap_behavior = AV_PTS_WRAP_IGNORE;
877  program->start_time =
878  program->end_time = AV_NOPTS_VALUE;
879  }
880  return program;
881 }
882 
884  int64_t start, int64_t end, const char *title)
885 {
886  FFFormatContext *const si = ffformatcontext(s);
887  AVChapter *chapter = NULL;
888  int ret;
889 
890  if (end != AV_NOPTS_VALUE && start > end) {
891  av_log(s, AV_LOG_ERROR, "Chapter end time %"PRId64" before start %"PRId64"\n", end, start);
892  return NULL;
893  }
894 
895  if (!s->nb_chapters) {
896  si->chapter_ids_monotonic = 1;
897  } else if (!si->chapter_ids_monotonic || s->chapters[s->nb_chapters-1]->id >= id) {
898  for (unsigned i = 0; i < s->nb_chapters; i++)
899  if (s->chapters[i]->id == id)
900  chapter = s->chapters[i];
901  if (!chapter)
902  si->chapter_ids_monotonic = 0;
903  }
904 
905  if (!chapter) {
906  chapter = av_mallocz(sizeof(AVChapter));
907  if (!chapter)
908  return NULL;
909  ret = av_dynarray_add_nofree(&s->chapters, &s->nb_chapters, chapter);
910  if (ret < 0) {
911  av_free(chapter);
912  return NULL;
913  }
914  }
915  av_dict_set(&chapter->metadata, "title", title, 0);
916  chapter->id = id;
917  chapter->time_base = time_base;
918  chapter->start = start;
919  chapter->end = end;
920 
921  return chapter;
922 }
923 
924 void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
925 {
927  void *tmp;
928 
929  if (idx >= ac->nb_streams) {
930  av_log(ac, AV_LOG_ERROR, "stream index %d is not valid\n", idx);
931  return;
932  }
933 
934  for (unsigned i = 0; i < ac->nb_programs; i++) {
935  if (ac->programs[i]->id != progid)
936  continue;
937  program = ac->programs[i];
938  for (unsigned j = 0; j < program->nb_stream_indexes; j++)
939  if (program->stream_index[j] == idx)
940  return;
941 
942  tmp = av_realloc_array(program->stream_index, program->nb_stream_indexes+1, sizeof(unsigned int));
943  if (!tmp)
944  return;
945  program->stream_index = tmp;
946  program->stream_index[program->nb_stream_indexes++] = idx;
947  return;
948  }
949 }
950 
951 uint64_t ff_ntp_time(void)
952 {
953  return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US;
954 }
955 
956 uint64_t ff_get_formatted_ntp_time(uint64_t ntp_time_us)
957 {
958  uint64_t ntp_ts, frac_part, sec;
959  uint32_t usec;
960 
961  //current ntp time in seconds and micro seconds
962  sec = ntp_time_us / 1000000;
963  usec = ntp_time_us % 1000000;
964 
965  //encoding in ntp timestamp format
966  frac_part = usec * 0xFFFFFFFFULL;
967  frac_part /= 1000000;
968 
969  if (sec > 0xFFFFFFFFULL)
970  av_log(NULL, AV_LOG_WARNING, "NTP time format roll over detected\n");
971 
972  ntp_ts = sec << 32;
973  ntp_ts |= frac_part;
974 
975  return ntp_ts;
976 }
977 
978 uint64_t ff_parse_ntp_time(uint64_t ntp_ts)
979 {
980  uint64_t sec = ntp_ts >> 32;
981  uint64_t frac_part = ntp_ts & 0xFFFFFFFFULL;
982  uint64_t usec = (frac_part * 1000000) / 0xFFFFFFFFULL;
983 
984  return (sec * 1000000) + usec;
985 }
986 
987 int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags)
988 {
989  const char *p;
990  char *q, buf1[20], c;
991  int nd, len, percentd_found;
992 
993  q = buf;
994  p = path;
995  percentd_found = 0;
996  for (;;) {
997  c = *p++;
998  if (c == '\0')
999  break;
1000  if (c == '%') {
1001  do {
1002  nd = 0;
1003  while (av_isdigit(*p)) {
1004  if (nd >= INT_MAX / 10 - 255)
1005  goto fail;
1006  nd = nd * 10 + *p++ - '0';
1007  }
1008  c = *p++;
1009  } while (av_isdigit(c));
1010 
1011  switch (c) {
1012  case '%':
1013  goto addchar;
1014  case 'd':
1015  if (!(flags & AV_FRAME_FILENAME_FLAGS_MULTIPLE) && percentd_found)
1016  goto fail;
1017  percentd_found = 1;
1018  if (number < 0)
1019  nd += 1;
1020  snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
1021  len = strlen(buf1);
1022  if ((q - buf + len) > buf_size - 1)
1023  goto fail;
1024  memcpy(q, buf1, len);
1025  q += len;
1026  break;
1027  default:
1028  goto fail;
1029  }
1030  } else {
1031 addchar:
1032  if ((q - buf) < buf_size - 1)
1033  *q++ = c;
1034  }
1035  }
1036  if (!percentd_found)
1037  goto fail;
1038  *q = '\0';
1039  return 0;
1040 fail:
1041  *q = '\0';
1042  return -1;
1043 }
1044 
1045 int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
1046 {
1047  return av_get_frame_filename2(buf, buf_size, path, number, 0);
1048 }
1049 
1050 void av_url_split(char *proto, int proto_size,
1051  char *authorization, int authorization_size,
1052  char *hostname, int hostname_size,
1053  int *port_ptr, char *path, int path_size, const char *url)
1054 {
1055  const char *p, *ls, *at, *at2, *col, *brk;
1056 
1057  if (port_ptr)
1058  *port_ptr = -1;
1059  if (proto_size > 0)
1060  proto[0] = 0;
1061  if (authorization_size > 0)
1062  authorization[0] = 0;
1063  if (hostname_size > 0)
1064  hostname[0] = 0;
1065  if (path_size > 0)
1066  path[0] = 0;
1067 
1068  /* parse protocol */
1069  if ((p = strchr(url, ':'))) {
1070  av_strlcpy(proto, url, FFMIN(proto_size, p + 1 - url));
1071  p++; /* skip ':' */
1072  if (*p == '/')
1073  p++;
1074  if (*p == '/')
1075  p++;
1076  } else {
1077  /* no protocol means plain filename */
1078  av_strlcpy(path, url, path_size);
1079  return;
1080  }
1081 
1082  /* separate path from hostname */
1083  ls = p + strcspn(p, "/?#");
1084  av_strlcpy(path, ls, path_size);
1085 
1086  /* the rest is hostname, use that to parse auth/port */
1087  if (ls != p) {
1088  /* authorization (user[:pass]@hostname) */
1089  at2 = p;
1090  while ((at = strchr(p, '@')) && at < ls) {
1091  av_strlcpy(authorization, at2,
1092  FFMIN(authorization_size, at + 1 - at2));
1093  p = at + 1; /* skip '@' */
1094  }
1095 
1096  if (*p == '[' && (brk = strchr(p, ']')) && brk < ls) {
1097  /* [host]:port */
1098  av_strlcpy(hostname, p + 1,
1099  FFMIN(hostname_size, brk - p));
1100  if (brk[1] == ':' && port_ptr)
1101  *port_ptr = atoi(brk + 2);
1102  } else if ((col = strchr(p, ':')) && col < ls) {
1103  av_strlcpy(hostname, p,
1104  FFMIN(col + 1 - p, hostname_size));
1105  if (port_ptr)
1106  *port_ptr = atoi(col + 1);
1107  } else
1108  av_strlcpy(hostname, p,
1109  FFMIN(ls + 1 - p, hostname_size));
1110  }
1111 }
1112 
1113 int ff_mkdir_p(const char *path)
1114 {
1115  int ret = 0;
1116  char *temp = av_strdup(path);
1117  char *pos = temp;
1118  char tmp_ch = '\0';
1119 
1120  if (!path || !temp) {
1121  return -1;
1122  }
1123 
1124  if (!av_strncasecmp(temp, "/", 1) || !av_strncasecmp(temp, "\\", 1)) {
1125  pos++;
1126  } else if (!av_strncasecmp(temp, "./", 2) || !av_strncasecmp(temp, ".\\", 2)) {
1127  pos += 2;
1128  }
1129 
1130  for ( ; *pos != '\0'; ++pos) {
1131  if (*pos == '/' || *pos == '\\') {
1132  tmp_ch = *pos;
1133  *pos = '\0';
1134  ret = mkdir(temp, 0755);
1135  *pos = tmp_ch;
1136  }
1137  }
1138 
1139  if ((*(pos - 1) != '/') || (*(pos - 1) != '\\')) {
1140  ret = mkdir(temp, 0755);
1141  }
1142 
1143  av_free(temp);
1144  return ret;
1145 }
1146 
1147 char *ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase)
1148 {
1149  static const char hex_table_uc[16] = { '0', '1', '2', '3',
1150  '4', '5', '6', '7',
1151  '8', '9', 'A', 'B',
1152  'C', 'D', 'E', 'F' };
1153  static const char hex_table_lc[16] = { '0', '1', '2', '3',
1154  '4', '5', '6', '7',
1155  '8', '9', 'a', 'b',
1156  'c', 'd', 'e', 'f' };
1157  const char *hex_table = lowercase ? hex_table_lc : hex_table_uc;
1158 
1159  for (int i = 0; i < s; i++) {
1160  buff[i * 2] = hex_table[src[i] >> 4];
1161  buff[i * 2 + 1] = hex_table[src[i] & 0xF];
1162  }
1163  buff[2 * s] = '\0';
1164 
1165  return buff;
1166 }
1167 
1168 int ff_hex_to_data(uint8_t *data, const char *p)
1169 {
1170  int c, len, v;
1171 
1172  len = 0;
1173  v = 1;
1174  for (;;) {
1175  p += strspn(p, SPACE_CHARS);
1176  if (*p == '\0')
1177  break;
1178  c = av_toupper((unsigned char) *p++);
1179  if (c >= '0' && c <= '9')
1180  c = c - '0';
1181  else if (c >= 'A' && c <= 'F')
1182  c = c - 'A' + 10;
1183  else
1184  break;
1185  v = (v << 4) | c;
1186  if (v & 0x100) {
1187  if (data)
1188  data[len] = v;
1189  len++;
1190  v = 1;
1191  }
1192  }
1193  return len;
1194 }
1195 
1196 void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits,
1197  unsigned int pts_num, unsigned int pts_den)
1198 {
1199  FFStream *const sti = ffstream(st);
1200  AVRational new_tb;
1201  if (av_reduce(&new_tb.num, &new_tb.den, pts_num, pts_den, INT_MAX)) {
1202  if (new_tb.num != pts_num)
1204  "st:%d removing common factor %d from timebase\n",
1205  st->index, pts_num / new_tb.num);
1206  } else
1208  "st:%d has too large timebase, reducing\n", st->index);
1209 
1210  if (new_tb.num <= 0 || new_tb.den <= 0) {
1212  "Ignoring attempt to set invalid timebase %d/%d for st:%d\n",
1213  new_tb.num, new_tb.den,
1214  st->index);
1215  return;
1216  }
1217  st->time_base = new_tb;
1218  sti->avctx->pkt_timebase = new_tb;
1219  st->pts_wrap_bits = pts_wrap_bits;
1220 }
1221 
1222 void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
1223  void *context)
1224 {
1225  const char *ptr = str;
1226 
1227  /* Parse key=value pairs. */
1228  for (;;) {
1229  const char *key;
1230  char *dest = NULL, *dest_end;
1231  int key_len, dest_len = 0;
1232 
1233  /* Skip whitespace and potential commas. */
1234  while (*ptr && (av_isspace(*ptr) || *ptr == ','))
1235  ptr++;
1236  if (!*ptr)
1237  break;
1238 
1239  key = ptr;
1240 
1241  if (!(ptr = strchr(key, '=')))
1242  break;
1243  ptr++;
1244  key_len = ptr - key;
1245 
1246  callback_get_buf(context, key, key_len, &dest, &dest_len);
1247  dest_end = dest ? dest + dest_len - 1 : NULL;
1248 
1249  if (*ptr == '\"') {
1250  ptr++;
1251  while (*ptr && *ptr != '\"') {
1252  if (*ptr == '\\') {
1253  if (!ptr[1])
1254  break;
1255  if (dest && dest < dest_end)
1256  *dest++ = ptr[1];
1257  ptr += 2;
1258  } else {
1259  if (dest && dest < dest_end)
1260  *dest++ = *ptr;
1261  ptr++;
1262  }
1263  }
1264  if (*ptr == '\"')
1265  ptr++;
1266  } else {
1267  for (; *ptr && !(av_isspace(*ptr) || *ptr == ','); ptr++)
1268  if (dest && dest < dest_end)
1269  *dest++ = *ptr;
1270  }
1271  if (dest)
1272  *dest = 0;
1273  }
1274 }
1275 
1277 {
1278  for (unsigned i = 0; i < s->nb_streams; i++)
1279  if (s->streams[i]->id == id)
1280  return i;
1281  return -1;
1282 }
1283 
1285  int std_compliance)
1286 {
1287  if (ofmt) {
1288  unsigned int codec_tag;
1289  if (ofmt->query_codec)
1290  return ofmt->query_codec(codec_id, std_compliance);
1291  else if (ofmt->codec_tag)
1292  return !!av_codec_get_tag2(ofmt->codec_tag, codec_id, &codec_tag);
1293  else if (codec_id == ofmt->video_codec ||
1294  codec_id == ofmt->audio_codec ||
1295  codec_id == ofmt->subtitle_codec ||
1296  codec_id == ofmt->data_codec)
1297  return 1;
1298  }
1299  return AVERROR_PATCHWELCOME;
1300 }
1301 
1303 {
1304 #if CONFIG_NETWORK
1305  int ret;
1306  if ((ret = ff_network_init()) < 0)
1307  return ret;
1308  if ((ret = ff_tls_init()) < 0)
1309  return ret;
1310 #endif
1311  return 0;
1312 }
1313 
1315 {
1316 #if CONFIG_NETWORK
1317  ff_network_close();
1318  ff_tls_deinit();
1319 #endif
1320  return 0;
1321 }
1322 
1324  uint64_t channel_layout, int32_t sample_rate,
1326 {
1327  uint32_t flags = 0;
1328  int size = 4;
1329  uint8_t *data;
1330  if (!pkt)
1331  return AVERROR(EINVAL);
1332  if (channels) {
1333  size += 4;
1335  }
1336  if (channel_layout) {
1337  size += 8;
1339  }
1340  if (sample_rate) {
1341  size += 4;
1343  }
1344  if (width || height) {
1345  size += 8;
1347  }
1349  if (!data)
1350  return AVERROR(ENOMEM);
1351  bytestream_put_le32(&data, flags);
1352  if (channels)
1353  bytestream_put_le32(&data, channels);
1354  if (channel_layout)
1355  bytestream_put_le64(&data, channel_layout);
1356  if (sample_rate)
1357  bytestream_put_le32(&data, sample_rate);
1358  if (width || height) {
1359  bytestream_put_le32(&data, width);
1360  bytestream_put_le32(&data, height);
1361  }
1362  return 0;
1363 }
1364 
1366 {
1367  AVRational undef = {0, 1};
1368  AVRational stream_sample_aspect_ratio = stream ? stream->sample_aspect_ratio : undef;
1369  AVRational codec_sample_aspect_ratio = stream && stream->codecpar ? stream->codecpar->sample_aspect_ratio : undef;
1370  AVRational frame_sample_aspect_ratio = frame ? frame->sample_aspect_ratio : codec_sample_aspect_ratio;
1371 
1372  av_reduce(&stream_sample_aspect_ratio.num, &stream_sample_aspect_ratio.den,
1373  stream_sample_aspect_ratio.num, stream_sample_aspect_ratio.den, INT_MAX);
1374  if (stream_sample_aspect_ratio.num <= 0 || stream_sample_aspect_ratio.den <= 0)
1375  stream_sample_aspect_ratio = undef;
1376 
1377  av_reduce(&frame_sample_aspect_ratio.num, &frame_sample_aspect_ratio.den,
1378  frame_sample_aspect_ratio.num, frame_sample_aspect_ratio.den, INT_MAX);
1379  if (frame_sample_aspect_ratio.num <= 0 || frame_sample_aspect_ratio.den <= 0)
1380  frame_sample_aspect_ratio = undef;
1381 
1382  if (stream_sample_aspect_ratio.num)
1383  return stream_sample_aspect_ratio;
1384  else
1385  return frame_sample_aspect_ratio;
1386 }
1387 
1389 {
1390  AVRational fr = st->r_frame_rate;
1391  AVCodecContext *const avctx = ffstream(st)->avctx;
1392  AVRational codec_fr = avctx->framerate;
1393  AVRational avg_fr = st->avg_frame_rate;
1394 
1395  if (avg_fr.num > 0 && avg_fr.den > 0 && fr.num > 0 && fr.den > 0 &&
1396  av_q2d(avg_fr) < 70 && av_q2d(fr) > 210) {
1397  fr = avg_fr;
1398  }
1399 
1400 
1401  if (avctx->ticks_per_frame > 1) {
1402  if ( codec_fr.num > 0 && codec_fr.den > 0 &&
1403  (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))
1404  fr = codec_fr;
1405  }
1406 
1407  return fr;
1408 }
1409 
1410 /**
1411  * Matches a stream specifier (but ignores requested index).
1412  *
1413  * @param indexptr set to point to the requested stream index if there is one
1414  *
1415  * @return <0 on error
1416  * 0 if st is NOT a matching stream
1417  * >0 if st is a matching stream
1418  */
1419 static int match_stream_specifier(const AVFormatContext *s, const AVStream *st,
1420  const char *spec, const char **indexptr,
1421  const AVProgram **p)
1422 {
1423  int match = 1; /* Stores if the specifier matches so far. */
1424  while (*spec) {
1425  if (*spec <= '9' && *spec >= '0') { /* opt:index */
1426  if (indexptr)
1427  *indexptr = spec;
1428  return match;
1429  } else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||
1430  *spec == 't' || *spec == 'V') { /* opt:[vasdtV] */
1431  enum AVMediaType type;
1432  int nopic = 0;
1433 
1434  switch (*spec++) {
1435  case 'v': type = AVMEDIA_TYPE_VIDEO; break;
1436  case 'a': type = AVMEDIA_TYPE_AUDIO; break;
1437  case 's': type = AVMEDIA_TYPE_SUBTITLE; break;
1438  case 'd': type = AVMEDIA_TYPE_DATA; break;
1439  case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
1440  case 'V': type = AVMEDIA_TYPE_VIDEO; nopic = 1; break;
1441  default: av_assert0(0);
1442  }
1443  if (*spec && *spec++ != ':') /* If we are not at the end, then another specifier must follow. */
1444  return AVERROR(EINVAL);
1445 
1446  if (type != st->codecpar->codec_type)
1447  match = 0;
1448  if (nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC))
1449  match = 0;
1450  } else if (*spec == 'p' && *(spec + 1) == ':') {
1451  int prog_id;
1452  int found = 0;
1453  char *endptr;
1454  spec += 2;
1455  prog_id = strtol(spec, &endptr, 0);
1456  /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
1457  if (spec == endptr || (*endptr && *endptr++ != ':'))
1458  return AVERROR(EINVAL);
1459  spec = endptr;
1460  if (match) {
1461  for (unsigned i = 0; i < s->nb_programs; i++) {
1462  if (s->programs[i]->id != prog_id)
1463  continue;
1464 
1465  for (unsigned j = 0; j < s->programs[i]->nb_stream_indexes; j++) {
1466  if (st->index == s->programs[i]->stream_index[j]) {
1467  found = 1;
1468  if (p)
1469  *p = s->programs[i];
1470  i = s->nb_programs;
1471  break;
1472  }
1473  }
1474  }
1475  }
1476  if (!found)
1477  match = 0;
1478  } else if (*spec == '#' ||
1479  (*spec == 'i' && *(spec + 1) == ':')) {
1480  int stream_id;
1481  char *endptr;
1482  spec += 1 + (*spec == 'i');
1483  stream_id = strtol(spec, &endptr, 0);
1484  if (spec == endptr || *endptr) /* Disallow empty id and make sure we are at the end. */
1485  return AVERROR(EINVAL);
1486  return match && (stream_id == st->id);
1487  } else if (*spec == 'm' && *(spec + 1) == ':') {
1488  const AVDictionaryEntry *tag;
1489  char *key, *val;
1490  int ret;
1491 
1492  if (match) {
1493  spec += 2;
1494  val = strchr(spec, ':');
1495 
1496  key = val ? av_strndup(spec, val - spec) : av_strdup(spec);
1497  if (!key)
1498  return AVERROR(ENOMEM);
1499 
1500  tag = av_dict_get(st->metadata, key, NULL, 0);
1501  if (tag) {
1502  if (!val || !strcmp(tag->value, val + 1))
1503  ret = 1;
1504  else
1505  ret = 0;
1506  } else
1507  ret = 0;
1508 
1509  av_freep(&key);
1510  }
1511  return match && ret;
1512  } else if (*spec == 'u' && *(spec + 1) == '\0') {
1513  const AVCodecParameters *par = st->codecpar;
1514  int val;
1515  switch (par->codec_type) {
1516  case AVMEDIA_TYPE_AUDIO:
1517  val = par->sample_rate && par->channels;
1518  if (par->format == AV_SAMPLE_FMT_NONE)
1519  return 0;
1520  break;
1521  case AVMEDIA_TYPE_VIDEO:
1522  val = par->width && par->height;
1523  if (par->format == AV_PIX_FMT_NONE)
1524  return 0;
1525  break;
1526  case AVMEDIA_TYPE_UNKNOWN:
1527  val = 0;
1528  break;
1529  default:
1530  val = 1;
1531  break;
1532  }
1533  return match && (par->codec_id != AV_CODEC_ID_NONE && val != 0);
1534  } else {
1535  return AVERROR(EINVAL);
1536  }
1537  }
1538 
1539  return match;
1540 }
1541 
1542 
1544  const char *spec)
1545 {
1546  int ret, index;
1547  char *endptr;
1548  const char *indexptr = NULL;
1549  const AVProgram *p = NULL;
1550  int nb_streams;
1551 
1552  ret = match_stream_specifier(s, st, spec, &indexptr, &p);
1553  if (ret < 0)
1554  goto error;
1555 
1556  if (!indexptr)
1557  return ret;
1558 
1559  index = strtol(indexptr, &endptr, 0);
1560  if (*endptr) { /* We can't have anything after the requested index. */
1561  ret = AVERROR(EINVAL);
1562  goto error;
1563  }
1564 
1565  /* This is not really needed but saves us a loop for simple stream index specifiers. */
1566  if (spec == indexptr)
1567  return (index == st->index);
1568 
1569  /* If we requested a matching stream index, we have to ensure st is that. */
1570  nb_streams = p ? p->nb_stream_indexes : s->nb_streams;
1571  for (int i = 0; i < nb_streams && index >= 0; i++) {
1572  const AVStream *candidate = s->streams[p ? p->stream_index[i] : i];
1573  ret = match_stream_specifier(s, candidate, spec, NULL, NULL);
1574  if (ret < 0)
1575  goto error;
1576  if (ret > 0 && index-- == 0 && st == candidate)
1577  return 1;
1578  }
1579  return 0;
1580 
1581 error:
1582  if (ret == AVERROR(EINVAL))
1583  av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
1584  return ret;
1585 }
1586 
1588 {
1589  static const uint8_t avci100_1080p_extradata[] = {
1590  // SPS
1591  0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
1592  0xb6, 0xd4, 0x20, 0x22, 0x33, 0x19, 0xc6, 0x63,
1593  0x23, 0x21, 0x01, 0x11, 0x98, 0xce, 0x33, 0x19,
1594  0x18, 0x21, 0x02, 0x56, 0xb9, 0x3d, 0x7d, 0x7e,
1595  0x4f, 0xe3, 0x3f, 0x11, 0xf1, 0x9e, 0x08, 0xb8,
1596  0x8c, 0x54, 0x43, 0xc0, 0x78, 0x02, 0x27, 0xe2,
1597  0x70, 0x1e, 0x30, 0x10, 0x10, 0x14, 0x00, 0x00,
1598  0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0xca,
1599  0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1600  // PPS
1601  0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x33, 0x48,
1602  0xd0
1603  };
1604  static const uint8_t avci100_1080i_extradata[] = {
1605  // SPS
1606  0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
1607  0xb6, 0xd4, 0x20, 0x22, 0x33, 0x19, 0xc6, 0x63,
1608  0x23, 0x21, 0x01, 0x11, 0x98, 0xce, 0x33, 0x19,
1609  0x18, 0x21, 0x03, 0x3a, 0x46, 0x65, 0x6a, 0x65,
1610  0x24, 0xad, 0xe9, 0x12, 0x32, 0x14, 0x1a, 0x26,
1611  0x34, 0xad, 0xa4, 0x41, 0x82, 0x23, 0x01, 0x50,
1612  0x2b, 0x1a, 0x24, 0x69, 0x48, 0x30, 0x40, 0x2e,
1613  0x11, 0x12, 0x08, 0xc6, 0x8c, 0x04, 0x41, 0x28,
1614  0x4c, 0x34, 0xf0, 0x1e, 0x01, 0x13, 0xf2, 0xe0,
1615  0x3c, 0x60, 0x20, 0x20, 0x28, 0x00, 0x00, 0x03,
1616  0x00, 0x08, 0x00, 0x00, 0x03, 0x01, 0x94, 0x20,
1617  // PPS
1618  0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x33, 0x48,
1619  0xd0
1620  };
1621  static const uint8_t avci50_1080p_extradata[] = {
1622  // SPS
1623  0x00, 0x00, 0x00, 0x01, 0x67, 0x6e, 0x10, 0x28,
1624  0xa6, 0xd4, 0x20, 0x32, 0x33, 0x0c, 0x71, 0x18,
1625  0x88, 0x62, 0x10, 0x19, 0x19, 0x86, 0x38, 0x8c,
1626  0x44, 0x30, 0x21, 0x02, 0x56, 0x4e, 0x6f, 0x37,
1627  0xcd, 0xf9, 0xbf, 0x81, 0x6b, 0xf3, 0x7c, 0xde,
1628  0x6e, 0x6c, 0xd3, 0x3c, 0x05, 0xa0, 0x22, 0x7e,
1629  0x5f, 0xfc, 0x00, 0x0c, 0x00, 0x13, 0x8c, 0x04,
1630  0x04, 0x05, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00,
1631  0x00, 0x03, 0x00, 0x32, 0x84, 0x00, 0x00, 0x00,
1632  // PPS
1633  0x00, 0x00, 0x00, 0x01, 0x68, 0xee, 0x31, 0x12,
1634  0x11
1635  };
1636  static const uint8_t avci50_1080i_extradata[] = {
1637  // SPS
1638  0x00, 0x00, 0x00, 0x01, 0x67, 0x6e, 0x10, 0x28,
1639  0xa6, 0xd4, 0x20, 0x32, 0x33, 0x0c, 0x71, 0x18,
1640  0x88, 0x62, 0x10, 0x19, 0x19, 0x86, 0x38, 0x8c,
1641  0x44, 0x30, 0x21, 0x02, 0x56, 0x4e, 0x6e, 0x61,
1642  0x87, 0x3e, 0x73, 0x4d, 0x98, 0x0c, 0x03, 0x06,
1643  0x9c, 0x0b, 0x73, 0xe6, 0xc0, 0xb5, 0x18, 0x63,
1644  0x0d, 0x39, 0xe0, 0x5b, 0x02, 0xd4, 0xc6, 0x19,
1645  0x1a, 0x79, 0x8c, 0x32, 0x34, 0x24, 0xf0, 0x16,
1646  0x81, 0x13, 0xf7, 0xff, 0x80, 0x02, 0x00, 0x01,
1647  0xf1, 0x80, 0x80, 0x80, 0xa0, 0x00, 0x00, 0x03,
1648  0x00, 0x20, 0x00, 0x00, 0x06, 0x50, 0x80, 0x00,
1649  // PPS
1650  0x00, 0x00, 0x00, 0x01, 0x68, 0xee, 0x31, 0x12,
1651  0x11
1652  };
1653  static const uint8_t avci100_720p_extradata[] = {
1654  // SPS
1655  0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
1656  0xb6, 0xd4, 0x20, 0x2a, 0x33, 0x1d, 0xc7, 0x62,
1657  0xa1, 0x08, 0x40, 0x54, 0x66, 0x3b, 0x8e, 0xc5,
1658  0x42, 0x02, 0x10, 0x25, 0x64, 0x2c, 0x89, 0xe8,
1659  0x85, 0xe4, 0x21, 0x4b, 0x90, 0x83, 0x06, 0x95,
1660  0xd1, 0x06, 0x46, 0x97, 0x20, 0xc8, 0xd7, 0x43,
1661  0x08, 0x11, 0xc2, 0x1e, 0x4c, 0x91, 0x0f, 0x01,
1662  0x40, 0x16, 0xec, 0x07, 0x8c, 0x04, 0x04, 0x05,
1663  0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03,
1664  0x00, 0x64, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00,
1665  // PPS
1666  0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x31, 0x12,
1667  0x11
1668  };
1669  static const uint8_t avci50_720p_extradata[] = {
1670  // SPS
1671  0x00, 0x00, 0x00, 0x01, 0x67, 0x6e, 0x10, 0x20,
1672  0xa6, 0xd4, 0x20, 0x32, 0x33, 0x0c, 0x71, 0x18,
1673  0x88, 0x62, 0x10, 0x19, 0x19, 0x86, 0x38, 0x8c,
1674  0x44, 0x30, 0x21, 0x02, 0x56, 0x4e, 0x6f, 0x37,
1675  0xcd, 0xf9, 0xbf, 0x81, 0x6b, 0xf3, 0x7c, 0xde,
1676  0x6e, 0x6c, 0xd3, 0x3c, 0x0f, 0x01, 0x6e, 0xff,
1677  0xc0, 0x00, 0xc0, 0x01, 0x38, 0xc0, 0x40, 0x40,
1678  0x50, 0x00, 0x00, 0x03, 0x00, 0x10, 0x00, 0x00,
1679  0x06, 0x48, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
1680  // PPS
1681  0x00, 0x00, 0x00, 0x01, 0x68, 0xee, 0x31, 0x12,
1682  0x11
1683  };
1684 
1685  const uint8_t *data = NULL;
1686  int ret, size = 0;
1687 
1688  if (st->codecpar->width == 1920) {
1690  data = avci100_1080p_extradata;
1691  size = sizeof(avci100_1080p_extradata);
1692  } else {
1693  data = avci100_1080i_extradata;
1694  size = sizeof(avci100_1080i_extradata);
1695  }
1696  } else if (st->codecpar->width == 1440) {
1698  data = avci50_1080p_extradata;
1699  size = sizeof(avci50_1080p_extradata);
1700  } else {
1701  data = avci50_1080i_extradata;
1702  size = sizeof(avci50_1080i_extradata);
1703  }
1704  } else if (st->codecpar->width == 1280) {
1705  data = avci100_720p_extradata;
1706  size = sizeof(avci100_720p_extradata);
1707  } else if (st->codecpar->width == 960) {
1708  data = avci50_720p_extradata;
1709  size = sizeof(avci50_720p_extradata);
1710  }
1711 
1712  if (!size)
1713  return 0;
1714 
1715  if ((ret = ff_alloc_extradata(st->codecpar, size)) < 0)
1716  return ret;
1717  memcpy(st->codecpar->extradata, data, size);
1718 
1719  return 0;
1720 }
1721 
1723  enum AVPacketSideDataType type, size_t *size)
1724 {
1725  for (int i = 0; i < st->nb_side_data; i++) {
1726  if (st->side_data[i].type == type) {
1727  if (size)
1728  *size = st->side_data[i].size;
1729  return st->side_data[i].data;
1730  }
1731  }
1732  if (size)
1733  *size = 0;
1734  return NULL;
1735 }
1736 
1738  uint8_t *data, size_t size)
1739 {
1740  AVPacketSideData *sd, *tmp;
1741 
1742  for (int i = 0; i < st->nb_side_data; i++) {
1743  sd = &st->side_data[i];
1744 
1745  if (sd->type == type) {
1746  av_freep(&sd->data);
1747  sd->data = data;
1748  sd->size = size;
1749  return 0;
1750  }
1751  }
1752 
1753  if ((unsigned)st->nb_side_data + 1 >= INT_MAX / sizeof(*st->side_data))
1754  return AVERROR(ERANGE);
1755 
1756  tmp = av_realloc(st->side_data, (st->nb_side_data + 1) * sizeof(*tmp));
1757  if (!tmp) {
1758  return AVERROR(ENOMEM);
1759  }
1760 
1761  st->side_data = tmp;
1762  st->nb_side_data++;
1763 
1764  sd = &st->side_data[st->nb_side_data - 1];
1765  sd->type = type;
1766  sd->data = data;
1767  sd->size = size;
1768 
1769  return 0;
1770 }
1771 
1773  size_t size)
1774 {
1775  int ret;
1776  uint8_t *data = av_malloc(size);
1777 
1778  if (!data)
1779  return NULL;
1780 
1782  if (ret < 0) {
1783  av_freep(&data);
1784  return NULL;
1785  }
1786 
1787  return data;
1788 }
1789 
1790 int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
1791 {
1792  int ret;
1793  const AVBitStreamFilter *bsf;
1794  FFStream *const sti = ffstream(st);
1795  AVBSFContext *bsfc;
1796 
1797  av_assert0(!sti->bsfc);
1798 
1799  if (!(bsf = av_bsf_get_by_name(name))) {
1800  av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter '%s'\n", name);
1801  return AVERROR_BSF_NOT_FOUND;
1802  }
1803 
1804  if ((ret = av_bsf_alloc(bsf, &bsfc)) < 0)
1805  return ret;
1806 
1807  bsfc->time_base_in = st->time_base;
1808  if ((ret = avcodec_parameters_copy(bsfc->par_in, st->codecpar)) < 0) {
1809  av_bsf_free(&bsfc);
1810  return ret;
1811  }
1812 
1813  if (args && bsfc->filter->priv_class) {
1814  if ((ret = av_set_options_string(bsfc->priv_data, args, "=", ":")) < 0) {
1815  av_bsf_free(&bsfc);
1816  return ret;
1817  }
1818  }
1819 
1820  if ((ret = av_bsf_init(bsfc)) < 0) {
1821  av_bsf_free(&bsfc);
1822  return ret;
1823  }
1824 
1825  sti->bsfc = bsfc;
1826 
1828  "Automatically inserted bitstream filter '%s'; args='%s'\n",
1829  name, args ? args : "");
1830  return 1;
1831 }
1832 
1834 {
1835  if (!s->oformat)
1836  return AVERROR(EINVAL);
1837 
1838  if (!(s->oformat->flags & AVFMT_NOFILE))
1839  return s->io_open(s, &s->pb, url, AVIO_FLAG_WRITE, options);
1840  return 0;
1841 }
1842 
1844 {
1845  avio_close(pb);
1846 }
1847 
1849 {
1850  int ret = 0;
1851  if (*pb) {
1852  if (s->io_close == ff_format_io_close_default || s->io_close == NULL)
1853  ret = s->io_close2(s, *pb);
1854  else
1855  s->io_close(s, *pb);
1856  }
1857  *pb = NULL;
1858  return ret;
1859 }
1860 
1861 int ff_is_http_proto(const char *filename) {
1862  const char *proto = avio_find_protocol_name(filename);
1863  return proto ? (!av_strcasecmp(proto, "http") || !av_strcasecmp(proto, "https")) : 0;
1864 }
1865 
1866 int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds)
1867 {
1868  AVDictionaryEntry *entry;
1869  int64_t parsed_timestamp;
1870  int ret;
1871  if ((entry = av_dict_get(s->metadata, "creation_time", NULL, 0))) {
1872  if ((ret = av_parse_time(&parsed_timestamp, entry->value, 0)) >= 0) {
1873  *timestamp = return_seconds ? parsed_timestamp / 1000000 : parsed_timestamp;
1874  return 1;
1875  } else {
1876  av_log(s, AV_LOG_WARNING, "Failed to parse creation_time %s\n", entry->value);
1877  return ret;
1878  }
1879  }
1880  return 0;
1881 }
1882 
1884 {
1885  int64_t timestamp;
1886  int ret = ff_parse_creation_time_metadata(s, &timestamp, 0);
1887  if (ret == 1)
1888  return avpriv_dict_set_timestamp(&s->metadata, "creation_time", timestamp);
1889  return ret;
1890 }
1891 
1892 int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t *palette)
1893 {
1894  uint8_t *side_data;
1895  size_t size;
1896 
1898  if (side_data) {
1899  if (size != AVPALETTE_SIZE) {
1900  av_log(s, AV_LOG_ERROR, "Invalid palette side data\n");
1901  return AVERROR_INVALIDDATA;
1902  }
1903  memcpy(palette, side_data, AVPALETTE_SIZE);
1904  return 1;
1905  }
1906 
1907  if (ret == CONTAINS_PAL) {
1908  for (int i = 0; i < AVPALETTE_COUNT; i++)
1909  palette[i] = AV_RL32(pkt->data + pkt->size - AVPALETTE_SIZE + i*4);
1910  return 1;
1911  }
1912 
1913  return 0;
1914 }
1915 
1917 {
1918  int ret;
1919  char *str;
1920 
1921  ret = av_bprint_finalize(buf, &str);
1922  if (ret < 0)
1923  return ret;
1924  if (!av_bprint_is_complete(buf)) {
1925  av_free(str);
1926  return AVERROR(ENOMEM);
1927  }
1928 
1929  par->extradata = str;
1930  /* Note: the string is NUL terminated (so extradata can be read as a
1931  * string), but the ending character is not accounted in the size (in
1932  * binary formats you are likely not supposed to mux that character). When
1933  * extradata is copied, it is also padded with AV_INPUT_BUFFER_PADDING_SIZE
1934  * zeros. */
1935  par->extradata_size = buf->len;
1936  return 0;
1937 }
1938 
1940  AVStream *ost, const AVStream *ist,
1942 {
1943  const AVCodecContext *const dec_ctx = cffstream(ist)->avctx;
1944  AVCodecContext *const enc_ctx = ffstream(ost)->avctx;
1945 
1946  enc_ctx->time_base = ist->time_base;
1947  /*
1948  * Avi is a special case here because it supports variable fps but
1949  * having the fps and timebase differe significantly adds quite some
1950  * overhead
1951  */
1952  if (!strcmp(ofmt->name, "avi")) {
1953 #if FF_API_R_FRAME_RATE
1954  if (copy_tb == AVFMT_TBCF_AUTO && ist->r_frame_rate.num
1955  && av_q2d(ist->r_frame_rate) >= av_q2d(ist->avg_frame_rate)
1956  && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(ist->time_base)
1957  && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(dec_ctx->time_base)
1958  && av_q2d(ist->time_base) < 1.0/500 && av_q2d(dec_ctx->time_base) < 1.0/500
1959  || copy_tb == AVFMT_TBCF_R_FRAMERATE) {
1960  enc_ctx->time_base.num = ist->r_frame_rate.den;
1961  enc_ctx->time_base.den = 2*ist->r_frame_rate.num;
1962  enc_ctx->ticks_per_frame = 2;
1963  } else
1964 #endif
1966  && av_q2d(ist->time_base) < 1.0/500
1967  || copy_tb == AVFMT_TBCF_DECODER) {
1968  enc_ctx->time_base = dec_ctx->time_base;
1969  enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
1970  enc_ctx->time_base.den *= 2;
1971  enc_ctx->ticks_per_frame = 2;
1972  }
1973  } else if (!(ofmt->flags & AVFMT_VARIABLE_FPS)
1974  && !av_match_name(ofmt->name, "mov,mp4,3gp,3g2,psp,ipod,ismv,f4v")) {
1977  && av_q2d(ist->time_base) < 1.0/500
1978  || copy_tb == AVFMT_TBCF_DECODER) {
1979  enc_ctx->time_base = dec_ctx->time_base;
1980  enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
1981  }
1982  }
1983 
1984  if ((enc_ctx->codec_tag == AV_RL32("tmcd") || ost->codecpar->codec_tag == AV_RL32("tmcd"))
1986  && dec_ctx->time_base.num > 0
1987  && 121LL*dec_ctx->time_base.num > dec_ctx->time_base.den) {
1988  enc_ctx->time_base = dec_ctx->time_base;
1989  }
1990 
1991  av_reduce(&enc_ctx->time_base.num, &enc_ctx->time_base.den,
1992  enc_ctx->time_base.num, enc_ctx->time_base.den, INT_MAX);
1993 
1994  return 0;
1995 }
1996 
1998 {
1999  // See avformat_transfer_internal_stream_timing_info() TODO.
2000  return cffstream(st)->avctx->time_base;
2001 }
2002 
2004 {
2005  av_assert0(url);
2006  av_freep(&s->url);
2007  s->url = url;
2008 }
2009 
2010 static int option_is_disposition(const AVOption *opt)
2011 {
2012  return opt->type == AV_OPT_TYPE_CONST &&
2013  opt->unit && !strcmp(opt->unit, "disposition");
2014 }
2015 
2016 int av_disposition_from_string(const char *disp)
2017 {
2018  for (const AVOption *opt = stream_options; opt->name; opt++)
2019  if (option_is_disposition(opt) && !strcmp(disp, opt->name))
2020  return opt->default_val.i64;
2021  return AVERROR(EINVAL);
2022 }
2023 
2024 const char *av_disposition_to_string(int disposition)
2025 {
2026  int val;
2027 
2028  if (disposition <= 0)
2029  return NULL;
2030 
2031  val = 1 << ff_ctz(disposition);
2032  for (const AVOption *opt = stream_options; opt->name; opt++)
2033  if (option_is_disposition(opt) && opt->default_val.i64 == val)
2034  return opt->name;
2035 
2036  return NULL;
2037 }
2038 
2039 int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size)
2040 {
2041  int ret;
2042  int64_t pos, pos_end;
2043  uint8_t *buf, *read_buf[2];
2044  int read_buf_id = 0;
2045  int read_size[2];
2046  AVIOContext *read_pb;
2047 
2048  buf = av_malloc_array(shift_size, 2);
2049  if (!buf)
2050  return AVERROR(ENOMEM);
2051  read_buf[0] = buf;
2052  read_buf[1] = buf + shift_size;
2053 
2054  /* Shift the data: the AVIO context of the output can only be used for
2055  * writing, so we re-open the same output, but for reading. It also avoids
2056  * a read/seek/write/seek back and forth. */
2057  avio_flush(s->pb);
2058  ret = s->io_open(s, &read_pb, s->url, AVIO_FLAG_READ, NULL);
2059  if (ret < 0) {
2060  av_log(s, AV_LOG_ERROR, "Unable to re-open %s output file for shifting data\n", s->url);
2061  goto end;
2062  }
2063 
2064  /* mark the end of the shift to up to the last data we wrote, and get ready
2065  * for writing */
2066  pos_end = avio_tell(s->pb);
2067  avio_seek(s->pb, read_start + shift_size, SEEK_SET);
2068 
2069  avio_seek(read_pb, read_start, SEEK_SET);
2070  pos = avio_tell(read_pb);
2071 
2072 #define READ_BLOCK do { \
2073  read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id], shift_size); \
2074  read_buf_id ^= 1; \
2075 } while (0)
2076 
2077  /* shift data by chunk of at most shift_size */
2078  READ_BLOCK;
2079  do {
2080  int n;
2081  READ_BLOCK;
2082  n = read_size[read_buf_id];
2083  if (n <= 0)
2084  break;
2085  avio_write(s->pb, read_buf[read_buf_id], n);
2086  pos += n;
2087  } while (pos < pos_end);
2088  ret = ff_format_io_close(s, &read_pb);
2089 
2090 end:
2091  av_free(buf);
2092  return ret;
2093 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
AV_CODEC_ID_PCM_S16LE
@ AV_CODEC_ID_PCM_S16LE
Definition: codec_id.h:314
ost
OutputStream * ost
Definition: ffmpeg_filter.c:160
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:424
be
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 be(in the first position) for now. Options ------- Then comes the options array. This is what will define the user accessible options. For example
AVCodec
AVCodec.
Definition: codec.h:202
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:83
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
ff_codec_get_id
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:357
AVBSFContext::par_in
AVCodecParameters * par_in
Parameters of the input stream.
Definition: bsf.h:69
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_CODEC_ID_PCM_F32BE
@ AV_CODEC_ID_PCM_F32BE
Definition: codec_id.h:334
avpriv_packet_list_put
int avpriv_packet_list_put(PacketList *packet_buffer, AVPacket *pkt, int(*copy)(AVPacket *dst, const AVPacket *src), int flags)
Append an AVPacket to the list.
Definition: avpacket.c:538
ff_data_to_hex
char * ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase)
Write hexadecimal string corresponding to given binary data.
Definition: utils.c:1147
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:74
name
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 default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
FFStream::inject_global_side_data
int inject_global_side_data
Internal data to inject global side data.
Definition: internal.h:380
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
LIBAVFORMAT_VERSION_INT
#define LIBAVFORMAT_VERSION_INT
Definition: version.h:38
AVOutputFormat::name
const char * name
Definition: avformat.h:504
AVChapter::metadata
AVDictionary * metadata
Definition: avformat.h:1163
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: utils.c:768
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
ff_lock_avformat
int ff_lock_avformat(void)
Definition: utils.c:77
av_codec_get_tag2
int av_codec_get_tag2(const AVCodecTag *const *tags, enum AVCodecID id, unsigned int *tag)
Definition: utils.c:425
AVProgram::nb_stream_indexes
unsigned int nb_stream_indexes
Definition: avformat.h:1129
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:234
ff_mkdir_p
int ff_mkdir_p(const char *path)
Automatically create sub-directories.
Definition: utils.c:1113
avio_close
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1252
FFStream::first_dts
int64_t first_dts
Timestamp corresponding to the last dts sync point.
Definition: internal.h:428
ff_ctz
#define ff_ctz
Definition: intmath.h:106
ff_ntp_time
uint64_t ff_ntp_time(void)
Get the current time since NTP epoch in microseconds.
Definition: utils.c:951
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
AV_PKT_DATA_PARAM_CHANGE
@ AV_PKT_DATA_PARAM_CHANGE
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
Definition: packet.h:72
ffiocontext
static av_always_inline FFIOContext * ffiocontext(AVIOContext *ctx)
Definition: avio_internal.h:82
FFStream::last_IP_pts
int64_t last_IP_pts
Definition: internal.h:396
ffformatcontext
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition: internal.h:189
thread.h
AVStream::priv_data
void * priv_data
Definition: avformat.h:951
AVFMT_VARIABLE_FPS
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:478
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:873
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:997
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: utils.c:485
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:1772
AVFMT_TBCF_DECODER
@ AVFMT_TBCF_DECODER
Definition: avformat.h:2859
av_stream_get_parser
struct AVCodecParserContext * av_stream_get_parser(const AVStream *st)
Definition: utils.c:95
AVCodecTag::id
enum AVCodecID id
Definition: internal.h:52
av_grow_packet
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
Definition: avpacket.c:122
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:215
av_isspace
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
Definition: avstring.h:227
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:820
av_bsf_init
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition: bsf.c:145
AVFMT_TBCF_AUTO
@ AVFMT_TBCF_AUTO
Definition: avformat.h:2858
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
ff_format_io_close
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: utils.c:1848
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1268
index
fg index
Definition: ffmpeg_filter.c:167
AVPacketSideData
Definition: packet.h:314
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:373
option_is_disposition
static int option_is_disposition(const AVOption *opt)
Definition: utils.c:2010
av_get_frame_filename2
int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags)
Return in 'buf' the path with 'd' replaced by a number.
Definition: utils.c:987
AVOption
AVOption.
Definition: opt.h:247
ist
ifilter ist
Definition: ffmpeg_filter.c:177
AV_PKT_DATA_PALETTE
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
Definition: packet.h:46
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:1015
AVChapter::start
int64_t start
Definition: avformat.h:1162
data
const char data[16]
Definition: mxf.c:143
AV_CODEC_ID_PCM_U24LE
@ AV_CODEC_ID_PCM_U24LE
Definition: codec_id.h:328
FFFormatContext::initialized
int initialized
Whether or not avformat_init_output has already been called.
Definition: internal.h:166
stream_class
static const AVClass stream_class
Definition: utils.c:756
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:61
AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
@ AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
Definition: packet.h:452
ff_toupper4
unsigned int ff_toupper4(unsigned int x)
Definition: to_upper4.h:29
LICENSE_PREFIX
#define LICENSE_PREFIX
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
FFStream::fps_last_dts
int64_t fps_last_dts
Definition: internal.h:272
LIBAVFORMAT_VERSION_MICRO
#define LIBAVFORMAT_VERSION_MICRO
Definition: version.h:36
FFStream::bsfc
AVBSFContext * bsfc
bitstream filter to run on stream
Definition: internal.h:211
AVFormatContext::programs
AVProgram ** programs
Definition: avformat.h:1369
FFStream::extract_extradata
struct FFStream::@259 extract_extradata
avpriv_new_chapter
AVChapter * avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, int64_t start, int64_t end, const char *title)
Add a new chapter.
Definition: utils.c:883
AVDictionary
Definition: dict.c:30
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
ff_network_close
void ff_network_close(void)
Definition: network.c:116
AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT
@ AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT
Definition: packet.h:451
cffstream
static const av_always_inline FFStream * cffstream(const AVStream *st)
Definition: internal.h:437
FFStream::last_dts_for_order_check
int64_t last_dts_for_order_check
Internal data to analyze DTS and detect faulty mpeg streams.
Definition: internal.h:373
av_get_frame_filename
int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
Definition: utils.c:1045
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:428
sample_rate
sample_rate
Definition: ffmpeg_filter.c:153
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:75
AVBSFContext
The bitstream filter state.
Definition: bsf.h:47
ff_find_stream_index
int ff_find_stream_index(const AVFormatContext *s, int id)
Find stream index based on format-specific stream ID.
Definition: utils.c:1276
ff_network_init
int ff_network_init(void)
Definition: network.c:58
ff_tls_init
int ff_tls_init(void)
Definition: network.c:31
AVOutputFormat::subtitle_codec
enum AVCodecID subtitle_codec
default subtitle codec
Definition: avformat.h:516
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
FFStream::bsf
AVBSFContext * bsf
Definition: internal.h:231
ff_free_stream
void ff_free_stream(AVFormatContext *s, AVStream *st)
Definition: utils.c:680
av_bsf_get_by_name
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
Definition: bitstream_filters.c:78
av_filename_number_test
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
Definition: utils.c:220
AV_CODEC_ID_PCM_S64LE
@ AV_CODEC_ID_PCM_S64LE
Definition: codec_id.h:345
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:311
ff_mutex_unlock
static int ff_mutex_unlock(AVMutex *mutex)
Definition: thread.h:169
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: utils.c:500
avformat_queue_attached_pictures
int avformat_queue_attached_pictures(AVFormatContext *s)
Definition: utils.c:227
av_set_options_string
int av_set_options_string(void *ctx, const char *opts, const char *key_val_sep, const char *pairs_sep)
Parse the key/value pairs list in opts.
Definition: opt.c:1485
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:1710
AVPacketSideData::size
size_t size
Definition: packet.h:316
ff_stream_encode_params_copy
int ff_stream_encode_params_copy(AVStream *dst, const AVStream *src)
Copy encoding parameters from source to destination stream.
Definition: utils.c:586
AVCodecParameters::channels
int channels
Audio only.
Definition: codec_par.h:166
decoder
static const chunk_decoder decoder[8]
Definition: dfa.c:330
READ_BLOCK
#define READ_BLOCK
RELATIVE_TS_BASE
#define RELATIVE_TS_BASE
Definition: internal.h:459
bsf.h
av_stream_get_end_pts
int64_t av_stream_get_end_pts(const AVStream *st)
Returns the pts of the last muxed packet + its duration.
Definition: utils.c:87
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:432
AV_CODEC_ID_PCM_S16BE
@ AV_CODEC_ID_PCM_S16BE
Definition: codec_id.h:315
fail
#define fail()
Definition: checkasm.h:127
av_shrink_packet
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition: avpacket.c:114
avformat_version
unsigned avformat_version(void)
Return the LIBAVFORMAT_VERSION_INT constant.
Definition: utils.c:60
AVStreamParseType
AVStreamParseType
Definition: avformat.h:790
AV_DISPOSITION_STILL_IMAGE
#define AV_DISPOSITION_STILL_IMAGE
The video stream contains still images.
Definition: avformat.h:905
free_stream
static void free_stream(AVStream **pst)
Definition: utils.c:644
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:504
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: defs.h:48
AVChapter
Definition: avformat.h:1159
val
static double val(void *priv, double ch)
Definition: aeval.c:76
AV_DISPOSITION_FORCED
#define AV_DISPOSITION_FORCED
Track should be used during playback by default.
Definition: avformat.h:853
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_DISPOSITION_TIMED_THUMBNAILS
#define AV_DISPOSITION_TIMED_THUMBNAILS
The stream is sparse, and contains thumbnail images, often corresponding to chapter markers.
Definition: avformat.h:878
av_new_program
AVProgram * av_new_program(AVFormatContext *ac, int id)
Definition: utils.c:852
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:985
AV_PTS_WRAP_IGNORE
#define AV_PTS_WRAP_IGNORE
Options for behavior on timestamp wrap detection.
Definition: avformat.h:924
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
ff_get_packet_palette
int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t *palette)
Retrieves the palette from a packet, either from side data, or appended to the video data in the pack...
Definition: utils.c:1892
avformat_network_init
int avformat_network_init(void)
Do global initialization of network libraries.
Definition: utils.c:1302
SPACE_CHARS
#define SPACE_CHARS
Definition: dnn_backend_tf.c:359
AVStream::attached_pic
AVPacket attached_pic
For streams with AV_DISPOSITION_ATTACHED_PIC disposition, this packet will contain the attached pictu...
Definition: avformat.h:1024
FFStream::priv_pts
FFFrac * priv_pts
Definition: internal.h:242
AV_DISPOSITION_CLEAN_EFFECTS
#define AV_DISPOSITION_CLEAN_EFFECTS
The audio stream contains music and sound effects without voice.
Definition: avformat.h:865
av_init_packet
void av_init_packet(AVPacket *pkt)
Definition: avpacket.c:37
AV_CODEC_ID_PCM_S8
@ AV_CODEC_ID_PCM_S8
Definition: codec_id.h:318
avassert.h
AVFormatContext::format_whitelist
char * format_whitelist
',' separated list of allowed demuxers.
Definition: avformat.h:1652
av_codec_get_tag
unsigned int av_codec_get_tag(const AVCodecTag *const *tags, enum AVCodecID id)
Definition: utils.c:417
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: utils.c:1365
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AV_PKT_FLAG_CORRUPT
#define AV_PKT_FLAG_CORRUPT
The packet content is corrupted.
Definition: packet.h:429
FFStream::info
struct FFStream::@260 * info
Stream information used internally by avformat_find_stream_info()
ff_add_param_change
int ff_add_param_change(AVPacket *pkt, int32_t channels, uint64_t channel_layout, int32_t sample_rate, int32_t width, int32_t height)
Add side data to a packet for changing parameters to the given values.
Definition: utils.c:1323
AVCodecTag
Definition: internal.h:51
AVOutputFormat::data_codec
enum AVCodecID data_codec
default data codec
Definition: avformat.h:611
AVProgram::id
int id
Definition: avformat.h:1125
AVMutex
#define AVMutex
Definition: thread.h:164
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:40
avformat_query_codec
int avformat_query_codec(const AVOutputFormat *ofmt, enum AVCodecID codec_id, int std_compliance)
Test if the given container can store a codec.
Definition: utils.c:1284
AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
@ AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
Definition: packet.h:453
FFFormatContext::parse_queue
PacketList parse_queue
Packets split by the parser get queued here.
Definition: internal.h:111
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:141
AVChapter::end
int64_t end
chapter start/end time in time_base units
Definition: avformat.h:1162
AVCodecDescriptor
This struct describes the properties of a single codec described by an AVCodecID.
Definition: codec_desc.h:38
FFStream::duration_error
double(* duration_error)[2][MAX_STD_TIMEBASES]
Definition: internal.h:253
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:277
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:96
height
static int height
Definition: utils.c:158
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:224
AVCodecParameters::sample_aspect_ratio
AVRational sample_aspect_ratio
Video only.
Definition: codec_par.h:136
AVFormatContext::nb_programs
unsigned int nb_programs
Definition: avformat.h:1368
av_append_packet
int av_append_packet(AVIOContext *s, AVPacket *pkt, int size)
Read data and append it to the current content of the AVPacket.
Definition: utils.c:213
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:449
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:126
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:515
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
AVOutputFormat::audio_codec
enum AVCodecID audio_codec
default audio codec
Definition: avformat.h:514
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:622
av_read_play
int av_read_play(AVFormatContext *s)
Start playing a network-based stream (e.g.
Definition: utils.c:568
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:315
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:411
channels
channels
Definition: aptx.h:33
AVBSFContext::time_base_in
AVRational time_base_in
The timebase used for the timestamps of the input packets.
Definition: bsf.h:81
nb_streams
static int nb_streams
Definition: ffprobe.c:297
ff_add_attached_pic
int ff_add_attached_pic(AVFormatContext *s, AVStream *st0, AVIOContext *pb, AVBufferRef **buf, int size)
Add an attached pic to an AVStream.
Definition: utils.c:250
AV_CODEC_ID_PCM_U16BE
@ AV_CODEC_ID_PCM_U16BE
Definition: codec_id.h:317
AVOutputFormat::codec_tag
const struct AVCodecTag *const * codec_tag
List of supported codec_id-codec_tag pairs, ordered by "better choice first".
Definition: avformat.h:529
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:369
key
const char * key
Definition: hwcontext_opencl.c:168
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
ff_hex_to_data
int ff_hex_to_data(uint8_t *data, const char *p)
Parse a string of hexadecimal strings.
Definition: utils.c:1168
FFFormatContext
Definition: internal.h:73
avio_flush
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:252
FFStream::need_parsing
enum AVStreamParseType need_parsing
Definition: internal.h:405
av_disposition_from_string
int av_disposition_from_string(const char *disp)
Definition: utils.c:2016
context
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 default minimum maximum flags name is the option keep it simple and lowercase description are in without and describe what they for example set the foo of the bar offset is the offset of the field in your context
Definition: writing_filters.txt:91
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:54
AVFormatContext
Format I/O context.
Definition: avformat.h:1200
FFStream::pub
AVStream pub
The public context.
Definition: internal.h:198
AV_CODEC_PROP_INTRA_ONLY
#define AV_CODEC_PROP_INTRA_ONLY
Codec uses only intra compression.
Definition: codec_desc.h:72
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:356
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1095
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
ff_format_output_open
int ff_format_output_open(AVFormatContext *s, const char *url, AVDictionary **options)
Utility function to open IO stream of output format.
Definition: utils.c:1833
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
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:965
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:152
AV_CODEC_ID_PCM_U24BE
@ AV_CODEC_ID_PCM_U24BE
Definition: codec_id.h:329
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:156
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_CODEC_ID_PCM_U32BE
@ AV_CODEC_ID_PCM_U32BE
Definition: codec_id.h:325
AVFormatContext::protocol_whitelist
char * protocol_whitelist
',' separated list of allowed protocols.
Definition: avformat.h:1737
AVPacketSideData::type
enum AVPacketSideDataType type
Definition: packet.h:317
AV_DISPOSITION_COMMENT
#define AV_DISPOSITION_COMMENT
The stream is a commentary track.
Definition: avformat.h:838
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: utils.c:1737
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
src
#define src
Definition: vp8dsp.c:255
AVERROR_BSF_NOT_FOUND
#define AVERROR_BSF_NOT_FOUND
Bitstream filter not found.
Definition: error.h:51
AV_CODEC_ID_PCM_S64BE
@ AV_CODEC_ID_PCM_S64BE
Definition: codec_id.h:346
avpriv_stream_set_need_parsing
void avpriv_stream_set_need_parsing(AVStream *st, enum AVStreamParseType type)
Definition: utils.c:100
parseutils.h
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: utils.c:1196
AVProgram::stream_index
unsigned int * stream_index
Definition: avformat.h:1128
AVBitStreamFilter::priv_class
const AVClass * priv_class
A class for the private data, used to declare bitstream filter private AVOptions.
Definition: bsf.h:109
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:1006
AV_DISPOSITION_METADATA
#define AV_DISPOSITION_METADATA
The subtitle stream contains time-aligned metadata that is not intended to be directly presented to t...
Definition: avformat.h:895
stream_options
static const AVOption stream_options[]
Definition: utils.c:733
avio_pause
int avio_pause(AVIOContext *h, int pause)
Pause and resume playing - only meaningful if using a network streaming protocol (e....
Definition: aviobuf.c:1317
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1617
ff_parse_key_value
void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf, void *context)
Parse a string with comma-separated key=value pairs.
Definition: utils.c:1222
av_parse_time
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
Definition: parseutils.c:589
time.h
ff_get_formatted_ntp_time
uint64_t ff_get_formatted_ntp_time(uint64_t ntp_time_us)
Get the NTP time stamp formatted as per the RFC-5905.
Definition: utils.c:956
AV_DISPOSITION_ORIGINAL
#define AV_DISPOSITION_ORIGINAL
The stream is in original language.
Definition: avformat.h:834
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:432
FFFormatContext::inject_global_side_data
int inject_global_side_data
Definition: internal.h:154
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVPALETTE_COUNT
#define AVPALETTE_COUNT
Definition: pixfmt.h:33
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:170
ff_get_extradata
int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, AVIOContext *pb, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0 and f...
Definition: utils.c:469
av_bprint_is_complete
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:185
AVStream::nb_frames
int64_t nb_frames
number of frames in this stream if known or 0
Definition: avformat.h:987
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:47
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:921
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:78
FFStream::fps_first_dts
int64_t fps_first_dts
Those are used for average framerate estimation.
Definition: internal.h:270
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1256
FFFormatContext::id3v2_meta
AVDictionary * id3v2_meta
ID3v2 tag useful for MP3 demuxing.
Definition: internal.h:176
AVOutputFormat::flags
int flags
can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:523
av_strncasecmp
int av_strncasecmp(const char *a, const char *b, size_t n)
Locale-independent case-insensitive compare.
Definition: avstring.c:225
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:506
options
const OptionDef options[]
AV_DISPOSITION_CAPTIONS
#define AV_DISPOSITION_CAPTIONS
The subtitle stream contains captions, providing a transcription and possibly a translation of audio.
Definition: avformat.h:884
ff_standardize_creation_time
int ff_standardize_creation_time(AVFormatContext *s)
Standardize creation_time metadata in AVFormatContext to an ISO-8601 timestamp string.
Definition: utils.c:1883
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
AV_CODEC_ID_PCM_S24LE
@ AV_CODEC_ID_PCM_S24LE
Definition: codec_id.h:326
AVMediaType
AVMediaType
Definition: avutil.h:199
AVPacket::size
int size
Definition: packet.h:374
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: utils.c:1543
id
enum AVCodecID id
Definition: extract_extradata_bsf.c:325
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:125
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:591
FFFrac::val
int64_t val
Definition: internal.h:69
FFStream
Definition: internal.h:194
ff_copy_whiteblacklists
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
Copies the whilelists from one context to the other.
Definition: utils.c:115
bps
unsigned bps
Definition: movenc.c:1597
AVCodecContext::pkt_timebase
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are.
Definition: avcodec.h:1724
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
AV_MUTEX_INITIALIZER
#define AV_MUTEX_INITIALIZER
Definition: thread.h:165
ff_get_pcm_codec_id
enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags)
Select a PCM codec based on the given parameters.
Definition: utils.c:368
size
int size
Definition: twinvq_data.h:10344
copy_tb
int copy_tb
Definition: ffmpeg_opt.c:158
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
NTP_OFFSET_US
#define NTP_OFFSET_US
Definition: internal.h:519
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: utils.c:1388
av_stream_get_codec_timebase
AVRational av_stream_get_codec_timebase(const AVStream *st)
Get the internal codec timebase from a stream.
Definition: utils.c:1997
format
ofilter format
Definition: ffmpeg_filter.c:172
ff_is_intra_only
int ff_is_intra_only(enum AVCodecID id)
Definition: utils.c:287
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:464
AV_DISPOSITION_DUB
#define AV_DISPOSITION_DUB
The stream is not in original language.
Definition: avformat.h:828
AVTimebaseSource
AVTimebaseSource
Definition: avformat.h:2857
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
AVOption::name
const char * name
Definition: opt.h:248
ff_unlock_avformat
int ff_unlock_avformat(void)
Definition: utils.c:82
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:1004
ff_stream_add_bitstream_filter
int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
Add a bitstream filter to a stream.
Definition: utils.c:1790
AV_DISPOSITION_HEARING_IMPAIRED
#define AV_DISPOSITION_HEARING_IMPAIRED
The stream is intended for hearing impaired audiences.
Definition: avformat.h:857
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:232
av_isdigit
static av_const int av_isdigit(int c)
Locale-independent conversion of ASCII isdigit.
Definition: avstring.h:211
av_format_inject_global_side_data
void av_format_inject_global_side_data(AVFormatContext *s)
This function will cause global side data to be injected in the next packet of each stream as well as...
Definition: utils.c:105
FFStream::pts_wrap_behavior
int pts_wrap_behavior
Options for behavior, when a wrap is detected.
Definition: internal.h:353
AVPacketSideDataType
AVPacketSideDataType
Definition: packet.h:40
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:136
ff_mutex_lock
static int ff_mutex_lock(AVMutex *mutex)
Definition: thread.h:168
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:379
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:203
bitrate
int64_t bitrate
Definition: h264_levels.c:131
FFStream::probe_packets
int probe_packets
Number of packets to buffer for codec probing.
Definition: internal.h:402
AV_FRAME_FILENAME_FLAGS_MULTIPLE
#define AV_FRAME_FILENAME_FLAGS_MULTIPLE
Allow multiple d.
Definition: avformat.h:2707
FFStream::probe_data
AVProbeData probe_data
Definition: internal.h:389
AVStream::side_data
AVPacketSideData * side_data
An array of side data that applies to the whole stream (i.e.
Definition: avformat.h:1044
SANE_CHUNK_SIZE
#define SANE_CHUNK_SIZE
Definition: utils.c:154
ffio_limit
int ffio_limit(AVIOContext *s, int size)
Definition: aviobuf.c:1090
ff_format_shift_data
int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size)
Make shift_size amount of space at read_start by shifting data in the output at read_start until the ...
Definition: utils.c:2039
avcodec_parameters_copy
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: codec_par.c:72
MAX_REORDER_DELAY
@ MAX_REORDER_DELAY
Definition: vaapi_encode.h:44
FFFormatContext::raw_packet_buffer
PacketList raw_packet_buffer
Raw packets from the demuxer, prior to parsing and decoding.
Definition: internal.h:107
bprint.h
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:48
AVOutputFormat
Definition: avformat.h:503
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
avio_internal.h
width
static int width
Definition: utils.c:158
AVChapter::id
int64_t id
unique ID to identify the chapter
Definition: avformat.h:1160
av_disposition_to_string
const char * av_disposition_to_string(int disposition)
Definition: utils.c:2024
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition: avpacket.c:253
internal.h
AVCodecParameters::height
int height
Definition: codec_par.h:127
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
AVFormatContext::codec_whitelist
char * codec_whitelist
',' separated list of allowed decoders.
Definition: avformat.h:1644
avformat_mutex
static AVMutex avformat_mutex
Definition: utils.c:53
AV_CODEC_ID_PCM_F64BE
@ AV_CODEC_ID_PCM_F64BE
Definition: codec_id.h:336
AV_DISPOSITION_KARAOKE
#define AV_DISPOSITION_KARAOKE
The stream contains karaoke audio.
Definition: avformat.h:846
av_toupper
static av_const int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
Definition: avstring.h:236
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:205
av_url_split
void av_url_split(char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
Split a URL string into components.
Definition: utils.c:1050
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV_CODEC_ID_PCM_S32BE
@ AV_CODEC_ID_PCM_S32BE
Definition: codec_id.h:323
FFStream::pts_buffer
int64_t pts_buffer[MAX_REORDER_DELAY+1]
Definition: internal.h:368
av_find_default_stream_index
int av_find_default_stream_index(AVFormatContext *s)
Definition: utils.c:309
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:263
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1124
avcodec_parameters_alloc
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: codec_par.c:51
AV_DISPOSITION_DEPENDENT
#define AV_DISPOSITION_DEPENDENT
The audio stream is intended to be mixed with another stream before presentation.
Definition: avformat.h:901
len
int len
Definition: vorbis_enc_data.h:426
av_read_pause
int av_read_pause(AVFormatContext *s)
Pause a network-based stream (e.g.
Definition: utils.c:577
av_get_packet
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition: utils.c:197
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:271
AVCodecParameters::field_order
enum AVFieldOrder field_order
Video only.
Definition: codec_par.h:141
ff_find_decoder
const AVCodec * ff_find_decoder(AVFormatContext *s, const AVStream *st, enum AVCodecID codec_id)
Definition: utils.c:135
AVCodecParserContext
Definition: avcodec.h:2775
AVBSFContext::priv_data
void * priv_data
Opaque filter-specific private data.
Definition: bsf.h:62
ff_tls_deinit
void ff_tls_deinit(void)
Definition: network.c:46
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:995
AV_DISPOSITION_VISUAL_IMPAIRED
#define AV_DISPOSITION_VISUAL_IMPAIRED
The stream is intended for visually impaired audiences.
Definition: avformat.h:861
tag
uint32_t tag
Definition: movenc.c:1596
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:949
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:935
pixfmt.h
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:260
ff_is_http_proto
int ff_is_http_proto(const char *filename)
Utility function to check if the file uses http or https protocol.
Definition: utils.c:1861
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
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:1048
ff_bprint_to_codecpar_extradata
int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf)
Finalize buf into extradata and set its size appropriately.
Definition: utils.c:1916
lowercase
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 default minimum maximum flags name is the option keep it simple and lowercase description are in lowercase
Definition: writing_filters.txt:89
pos
unsigned int pos
Definition: spdifenc.c:412
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: utils.c:1722
dict.h
AVOption::type
enum AVOptionType type
Definition: opt.h:261
network.h
AV_DISPOSITION_DESCRIPTIONS
#define AV_DISPOSITION_DESCRIPTIONS
The subtitle stream contains a textual description of the video content.
Definition: avformat.h:890
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
FFFormatContext::chapter_ids_monotonic
int chapter_ids_monotonic
Set if chapter ids are strictly monotonic.
Definition: internal.h:186
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
avformat_network_deinit
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
Definition: utils.c:1314
av_program_add_stream_index
void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
Definition: utils.c:924
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:322
AVCodecContext
main external API structure.
Definition: avcodec.h:383
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:943
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: utils.c:1939
AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT
@ AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT
Definition: packet.h:450
AVBitStreamFilter
Definition: bsf.h:90
av_packet_new_side_data
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
Definition: avpacket.c:232
AVERROR_STREAM_NOT_FOUND
#define AVERROR_STREAM_NOT_FOUND
Stream not found.
Definition: error.h:67
FFStream::avctx
AVCodecContext * avctx
The codec context used by avformat_find_stream_info, the parser, etc.
Definition: internal.h:221
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
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:353
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: utils.c:688
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:641
ff_parse_key_val_cb
void(* ff_parse_key_val_cb)(void *context, const char *key, int key_len, char **dest, int *dest_len)
Callback function type for ff_parse_key_value.
Definition: internal.h:614
av_format_ffversion
const char av_format_ffversion[]
Definition: utils.c:51
AV_CODEC_ID_PCM_U32LE
@ AV_CODEC_ID_PCM_U32LE
Definition: codec_id.h:324
AVOutputFormat::video_codec
enum AVCodecID video_codec
default video codec
Definition: avformat.h:515
temp
else temp
Definition: vf_mcdeint.c:248
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:1084
AVPacket::stream_index
int stream_index
Definition: packet.h:375
ff_format_set_url
void ff_format_set_url(AVFormatContext *s, char *url)
Set AVFormatContext url field to the provided pointer.
Definition: utils.c:2003
avformat_license
const char * avformat_license(void)
Return the libavformat license.
Definition: utils.c:71
av_gettime
int64_t av_gettime(void)
Get the current time in microseconds.
Definition: time.c:39
FFStream::index_entries
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: internal.h:277
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:82
AVBSFContext::filter
const struct AVBitStreamFilter * filter
The bitstream filter this context is an instance of.
Definition: bsf.h:56
AVERROR_DECODER_NOT_FOUND
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
Definition: error.h:54
AVIO_FLAG_READ
#define AVIO_FLAG_READ
read-only
Definition: avio.h:621
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:279
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_CODEC_ID_PCM_S32LE
@ AV_CODEC_ID_PCM_S32LE
Definition: codec_id.h:322
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
packet_internal.h
ff_codec_get_tag
unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id)
Definition: utils.c:347
AV_CODEC_ID_PCM_U8
@ AV_CODEC_ID_PCM_U8
Definition: codec_id.h:319
AVOption::unit
const char * unit
The logical unit to which the option belongs.
Definition: opt.h:303
FFFormatContext::pkt
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
Definition: internal.h:132
AV_FIELD_PROGRESSIVE
@ AV_FIELD_PROGRESSIVE
Definition: codec_par.h:38
AVCodecParameters::format
int format
Definition: codec_par.h:84
avformat_configuration
const char * avformat_configuration(void)
Return the libavformat build-time configuration.
Definition: utils.c:66
AV_CODEC_ID_PCM_F64LE
@ AV_CODEC_ID_PCM_F64LE
Definition: codec_id.h:337
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:408
AVDictionaryEntry
Definition: dict.h:79
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
AVPacket
This structure stores compressed data.
Definition: packet.h:350
ff_flush_packet_queue
void ff_flush_packet_queue(AVFormatContext *s)
Definition: utils.c:299
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
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:217
FFStream::cur_dts
int64_t cur_dts
Definition: internal.h:429
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:393
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:48
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: utils.c:1772
avio_find_protocol_name
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
Definition: avio.c:467
d
d
Definition: ffmpeg_filter.c:153
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Definition: opt.h:223
ff_parse_ntp_time
uint64_t ff_parse_ntp_time(uint64_t ntp_ts)
Parse the NTP time in micro seconds (since NTP epoch).
Definition: utils.c:978
int32_t
int32_t
Definition: audioconvert.c:56
bytestream.h
convert_header.str
string str
Definition: convert_header.py:20
AV_CODEC_ID_PCM_U16LE
@ AV_CODEC_ID_PCM_U16LE
Definition: codec_id.h:316
FFStream::need_context_update
int need_context_update
Whether the internal avctx needs to be updated from codecpar (after a late change to codecpar)
Definition: internal.h:238
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
ff_format_io_close_default
void ff_format_io_close_default(AVFormatContext *s, AVIOContext *pb)
Definition: utils.c:1843
FFStream::last_dts
int64_t last_dts
Definition: internal.h:249
av_strlcpy
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:83
AV_CODEC_ID_PCM_F32LE
@ AV_CODEC_ID_PCM_F32LE
Definition: codec_id.h:335
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:89
CONTAINS_PAL
#define CONTAINS_PAL
Definition: internal.h:966
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: utils.c:614
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
FFStream::parser
struct AVCodecParserContext * parser
Definition: internal.h:406
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
ff_parse_creation_time_metadata
int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds)
Parse creation_time in AVFormatContext metadata if exists and warn if the parsing fails.
Definition: utils.c:1866
ffio_read_size
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:691
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3521
AVDictionaryEntry::value
char * value
Definition: dict.h:81
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:975
avstring.h
av_stream_get_class
const AVClass * av_stream_get_class(void)
Get the AVClass for AVStream.
Definition: utils.c:763
av_codec_get_id
enum AVCodecID av_codec_get_id(const AVCodecTag *const *tags, unsigned int tag)
Definition: utils.c:441
AVOutputFormat::query_codec
int(* query_codec)(enum AVCodecID id, int std_compliance)
Test if the given codec can be stored in this container.
Definition: avformat.h:586
av_strndup
char * av_strndup(const char *s, size_t len)
Duplicate a substring of a string.
Definition: mem.c:291
AVStream::pts_wrap_bits
int pts_wrap_bits
Number of bits in timestamps.
Definition: avformat.h:1104
AVChapter::time_base
AVRational time_base
time base in which the start/end timestamps are specified
Definition: avformat.h:1161
AVCodecTag::tag
unsigned int tag
Definition: internal.h:53
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
snprintf
#define snprintf
Definition: snprintf.h:34
ff_alloc_extradata
int ff_alloc_extradata(AVCodecParameters *par, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0.
Definition: utils.c:451
FFStream::pts_wrap_reference
int64_t pts_wrap_reference
Internal data to check for wrapping of the time stamp.
Definition: internal.h:341
AV_CODEC_ID_PCM_S24BE
@ AV_CODEC_ID_PCM_S24BE
Definition: codec_id.h:327
avpriv_dict_set_timestamp
int avpriv_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t timestamp)
Set a dictionary value to an ISO-8601 compliant timestamp string.
Definition: dict.c:258
av_bsf_alloc
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **pctx)
Allocate a context for a given bitstream filter.
Definition: bsf.c:100
dec_ctx
static AVCodecContext * dec_ctx
Definition: filtering_audio.c:44
av_parser_close
void av_parser_close(AVCodecParserContext *s)
Definition: parser.c:191
ff_generate_avci_extradata
int ff_generate_avci_extradata(AVStream *st)
Generate standard extradata for AVC-Intra based on width/height and field order.
Definition: utils.c:1587
AV_DISPOSITION_LYRICS
#define AV_DISPOSITION_LYRICS
The stream contains song lyrics.
Definition: avformat.h:842
append_packet_chunked
static int append_packet_chunked(AVIOContext *s, AVPacket *pkt, int size)
Definition: utils.c:158
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: utils.c:1419
intmath.h