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  si->chapter_ids_monotonic = 0;
899  for (unsigned i = 0; i < s->nb_chapters; i++)
900  if (s->chapters[i]->id == id)
901  chapter = s->chapters[i];
902  }
903 
904  if (!chapter) {
905  chapter = av_mallocz(sizeof(AVChapter));
906  if (!chapter)
907  return NULL;
908  ret = av_dynarray_add_nofree(&s->chapters, &s->nb_chapters, chapter);
909  if (ret < 0) {
910  av_free(chapter);
911  return NULL;
912  }
913  }
914  av_dict_set(&chapter->metadata, "title", title, 0);
915  chapter->id = id;
916  chapter->time_base = time_base;
917  chapter->start = start;
918  chapter->end = end;
919 
920  return chapter;
921 }
922 
923 void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
924 {
926  void *tmp;
927 
928  if (idx >= ac->nb_streams) {
929  av_log(ac, AV_LOG_ERROR, "stream index %d is not valid\n", idx);
930  return;
931  }
932 
933  for (unsigned i = 0; i < ac->nb_programs; i++) {
934  if (ac->programs[i]->id != progid)
935  continue;
936  program = ac->programs[i];
937  for (unsigned j = 0; j < program->nb_stream_indexes; j++)
938  if (program->stream_index[j] == idx)
939  return;
940 
941  tmp = av_realloc_array(program->stream_index, program->nb_stream_indexes+1, sizeof(unsigned int));
942  if (!tmp)
943  return;
944  program->stream_index = tmp;
945  program->stream_index[program->nb_stream_indexes++] = idx;
946  return;
947  }
948 }
949 
950 uint64_t ff_ntp_time(void)
951 {
952  return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US;
953 }
954 
955 uint64_t ff_get_formatted_ntp_time(uint64_t ntp_time_us)
956 {
957  uint64_t ntp_ts, frac_part, sec;
958  uint32_t usec;
959 
960  //current ntp time in seconds and micro seconds
961  sec = ntp_time_us / 1000000;
962  usec = ntp_time_us % 1000000;
963 
964  //encoding in ntp timestamp format
965  frac_part = usec * 0xFFFFFFFFULL;
966  frac_part /= 1000000;
967 
968  if (sec > 0xFFFFFFFFULL)
969  av_log(NULL, AV_LOG_WARNING, "NTP time format roll over detected\n");
970 
971  ntp_ts = sec << 32;
972  ntp_ts |= frac_part;
973 
974  return ntp_ts;
975 }
976 
977 uint64_t ff_parse_ntp_time(uint64_t ntp_ts)
978 {
979  uint64_t sec = ntp_ts >> 32;
980  uint64_t frac_part = ntp_ts & 0xFFFFFFFFULL;
981  uint64_t usec = (frac_part * 1000000) / 0xFFFFFFFFULL;
982 
983  return (sec * 1000000) + usec;
984 }
985 
986 int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags)
987 {
988  const char *p;
989  char *q, buf1[20], c;
990  int nd, len, percentd_found;
991 
992  q = buf;
993  p = path;
994  percentd_found = 0;
995  for (;;) {
996  c = *p++;
997  if (c == '\0')
998  break;
999  if (c == '%') {
1000  do {
1001  nd = 0;
1002  while (av_isdigit(*p)) {
1003  if (nd >= INT_MAX / 10 - 255)
1004  goto fail;
1005  nd = nd * 10 + *p++ - '0';
1006  }
1007  c = *p++;
1008  } while (av_isdigit(c));
1009 
1010  switch (c) {
1011  case '%':
1012  goto addchar;
1013  case 'd':
1014  if (!(flags & AV_FRAME_FILENAME_FLAGS_MULTIPLE) && percentd_found)
1015  goto fail;
1016  percentd_found = 1;
1017  if (number < 0)
1018  nd += 1;
1019  snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
1020  len = strlen(buf1);
1021  if ((q - buf + len) > buf_size - 1)
1022  goto fail;
1023  memcpy(q, buf1, len);
1024  q += len;
1025  break;
1026  default:
1027  goto fail;
1028  }
1029  } else {
1030 addchar:
1031  if ((q - buf) < buf_size - 1)
1032  *q++ = c;
1033  }
1034  }
1035  if (!percentd_found)
1036  goto fail;
1037  *q = '\0';
1038  return 0;
1039 fail:
1040  *q = '\0';
1041  return -1;
1042 }
1043 
1044 int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
1045 {
1046  return av_get_frame_filename2(buf, buf_size, path, number, 0);
1047 }
1048 
1049 void av_url_split(char *proto, int proto_size,
1050  char *authorization, int authorization_size,
1051  char *hostname, int hostname_size,
1052  int *port_ptr, char *path, int path_size, const char *url)
1053 {
1054  const char *p, *ls, *at, *at2, *col, *brk;
1055 
1056  if (port_ptr)
1057  *port_ptr = -1;
1058  if (proto_size > 0)
1059  proto[0] = 0;
1060  if (authorization_size > 0)
1061  authorization[0] = 0;
1062  if (hostname_size > 0)
1063  hostname[0] = 0;
1064  if (path_size > 0)
1065  path[0] = 0;
1066 
1067  /* parse protocol */
1068  if ((p = strchr(url, ':'))) {
1069  av_strlcpy(proto, url, FFMIN(proto_size, p + 1 - url));
1070  p++; /* skip ':' */
1071  if (*p == '/')
1072  p++;
1073  if (*p == '/')
1074  p++;
1075  } else {
1076  /* no protocol means plain filename */
1077  av_strlcpy(path, url, path_size);
1078  return;
1079  }
1080 
1081  /* separate path from hostname */
1082  ls = p + strcspn(p, "/?#");
1083  av_strlcpy(path, ls, path_size);
1084 
1085  /* the rest is hostname, use that to parse auth/port */
1086  if (ls != p) {
1087  /* authorization (user[:pass]@hostname) */
1088  at2 = p;
1089  while ((at = strchr(p, '@')) && at < ls) {
1090  av_strlcpy(authorization, at2,
1091  FFMIN(authorization_size, at + 1 - at2));
1092  p = at + 1; /* skip '@' */
1093  }
1094 
1095  if (*p == '[' && (brk = strchr(p, ']')) && brk < ls) {
1096  /* [host]:port */
1097  av_strlcpy(hostname, p + 1,
1098  FFMIN(hostname_size, brk - p));
1099  if (brk[1] == ':' && port_ptr)
1100  *port_ptr = atoi(brk + 2);
1101  } else if ((col = strchr(p, ':')) && col < ls) {
1102  av_strlcpy(hostname, p,
1103  FFMIN(col + 1 - p, hostname_size));
1104  if (port_ptr)
1105  *port_ptr = atoi(col + 1);
1106  } else
1107  av_strlcpy(hostname, p,
1108  FFMIN(ls + 1 - p, hostname_size));
1109  }
1110 }
1111 
1112 int ff_mkdir_p(const char *path)
1113 {
1114  int ret = 0;
1115  char *temp = av_strdup(path);
1116  char *pos = temp;
1117  char tmp_ch = '\0';
1118 
1119  if (!path || !temp) {
1120  return -1;
1121  }
1122 
1123  if (!av_strncasecmp(temp, "/", 1) || !av_strncasecmp(temp, "\\", 1)) {
1124  pos++;
1125  } else if (!av_strncasecmp(temp, "./", 2) || !av_strncasecmp(temp, ".\\", 2)) {
1126  pos += 2;
1127  }
1128 
1129  for ( ; *pos != '\0'; ++pos) {
1130  if (*pos == '/' || *pos == '\\') {
1131  tmp_ch = *pos;
1132  *pos = '\0';
1133  ret = mkdir(temp, 0755);
1134  *pos = tmp_ch;
1135  }
1136  }
1137 
1138  if ((*(pos - 1) != '/') || (*(pos - 1) != '\\')) {
1139  ret = mkdir(temp, 0755);
1140  }
1141 
1142  av_free(temp);
1143  return ret;
1144 }
1145 
1146 char *ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase)
1147 {
1148  static const char hex_table_uc[16] = { '0', '1', '2', '3',
1149  '4', '5', '6', '7',
1150  '8', '9', 'A', 'B',
1151  'C', 'D', 'E', 'F' };
1152  static const char hex_table_lc[16] = { '0', '1', '2', '3',
1153  '4', '5', '6', '7',
1154  '8', '9', 'a', 'b',
1155  'c', 'd', 'e', 'f' };
1156  const char *hex_table = lowercase ? hex_table_lc : hex_table_uc;
1157 
1158  for (int i = 0; i < s; i++) {
1159  buff[i * 2] = hex_table[src[i] >> 4];
1160  buff[i * 2 + 1] = hex_table[src[i] & 0xF];
1161  }
1162  buff[2 * s] = '\0';
1163 
1164  return buff;
1165 }
1166 
1167 int ff_hex_to_data(uint8_t *data, const char *p)
1168 {
1169  int c, len, v;
1170 
1171  len = 0;
1172  v = 1;
1173  for (;;) {
1174  p += strspn(p, SPACE_CHARS);
1175  if (*p == '\0')
1176  break;
1177  c = av_toupper((unsigned char) *p++);
1178  if (c >= '0' && c <= '9')
1179  c = c - '0';
1180  else if (c >= 'A' && c <= 'F')
1181  c = c - 'A' + 10;
1182  else
1183  break;
1184  v = (v << 4) | c;
1185  if (v & 0x100) {
1186  if (data)
1187  data[len] = v;
1188  len++;
1189  v = 1;
1190  }
1191  }
1192  return len;
1193 }
1194 
1195 void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits,
1196  unsigned int pts_num, unsigned int pts_den)
1197 {
1198  FFStream *const sti = ffstream(st);
1199  AVRational new_tb;
1200  if (av_reduce(&new_tb.num, &new_tb.den, pts_num, pts_den, INT_MAX)) {
1201  if (new_tb.num != pts_num)
1203  "st:%d removing common factor %d from timebase\n",
1204  st->index, pts_num / new_tb.num);
1205  } else
1207  "st:%d has too large timebase, reducing\n", st->index);
1208 
1209  if (new_tb.num <= 0 || new_tb.den <= 0) {
1211  "Ignoring attempt to set invalid timebase %d/%d for st:%d\n",
1212  new_tb.num, new_tb.den,
1213  st->index);
1214  return;
1215  }
1216  st->time_base = new_tb;
1217  sti->avctx->pkt_timebase = new_tb;
1218  st->pts_wrap_bits = pts_wrap_bits;
1219 }
1220 
1221 void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
1222  void *context)
1223 {
1224  const char *ptr = str;
1225 
1226  /* Parse key=value pairs. */
1227  for (;;) {
1228  const char *key;
1229  char *dest = NULL, *dest_end;
1230  int key_len, dest_len = 0;
1231 
1232  /* Skip whitespace and potential commas. */
1233  while (*ptr && (av_isspace(*ptr) || *ptr == ','))
1234  ptr++;
1235  if (!*ptr)
1236  break;
1237 
1238  key = ptr;
1239 
1240  if (!(ptr = strchr(key, '=')))
1241  break;
1242  ptr++;
1243  key_len = ptr - key;
1244 
1245  callback_get_buf(context, key, key_len, &dest, &dest_len);
1246  dest_end = dest + dest_len - 1;
1247 
1248  if (*ptr == '\"') {
1249  ptr++;
1250  while (*ptr && *ptr != '\"') {
1251  if (*ptr == '\\') {
1252  if (!ptr[1])
1253  break;
1254  if (dest && dest < dest_end)
1255  *dest++ = ptr[1];
1256  ptr += 2;
1257  } else {
1258  if (dest && dest < dest_end)
1259  *dest++ = *ptr;
1260  ptr++;
1261  }
1262  }
1263  if (*ptr == '\"')
1264  ptr++;
1265  } else {
1266  for (; *ptr && !(av_isspace(*ptr) || *ptr == ','); ptr++)
1267  if (dest && dest < dest_end)
1268  *dest++ = *ptr;
1269  }
1270  if (dest)
1271  *dest = 0;
1272  }
1273 }
1274 
1276 {
1277  for (unsigned i = 0; i < s->nb_streams; i++)
1278  if (s->streams[i]->id == id)
1279  return i;
1280  return -1;
1281 }
1282 
1284  int std_compliance)
1285 {
1286  if (ofmt) {
1287  unsigned int codec_tag;
1288  if (ofmt->query_codec)
1289  return ofmt->query_codec(codec_id, std_compliance);
1290  else if (ofmt->codec_tag)
1291  return !!av_codec_get_tag2(ofmt->codec_tag, codec_id, &codec_tag);
1292  else if (codec_id == ofmt->video_codec ||
1293  codec_id == ofmt->audio_codec ||
1294  codec_id == ofmt->subtitle_codec ||
1295  codec_id == ofmt->data_codec)
1296  return 1;
1297  }
1298  return AVERROR_PATCHWELCOME;
1299 }
1300 
1302 {
1303 #if CONFIG_NETWORK
1304  int ret;
1305  if ((ret = ff_network_init()) < 0)
1306  return ret;
1307  if ((ret = ff_tls_init()) < 0)
1308  return ret;
1309 #endif
1310  return 0;
1311 }
1312 
1314 {
1315 #if CONFIG_NETWORK
1316  ff_network_close();
1317  ff_tls_deinit();
1318 #endif
1319  return 0;
1320 }
1321 
1323  uint64_t channel_layout, int32_t sample_rate,
1325 {
1326  uint32_t flags = 0;
1327  int size = 4;
1328  uint8_t *data;
1329  if (!pkt)
1330  return AVERROR(EINVAL);
1331  if (channels) {
1332  size += 4;
1334  }
1335  if (channel_layout) {
1336  size += 8;
1338  }
1339  if (sample_rate) {
1340  size += 4;
1342  }
1343  if (width || height) {
1344  size += 8;
1346  }
1348  if (!data)
1349  return AVERROR(ENOMEM);
1350  bytestream_put_le32(&data, flags);
1351  if (channels)
1352  bytestream_put_le32(&data, channels);
1353  if (channel_layout)
1354  bytestream_put_le64(&data, channel_layout);
1355  if (sample_rate)
1356  bytestream_put_le32(&data, sample_rate);
1357  if (width || height) {
1358  bytestream_put_le32(&data, width);
1359  bytestream_put_le32(&data, height);
1360  }
1361  return 0;
1362 }
1363 
1365 {
1366  AVRational undef = {0, 1};
1367  AVRational stream_sample_aspect_ratio = stream ? stream->sample_aspect_ratio : undef;
1368  AVRational codec_sample_aspect_ratio = stream && stream->codecpar ? stream->codecpar->sample_aspect_ratio : undef;
1369  AVRational frame_sample_aspect_ratio = frame ? frame->sample_aspect_ratio : codec_sample_aspect_ratio;
1370 
1371  av_reduce(&stream_sample_aspect_ratio.num, &stream_sample_aspect_ratio.den,
1372  stream_sample_aspect_ratio.num, stream_sample_aspect_ratio.den, INT_MAX);
1373  if (stream_sample_aspect_ratio.num <= 0 || stream_sample_aspect_ratio.den <= 0)
1374  stream_sample_aspect_ratio = undef;
1375 
1376  av_reduce(&frame_sample_aspect_ratio.num, &frame_sample_aspect_ratio.den,
1377  frame_sample_aspect_ratio.num, frame_sample_aspect_ratio.den, INT_MAX);
1378  if (frame_sample_aspect_ratio.num <= 0 || frame_sample_aspect_ratio.den <= 0)
1379  frame_sample_aspect_ratio = undef;
1380 
1381  if (stream_sample_aspect_ratio.num)
1382  return stream_sample_aspect_ratio;
1383  else
1384  return frame_sample_aspect_ratio;
1385 }
1386 
1388 {
1389  AVRational fr = st->r_frame_rate;
1390  AVCodecContext *const avctx = ffstream(st)->avctx;
1391  AVRational codec_fr = avctx->framerate;
1392  AVRational avg_fr = st->avg_frame_rate;
1393 
1394  if (avg_fr.num > 0 && avg_fr.den > 0 && fr.num > 0 && fr.den > 0 &&
1395  av_q2d(avg_fr) < 70 && av_q2d(fr) > 210) {
1396  fr = avg_fr;
1397  }
1398 
1399 
1400  if (avctx->ticks_per_frame > 1) {
1401  if ( codec_fr.num > 0 && codec_fr.den > 0 &&
1402  (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))
1403  fr = codec_fr;
1404  }
1405 
1406  return fr;
1407 }
1408 
1409 /**
1410  * Matches a stream specifier (but ignores requested index).
1411  *
1412  * @param indexptr set to point to the requested stream index if there is one
1413  *
1414  * @return <0 on error
1415  * 0 if st is NOT a matching stream
1416  * >0 if st is a matching stream
1417  */
1418 static int match_stream_specifier(const AVFormatContext *s, const AVStream *st,
1419  const char *spec, const char **indexptr,
1420  const AVProgram **p)
1421 {
1422  int match = 1; /* Stores if the specifier matches so far. */
1423  while (*spec) {
1424  if (*spec <= '9' && *spec >= '0') { /* opt:index */
1425  if (indexptr)
1426  *indexptr = spec;
1427  return match;
1428  } else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||
1429  *spec == 't' || *spec == 'V') { /* opt:[vasdtV] */
1430  enum AVMediaType type;
1431  int nopic = 0;
1432 
1433  switch (*spec++) {
1434  case 'v': type = AVMEDIA_TYPE_VIDEO; break;
1435  case 'a': type = AVMEDIA_TYPE_AUDIO; break;
1436  case 's': type = AVMEDIA_TYPE_SUBTITLE; break;
1437  case 'd': type = AVMEDIA_TYPE_DATA; break;
1438  case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
1439  case 'V': type = AVMEDIA_TYPE_VIDEO; nopic = 1; break;
1440  default: av_assert0(0);
1441  }
1442  if (*spec && *spec++ != ':') /* If we are not at the end, then another specifier must follow. */
1443  return AVERROR(EINVAL);
1444 
1445  if (type != st->codecpar->codec_type)
1446  match = 0;
1447  if (nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC))
1448  match = 0;
1449  } else if (*spec == 'p' && *(spec + 1) == ':') {
1450  int prog_id;
1451  int found = 0;
1452  char *endptr;
1453  spec += 2;
1454  prog_id = strtol(spec, &endptr, 0);
1455  /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
1456  if (spec == endptr || (*endptr && *endptr++ != ':'))
1457  return AVERROR(EINVAL);
1458  spec = endptr;
1459  if (match) {
1460  for (unsigned i = 0; i < s->nb_programs; i++) {
1461  if (s->programs[i]->id != prog_id)
1462  continue;
1463 
1464  for (unsigned j = 0; j < s->programs[i]->nb_stream_indexes; j++) {
1465  if (st->index == s->programs[i]->stream_index[j]) {
1466  found = 1;
1467  if (p)
1468  *p = s->programs[i];
1469  i = s->nb_programs;
1470  break;
1471  }
1472  }
1473  }
1474  }
1475  if (!found)
1476  match = 0;
1477  } else if (*spec == '#' ||
1478  (*spec == 'i' && *(spec + 1) == ':')) {
1479  int stream_id;
1480  char *endptr;
1481  spec += 1 + (*spec == 'i');
1482  stream_id = strtol(spec, &endptr, 0);
1483  if (spec == endptr || *endptr) /* Disallow empty id and make sure we are at the end. */
1484  return AVERROR(EINVAL);
1485  return match && (stream_id == st->id);
1486  } else if (*spec == 'm' && *(spec + 1) == ':') {
1487  const AVDictionaryEntry *tag;
1488  char *key, *val;
1489  int ret;
1490 
1491  if (match) {
1492  spec += 2;
1493  val = strchr(spec, ':');
1494 
1495  key = val ? av_strndup(spec, val - spec) : av_strdup(spec);
1496  if (!key)
1497  return AVERROR(ENOMEM);
1498 
1499  tag = av_dict_get(st->metadata, key, NULL, 0);
1500  if (tag) {
1501  if (!val || !strcmp(tag->value, val + 1))
1502  ret = 1;
1503  else
1504  ret = 0;
1505  } else
1506  ret = 0;
1507 
1508  av_freep(&key);
1509  }
1510  return match && ret;
1511  } else if (*spec == 'u' && *(spec + 1) == '\0') {
1512  const AVCodecParameters *par = st->codecpar;
1513  int val;
1514  switch (par->codec_type) {
1515  case AVMEDIA_TYPE_AUDIO:
1516  val = par->sample_rate && par->channels;
1517  if (par->format == AV_SAMPLE_FMT_NONE)
1518  return 0;
1519  break;
1520  case AVMEDIA_TYPE_VIDEO:
1521  val = par->width && par->height;
1522  if (par->format == AV_PIX_FMT_NONE)
1523  return 0;
1524  break;
1525  case AVMEDIA_TYPE_UNKNOWN:
1526  val = 0;
1527  break;
1528  default:
1529  val = 1;
1530  break;
1531  }
1532  return match && (par->codec_id != AV_CODEC_ID_NONE && val != 0);
1533  } else {
1534  return AVERROR(EINVAL);
1535  }
1536  }
1537 
1538  return match;
1539 }
1540 
1541 
1543  const char *spec)
1544 {
1545  int ret, index;
1546  char *endptr;
1547  const char *indexptr = NULL;
1548  const AVProgram *p = NULL;
1549  int nb_streams;
1550 
1551  ret = match_stream_specifier(s, st, spec, &indexptr, &p);
1552  if (ret < 0)
1553  goto error;
1554 
1555  if (!indexptr)
1556  return ret;
1557 
1558  index = strtol(indexptr, &endptr, 0);
1559  if (*endptr) { /* We can't have anything after the requested index. */
1560  ret = AVERROR(EINVAL);
1561  goto error;
1562  }
1563 
1564  /* This is not really needed but saves us a loop for simple stream index specifiers. */
1565  if (spec == indexptr)
1566  return (index == st->index);
1567 
1568  /* If we requested a matching stream index, we have to ensure st is that. */
1569  nb_streams = p ? p->nb_stream_indexes : s->nb_streams;
1570  for (int i = 0; i < nb_streams && index >= 0; i++) {
1571  const AVStream *candidate = s->streams[p ? p->stream_index[i] : i];
1572  ret = match_stream_specifier(s, candidate, spec, NULL, NULL);
1573  if (ret < 0)
1574  goto error;
1575  if (ret > 0 && index-- == 0 && st == candidate)
1576  return 1;
1577  }
1578  return 0;
1579 
1580 error:
1581  if (ret == AVERROR(EINVAL))
1582  av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
1583  return ret;
1584 }
1585 
1587 {
1588  static const uint8_t avci100_1080p_extradata[] = {
1589  // SPS
1590  0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
1591  0xb6, 0xd4, 0x20, 0x22, 0x33, 0x19, 0xc6, 0x63,
1592  0x23, 0x21, 0x01, 0x11, 0x98, 0xce, 0x33, 0x19,
1593  0x18, 0x21, 0x02, 0x56, 0xb9, 0x3d, 0x7d, 0x7e,
1594  0x4f, 0xe3, 0x3f, 0x11, 0xf1, 0x9e, 0x08, 0xb8,
1595  0x8c, 0x54, 0x43, 0xc0, 0x78, 0x02, 0x27, 0xe2,
1596  0x70, 0x1e, 0x30, 0x10, 0x10, 0x14, 0x00, 0x00,
1597  0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0xca,
1598  0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1599  // PPS
1600  0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x33, 0x48,
1601  0xd0
1602  };
1603  static const uint8_t avci100_1080i_extradata[] = {
1604  // SPS
1605  0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
1606  0xb6, 0xd4, 0x20, 0x22, 0x33, 0x19, 0xc6, 0x63,
1607  0x23, 0x21, 0x01, 0x11, 0x98, 0xce, 0x33, 0x19,
1608  0x18, 0x21, 0x03, 0x3a, 0x46, 0x65, 0x6a, 0x65,
1609  0x24, 0xad, 0xe9, 0x12, 0x32, 0x14, 0x1a, 0x26,
1610  0x34, 0xad, 0xa4, 0x41, 0x82, 0x23, 0x01, 0x50,
1611  0x2b, 0x1a, 0x24, 0x69, 0x48, 0x30, 0x40, 0x2e,
1612  0x11, 0x12, 0x08, 0xc6, 0x8c, 0x04, 0x41, 0x28,
1613  0x4c, 0x34, 0xf0, 0x1e, 0x01, 0x13, 0xf2, 0xe0,
1614  0x3c, 0x60, 0x20, 0x20, 0x28, 0x00, 0x00, 0x03,
1615  0x00, 0x08, 0x00, 0x00, 0x03, 0x01, 0x94, 0x20,
1616  // PPS
1617  0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x33, 0x48,
1618  0xd0
1619  };
1620  static const uint8_t avci50_1080p_extradata[] = {
1621  // SPS
1622  0x00, 0x00, 0x00, 0x01, 0x67, 0x6e, 0x10, 0x28,
1623  0xa6, 0xd4, 0x20, 0x32, 0x33, 0x0c, 0x71, 0x18,
1624  0x88, 0x62, 0x10, 0x19, 0x19, 0x86, 0x38, 0x8c,
1625  0x44, 0x30, 0x21, 0x02, 0x56, 0x4e, 0x6f, 0x37,
1626  0xcd, 0xf9, 0xbf, 0x81, 0x6b, 0xf3, 0x7c, 0xde,
1627  0x6e, 0x6c, 0xd3, 0x3c, 0x05, 0xa0, 0x22, 0x7e,
1628  0x5f, 0xfc, 0x00, 0x0c, 0x00, 0x13, 0x8c, 0x04,
1629  0x04, 0x05, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00,
1630  0x00, 0x03, 0x00, 0x32, 0x84, 0x00, 0x00, 0x00,
1631  // PPS
1632  0x00, 0x00, 0x00, 0x01, 0x68, 0xee, 0x31, 0x12,
1633  0x11
1634  };
1635  static const uint8_t avci50_1080i_extradata[] = {
1636  // SPS
1637  0x00, 0x00, 0x00, 0x01, 0x67, 0x6e, 0x10, 0x28,
1638  0xa6, 0xd4, 0x20, 0x32, 0x33, 0x0c, 0x71, 0x18,
1639  0x88, 0x62, 0x10, 0x19, 0x19, 0x86, 0x38, 0x8c,
1640  0x44, 0x30, 0x21, 0x02, 0x56, 0x4e, 0x6e, 0x61,
1641  0x87, 0x3e, 0x73, 0x4d, 0x98, 0x0c, 0x03, 0x06,
1642  0x9c, 0x0b, 0x73, 0xe6, 0xc0, 0xb5, 0x18, 0x63,
1643  0x0d, 0x39, 0xe0, 0x5b, 0x02, 0xd4, 0xc6, 0x19,
1644  0x1a, 0x79, 0x8c, 0x32, 0x34, 0x24, 0xf0, 0x16,
1645  0x81, 0x13, 0xf7, 0xff, 0x80, 0x02, 0x00, 0x01,
1646  0xf1, 0x80, 0x80, 0x80, 0xa0, 0x00, 0x00, 0x03,
1647  0x00, 0x20, 0x00, 0x00, 0x06, 0x50, 0x80, 0x00,
1648  // PPS
1649  0x00, 0x00, 0x00, 0x01, 0x68, 0xee, 0x31, 0x12,
1650  0x11
1651  };
1652  static const uint8_t avci100_720p_extradata[] = {
1653  // SPS
1654  0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
1655  0xb6, 0xd4, 0x20, 0x2a, 0x33, 0x1d, 0xc7, 0x62,
1656  0xa1, 0x08, 0x40, 0x54, 0x66, 0x3b, 0x8e, 0xc5,
1657  0x42, 0x02, 0x10, 0x25, 0x64, 0x2c, 0x89, 0xe8,
1658  0x85, 0xe4, 0x21, 0x4b, 0x90, 0x83, 0x06, 0x95,
1659  0xd1, 0x06, 0x46, 0x97, 0x20, 0xc8, 0xd7, 0x43,
1660  0x08, 0x11, 0xc2, 0x1e, 0x4c, 0x91, 0x0f, 0x01,
1661  0x40, 0x16, 0xec, 0x07, 0x8c, 0x04, 0x04, 0x05,
1662  0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03,
1663  0x00, 0x64, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00,
1664  // PPS
1665  0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x31, 0x12,
1666  0x11
1667  };
1668  static const uint8_t avci50_720p_extradata[] = {
1669  // SPS
1670  0x00, 0x00, 0x00, 0x01, 0x67, 0x6e, 0x10, 0x20,
1671  0xa6, 0xd4, 0x20, 0x32, 0x33, 0x0c, 0x71, 0x18,
1672  0x88, 0x62, 0x10, 0x19, 0x19, 0x86, 0x38, 0x8c,
1673  0x44, 0x30, 0x21, 0x02, 0x56, 0x4e, 0x6f, 0x37,
1674  0xcd, 0xf9, 0xbf, 0x81, 0x6b, 0xf3, 0x7c, 0xde,
1675  0x6e, 0x6c, 0xd3, 0x3c, 0x0f, 0x01, 0x6e, 0xff,
1676  0xc0, 0x00, 0xc0, 0x01, 0x38, 0xc0, 0x40, 0x40,
1677  0x50, 0x00, 0x00, 0x03, 0x00, 0x10, 0x00, 0x00,
1678  0x06, 0x48, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
1679  // PPS
1680  0x00, 0x00, 0x00, 0x01, 0x68, 0xee, 0x31, 0x12,
1681  0x11
1682  };
1683 
1684  const uint8_t *data = NULL;
1685  int ret, size = 0;
1686 
1687  if (st->codecpar->width == 1920) {
1689  data = avci100_1080p_extradata;
1690  size = sizeof(avci100_1080p_extradata);
1691  } else {
1692  data = avci100_1080i_extradata;
1693  size = sizeof(avci100_1080i_extradata);
1694  }
1695  } else if (st->codecpar->width == 1440) {
1697  data = avci50_1080p_extradata;
1698  size = sizeof(avci50_1080p_extradata);
1699  } else {
1700  data = avci50_1080i_extradata;
1701  size = sizeof(avci50_1080i_extradata);
1702  }
1703  } else if (st->codecpar->width == 1280) {
1704  data = avci100_720p_extradata;
1705  size = sizeof(avci100_720p_extradata);
1706  } else if (st->codecpar->width == 960) {
1707  data = avci50_720p_extradata;
1708  size = sizeof(avci50_720p_extradata);
1709  }
1710 
1711  if (!size)
1712  return 0;
1713 
1714  if ((ret = ff_alloc_extradata(st->codecpar, size)) < 0)
1715  return ret;
1716  memcpy(st->codecpar->extradata, data, size);
1717 
1718  return 0;
1719 }
1720 
1722  enum AVPacketSideDataType type, size_t *size)
1723 {
1724  for (int i = 0; i < st->nb_side_data; i++) {
1725  if (st->side_data[i].type == type) {
1726  if (size)
1727  *size = st->side_data[i].size;
1728  return st->side_data[i].data;
1729  }
1730  }
1731  if (size)
1732  *size = 0;
1733  return NULL;
1734 }
1735 
1737  uint8_t *data, size_t size)
1738 {
1739  AVPacketSideData *sd, *tmp;
1740 
1741  for (int i = 0; i < st->nb_side_data; i++) {
1742  sd = &st->side_data[i];
1743 
1744  if (sd->type == type) {
1745  av_freep(&sd->data);
1746  sd->data = data;
1747  sd->size = size;
1748  return 0;
1749  }
1750  }
1751 
1752  if ((unsigned)st->nb_side_data + 1 >= INT_MAX / sizeof(*st->side_data))
1753  return AVERROR(ERANGE);
1754 
1755  tmp = av_realloc(st->side_data, (st->nb_side_data + 1) * sizeof(*tmp));
1756  if (!tmp) {
1757  return AVERROR(ENOMEM);
1758  }
1759 
1760  st->side_data = tmp;
1761  st->nb_side_data++;
1762 
1763  sd = &st->side_data[st->nb_side_data - 1];
1764  sd->type = type;
1765  sd->data = data;
1766  sd->size = size;
1767 
1768  return 0;
1769 }
1770 
1772  size_t size)
1773 {
1774  int ret;
1775  uint8_t *data = av_malloc(size);
1776 
1777  if (!data)
1778  return NULL;
1779 
1781  if (ret < 0) {
1782  av_freep(&data);
1783  return NULL;
1784  }
1785 
1786  return data;
1787 }
1788 
1789 int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
1790 {
1791  int ret;
1792  const AVBitStreamFilter *bsf;
1793  FFStream *const sti = ffstream(st);
1794  AVBSFContext *bsfc;
1795 
1796  av_assert0(!sti->bsfc);
1797 
1798  if (!(bsf = av_bsf_get_by_name(name))) {
1799  av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter '%s'\n", name);
1800  return AVERROR_BSF_NOT_FOUND;
1801  }
1802 
1803  if ((ret = av_bsf_alloc(bsf, &bsfc)) < 0)
1804  return ret;
1805 
1806  bsfc->time_base_in = st->time_base;
1807  if ((ret = avcodec_parameters_copy(bsfc->par_in, st->codecpar)) < 0) {
1808  av_bsf_free(&bsfc);
1809  return ret;
1810  }
1811 
1812  if (args && bsfc->filter->priv_class) {
1813  if ((ret = av_set_options_string(bsfc->priv_data, args, "=", ":")) < 0) {
1814  av_bsf_free(&bsfc);
1815  return ret;
1816  }
1817  }
1818 
1819  if ((ret = av_bsf_init(bsfc)) < 0) {
1820  av_bsf_free(&bsfc);
1821  return ret;
1822  }
1823 
1824  sti->bsfc = bsfc;
1825 
1827  "Automatically inserted bitstream filter '%s'; args='%s'\n",
1828  name, args ? args : "");
1829  return 1;
1830 }
1831 
1833 {
1834  if (!s->oformat)
1835  return AVERROR(EINVAL);
1836 
1837  if (!(s->oformat->flags & AVFMT_NOFILE))
1838  return s->io_open(s, &s->pb, url, AVIO_FLAG_WRITE, options);
1839  return 0;
1840 }
1841 
1843 {
1844  avio_close(pb);
1845 }
1846 
1848 {
1849  int ret = 0;
1850  if (*pb) {
1851  if (s->io_close == ff_format_io_close_default || s->io_close == NULL)
1852  ret = s->io_close2(s, *pb);
1853  else
1854  s->io_close(s, *pb);
1855  }
1856  *pb = NULL;
1857  return ret;
1858 }
1859 
1860 int ff_is_http_proto(const char *filename) {
1861  const char *proto = avio_find_protocol_name(filename);
1862  return proto ? (!av_strcasecmp(proto, "http") || !av_strcasecmp(proto, "https")) : 0;
1863 }
1864 
1865 int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds)
1866 {
1867  AVDictionaryEntry *entry;
1868  int64_t parsed_timestamp;
1869  int ret;
1870  if ((entry = av_dict_get(s->metadata, "creation_time", NULL, 0))) {
1871  if ((ret = av_parse_time(&parsed_timestamp, entry->value, 0)) >= 0) {
1872  *timestamp = return_seconds ? parsed_timestamp / 1000000 : parsed_timestamp;
1873  return 1;
1874  } else {
1875  av_log(s, AV_LOG_WARNING, "Failed to parse creation_time %s\n", entry->value);
1876  return ret;
1877  }
1878  }
1879  return 0;
1880 }
1881 
1883 {
1884  int64_t timestamp;
1885  int ret = ff_parse_creation_time_metadata(s, &timestamp, 0);
1886  if (ret == 1)
1887  return avpriv_dict_set_timestamp(&s->metadata, "creation_time", timestamp);
1888  return ret;
1889 }
1890 
1891 int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t *palette)
1892 {
1893  uint8_t *side_data;
1894  size_t size;
1895 
1897  if (side_data) {
1898  if (size != AVPALETTE_SIZE) {
1899  av_log(s, AV_LOG_ERROR, "Invalid palette side data\n");
1900  return AVERROR_INVALIDDATA;
1901  }
1902  memcpy(palette, side_data, AVPALETTE_SIZE);
1903  return 1;
1904  }
1905 
1906  if (ret == CONTAINS_PAL) {
1907  for (int i = 0; i < AVPALETTE_COUNT; i++)
1908  palette[i] = AV_RL32(pkt->data + pkt->size - AVPALETTE_SIZE + i*4);
1909  return 1;
1910  }
1911 
1912  return 0;
1913 }
1914 
1916 {
1917  int ret;
1918  char *str;
1919 
1920  ret = av_bprint_finalize(buf, &str);
1921  if (ret < 0)
1922  return ret;
1923  if (!av_bprint_is_complete(buf)) {
1924  av_free(str);
1925  return AVERROR(ENOMEM);
1926  }
1927 
1928  par->extradata = str;
1929  /* Note: the string is NUL terminated (so extradata can be read as a
1930  * string), but the ending character is not accounted in the size (in
1931  * binary formats you are likely not supposed to mux that character). When
1932  * extradata is copied, it is also padded with AV_INPUT_BUFFER_PADDING_SIZE
1933  * zeros. */
1934  par->extradata_size = buf->len;
1935  return 0;
1936 }
1937 
1939  AVStream *ost, const AVStream *ist,
1941 {
1942  const AVCodecContext *const dec_ctx = cffstream(ist)->avctx;
1943  AVCodecContext *const enc_ctx = ffstream(ost)->avctx;
1944 
1945  enc_ctx->time_base = ist->time_base;
1946  /*
1947  * Avi is a special case here because it supports variable fps but
1948  * having the fps and timebase differe significantly adds quite some
1949  * overhead
1950  */
1951  if (!strcmp(ofmt->name, "avi")) {
1952 #if FF_API_R_FRAME_RATE
1953  if (copy_tb == AVFMT_TBCF_AUTO && ist->r_frame_rate.num
1954  && av_q2d(ist->r_frame_rate) >= av_q2d(ist->avg_frame_rate)
1955  && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(ist->time_base)
1956  && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(dec_ctx->time_base)
1957  && av_q2d(ist->time_base) < 1.0/500 && av_q2d(dec_ctx->time_base) < 1.0/500
1958  || copy_tb == AVFMT_TBCF_R_FRAMERATE) {
1959  enc_ctx->time_base.num = ist->r_frame_rate.den;
1960  enc_ctx->time_base.den = 2*ist->r_frame_rate.num;
1961  enc_ctx->ticks_per_frame = 2;
1962  } else
1963 #endif
1965  && av_q2d(ist->time_base) < 1.0/500
1966  || copy_tb == AVFMT_TBCF_DECODER) {
1967  enc_ctx->time_base = dec_ctx->time_base;
1968  enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
1969  enc_ctx->time_base.den *= 2;
1970  enc_ctx->ticks_per_frame = 2;
1971  }
1972  } else if (!(ofmt->flags & AVFMT_VARIABLE_FPS)
1973  && !av_match_name(ofmt->name, "mov,mp4,3gp,3g2,psp,ipod,ismv,f4v")) {
1976  && av_q2d(ist->time_base) < 1.0/500
1977  || copy_tb == AVFMT_TBCF_DECODER) {
1978  enc_ctx->time_base = dec_ctx->time_base;
1979  enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
1980  }
1981  }
1982 
1983  if ((enc_ctx->codec_tag == AV_RL32("tmcd") || ost->codecpar->codec_tag == AV_RL32("tmcd"))
1985  && dec_ctx->time_base.num > 0
1986  && 121LL*dec_ctx->time_base.num > dec_ctx->time_base.den) {
1987  enc_ctx->time_base = dec_ctx->time_base;
1988  }
1989 
1990  av_reduce(&enc_ctx->time_base.num, &enc_ctx->time_base.den,
1991  enc_ctx->time_base.num, enc_ctx->time_base.den, INT_MAX);
1992 
1993  return 0;
1994 }
1995 
1997 {
1998  // See avformat_transfer_internal_stream_timing_info() TODO.
1999  return cffstream(st)->avctx->time_base;
2000 }
2001 
2003 {
2004  av_assert0(url);
2005  av_freep(&s->url);
2006  s->url = url;
2007 }
2008 
2009 static int option_is_disposition(const AVOption *opt)
2010 {
2011  return opt->type == AV_OPT_TYPE_CONST &&
2012  opt->unit && !strcmp(opt->unit, "disposition");
2013 }
2014 
2015 int av_disposition_from_string(const char *disp)
2016 {
2017  for (const AVOption *opt = stream_options; opt->name; opt++)
2018  if (option_is_disposition(opt) && !strcmp(disp, opt->name))
2019  return opt->default_val.i64;
2020  return AVERROR(EINVAL);
2021 }
2022 
2023 const char *av_disposition_to_string(int disposition)
2024 {
2025  int val;
2026 
2027  if (disposition <= 0)
2028  return NULL;
2029 
2030  val = 1 << ff_ctz(disposition);
2031  for (const AVOption *opt = stream_options; opt->name; opt++)
2032  if (option_is_disposition(opt) && opt->default_val.i64 == val)
2033  return opt->name;
2034 
2035  return NULL;
2036 }
2037 
2038 int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size)
2039 {
2040  int ret;
2041  int64_t pos, pos_end;
2042  uint8_t *buf, *read_buf[2];
2043  int read_buf_id = 0;
2044  int read_size[2];
2045  AVIOContext *read_pb;
2046 
2047  buf = av_malloc_array(shift_size, 2);
2048  if (!buf)
2049  return AVERROR(ENOMEM);
2050  read_buf[0] = buf;
2051  read_buf[1] = buf + shift_size;
2052 
2053  /* Shift the data: the AVIO context of the output can only be used for
2054  * writing, so we re-open the same output, but for reading. It also avoids
2055  * a read/seek/write/seek back and forth. */
2056  avio_flush(s->pb);
2057  ret = s->io_open(s, &read_pb, s->url, AVIO_FLAG_READ, NULL);
2058  if (ret < 0) {
2059  av_log(s, AV_LOG_ERROR, "Unable to re-open %s output file for shifting data\n", s->url);
2060  goto end;
2061  }
2062 
2063  /* mark the end of the shift to up to the last data we wrote, and get ready
2064  * for writing */
2065  pos_end = avio_tell(s->pb);
2066  avio_seek(s->pb, read_start + shift_size, SEEK_SET);
2067 
2068  avio_seek(read_pb, read_start, SEEK_SET);
2069  pos = avio_tell(read_pb);
2070 
2071 #define READ_BLOCK do { \
2072  read_size[read_buf_id] = avio_read(read_pb, read_buf[read_buf_id], shift_size); \
2073  read_buf_id ^= 1; \
2074 } while (0)
2075 
2076  /* shift data by chunk of at most shift_size */
2077  READ_BLOCK;
2078  do {
2079  int n;
2080  READ_BLOCK;
2081  n = read_size[read_buf_id];
2082  if (n <= 0)
2083  break;
2084  avio_write(s->pb, read_buf[read_buf_id], n);
2085  pos += n;
2086  } while (pos < pos_end);
2087  ret = ff_format_io_close(s, &read_pb);
2088 
2089 end:
2090  av_free(buf);
2091  return ret;
2092 }
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:1146
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:1112
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:950
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:1847
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:2009
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:986
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:1044
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:1275
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:128
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:1891
avformat_network_init
int avformat_network_init(void)
Do global initialization of network libraries.
Definition: utils.c:1301
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:1364
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:1322
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:1283
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:1167
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:2015
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:1832
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:1736
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
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:1195
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:1221
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:955
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:1882
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:1542
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:1387
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:1996
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:1789
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:2038
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:2023
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:1049
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:2773
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:1860
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:1915
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:1721
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:1313
av_program_add_stream_index
void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
Definition: utils.c:923
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:1938
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:2002
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
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
av_dict_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c: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:1771
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:977
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:1842
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:1865
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:1586
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:1418
intmath.h