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/opt.h"
32 #include "libavutil/parseutils.h"
33 #include "libavutil/pixfmt.h"
34 #include "libavutil/thread.h"
35 #include "libavutil/time.h"
36 
37 #include "libavcodec/bsf.h"
38 #include "libavcodec/bytestream.h"
39 #include "libavcodec/internal.h"
41 
42 #include "avformat.h"
43 #include "avio_internal.h"
44 #include "internal.h"
45 #if CONFIG_NETWORK
46 #include "network.h"
47 #endif
48 
49 #include "libavutil/ffversion.h"
50 const char av_format_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
51 
53 
54 /**
55  * @file
56  * various utility functions for use within FFmpeg
57  */
58 
59 unsigned avformat_version(void)
60 {
63 }
64 
65 const char *avformat_configuration(void)
66 {
67  return FFMPEG_CONFIGURATION;
68 }
69 
70 const char *avformat_license(void)
71 {
72 #define LICENSE_PREFIX "libavformat license: "
73  return &LICENSE_PREFIX FFMPEG_LICENSE[sizeof(LICENSE_PREFIX) - 1];
74 }
75 
77 {
78  return ff_mutex_lock(&avformat_mutex) ? -1 : 0;
79 }
80 
82 {
83  return ff_mutex_unlock(&avformat_mutex) ? -1 : 0;
84 }
85 
86 int64_t av_stream_get_end_pts(const AVStream *st)
87 {
88  if (cffstream(st)->priv_pts) {
89  return cffstream(st)->priv_pts->val;
90  } else
91  return AV_NOPTS_VALUE;
92 }
93 
95 {
96  return cffstream(st)->parser;
97 }
98 
100 {
101  ffstream(st)->need_parsing = type;
102 }
103 
105 {
106  FFFormatContext *const si = ffformatcontext(s);
107  si->inject_global_side_data = 1;
108  for (unsigned i = 0; i < s->nb_streams; i++) {
109  AVStream *st = s->streams[i];
111  }
112 }
113 
115 {
116  av_assert0(!dst->codec_whitelist &&
117  !dst->format_whitelist &&
118  !dst->protocol_whitelist &&
119  !dst->protocol_blacklist);
120  dst-> codec_whitelist = av_strdup(src->codec_whitelist);
121  dst->format_whitelist = av_strdup(src->format_whitelist);
122  dst->protocol_whitelist = av_strdup(src->protocol_whitelist);
123  dst->protocol_blacklist = av_strdup(src->protocol_blacklist);
124  if ( (src-> codec_whitelist && !dst-> codec_whitelist)
125  || (src-> format_whitelist && !dst-> format_whitelist)
126  || (src->protocol_whitelist && !dst->protocol_whitelist)
127  || (src->protocol_blacklist && !dst->protocol_blacklist)) {
128  av_log(dst, AV_LOG_ERROR, "Failed to duplicate black/whitelist\n");
129  return AVERROR(ENOMEM);
130  }
131  return 0;
132 }
133 
135  enum AVCodecID codec_id)
136 {
137  switch (st->codecpar->codec_type) {
138  case AVMEDIA_TYPE_VIDEO:
139  if (s->video_codec) return s->video_codec;
140  break;
141  case AVMEDIA_TYPE_AUDIO:
142  if (s->audio_codec) return s->audio_codec;
143  break;
145  if (s->subtitle_codec) return s->subtitle_codec;
146  break;
147  }
148 
150 }
151 
152 /* an arbitrarily chosen "sane" max packet size -- 50M */
153 #define SANE_CHUNK_SIZE (50000000)
154 
155 /* Read the data in sane-sized chunks and append to pkt.
156  * Return the number of bytes read or an error. */
158 {
159  int orig_size = pkt->size;
160  int ret;
161 
162  do {
163  int prev_size = pkt->size;
164  int read_size;
165 
166  /* When the caller requests a lot of data, limit it to the amount
167  * left in file or SANE_CHUNK_SIZE when it is not known. */
168  read_size = size;
169  if (read_size > SANE_CHUNK_SIZE/10) {
170  read_size = ffio_limit(s, read_size);
171  // If filesize/maxsize is unknown, limit to SANE_CHUNK_SIZE
172  if (ffiocontext(s)->maxsize < 0)
173  read_size = FFMIN(read_size, SANE_CHUNK_SIZE);
174  }
175 
176  ret = av_grow_packet(pkt, read_size);
177  if (ret < 0)
178  break;
179 
180  ret = avio_read(s, pkt->data + prev_size, read_size);
181  if (ret != read_size) {
182  av_shrink_packet(pkt, prev_size + FFMAX(ret, 0));
183  break;
184  }
185 
186  size -= read_size;
187  } while (size > 0);
188  if (size > 0)
190 
191  if (!pkt->size)
193  return pkt->size > orig_size ? pkt->size - orig_size : ret;
194 }
195 
197 {
198 #if FF_API_INIT_PACKET
201  pkt->data = NULL;
202  pkt->size = 0;
204 #else
206 #endif
207  pkt->pos = avio_tell(s);
208 
209  return append_packet_chunked(s, pkt, size);
210 }
211 
213 {
214  if (!pkt->size)
215  return av_get_packet(s, pkt, size);
216  return append_packet_chunked(s, pkt, size);
217 }
218 
219 int av_filename_number_test(const char *filename)
220 {
221  char buf[1024];
222  return filename &&
223  (av_get_frame_filename(buf, sizeof(buf), filename, 1) >= 0);
224 }
225 
227 {
228  FFFormatContext *const si = ffformatcontext(s);
229  int ret;
230  for (unsigned i = 0; i < s->nb_streams; i++)
231  if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC &&
232  s->streams[i]->discard < AVDISCARD_ALL) {
233  if (s->streams[i]->attached_pic.size <= 0) {
235  "Attached picture on stream %d has invalid size, "
236  "ignoring\n", i);
237  continue;
238  }
239 
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 
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 (avpriv_toupper4(tag) == avpriv_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 
607  /* Free existing side data*/
608  for (int i = 0; i < dst->nb_side_data; i++)
609  av_free(dst->side_data[i].data);
610  av_freep(&dst->side_data);
611  dst->nb_side_data = 0;
612 
613  /* Copy side data if present */
614  if (src->nb_side_data) {
615  dst->side_data = av_calloc(src->nb_side_data,
616  sizeof(*dst->side_data));
617  if (!dst->side_data)
618  return AVERROR(ENOMEM);
619  dst->nb_side_data = src->nb_side_data;
620 
621  for (int i = 0; i < src->nb_side_data; i++) {
622  uint8_t *data = av_memdup(src->side_data[i].data,
623  src->side_data[i].size);
624  if (!data)
625  return AVERROR(ENOMEM);
626  dst->side_data[i].type = src->side_data[i].type;
627  dst->side_data[i].size = src->side_data[i].size;
628  dst->side_data[i].data = data;
629  }
630  }
631 
632  return 0;
633 }
634 
635 static void free_stream(AVStream **pst)
636 {
637  AVStream *st = *pst;
638  FFStream *const sti = ffstream(st);
639 
640  if (!st)
641  return;
642 
643  for (int i = 0; i < st->nb_side_data; i++)
644  av_freep(&st->side_data[i].data);
645  av_freep(&st->side_data);
646 
647  if (st->attached_pic.data)
649 
650  av_parser_close(sti->parser);
652  av_bsf_free(&sti->bsfc);
653  av_freep(&sti->priv_pts);
654  av_freep(&sti->index_entries);
655  av_freep(&sti->probe_data.buf);
656 
658 
659  if (sti->info) {
660  av_freep(&sti->info->duration_error);
661  av_freep(&sti->info);
662  }
663 
664  av_dict_free(&st->metadata);
666  av_freep(&st->priv_data);
667 
668  av_freep(pst);
669 }
670 
672 {
673  av_assert0(s->nb_streams>0);
674  av_assert0(s->streams[ s->nb_streams - 1 ] == st);
675 
676  free_stream(&s->streams[ --s->nb_streams ]);
677 }
678 
680 {
681  FFFormatContext *si;
682 
683  if (!s)
684  return;
685  si = ffformatcontext(s);
686 
687  if (s->oformat && s->oformat->deinit && si->initialized)
688  s->oformat->deinit(s);
689 
690  av_opt_free(s);
691  if (s->iformat && s->iformat->priv_class && s->priv_data)
692  av_opt_free(s->priv_data);
693  if (s->oformat && s->oformat->priv_class && s->priv_data)
694  av_opt_free(s->priv_data);
695 
696  for (unsigned i = 0; i < s->nb_streams; i++)
697  free_stream(&s->streams[i]);
698  s->nb_streams = 0;
699 
700  for (unsigned i = 0; i < s->nb_programs; i++) {
701  av_dict_free(&s->programs[i]->metadata);
702  av_freep(&s->programs[i]->stream_index);
703  av_freep(&s->programs[i]);
704  }
705  s->nb_programs = 0;
706 
707  av_freep(&s->programs);
708  av_freep(&s->priv_data);
709  while (s->nb_chapters--) {
710  av_dict_free(&s->chapters[s->nb_chapters]->metadata);
711  av_freep(&s->chapters[s->nb_chapters]);
712  }
713  av_freep(&s->chapters);
714  av_dict_free(&s->metadata);
715  av_dict_free(&si->id3v2_meta);
716  av_packet_free(&si->pkt);
718  av_freep(&s->streams);
720  av_freep(&s->url);
721  av_free(s);
722 }
723 
725 {
726  FFFormatContext *const si = ffformatcontext(s);
727  FFStream *sti;
728  AVStream *st;
729  AVStream **streams;
730 
731  if (s->nb_streams >= s->max_streams) {
732  av_log(s, AV_LOG_ERROR, "Number of streams exceeds max_streams parameter"
733  " (%d), see the documentation if you wish to increase it\n",
734  s->max_streams);
735  return NULL;
736  }
737  streams = av_realloc_array(s->streams, s->nb_streams + 1, sizeof(*streams));
738  if (!streams)
739  return NULL;
740  s->streams = streams;
741 
742 
743  sti = av_mallocz(sizeof(*sti));
744  if (!sti)
745  return NULL;
746  st = &sti->pub;
747 
749  if (!st->codecpar)
750  goto fail;
751 
753  if (!sti->avctx)
754  goto fail;
755 
756  if (s->iformat) {
757  sti->info = av_mallocz(sizeof(*sti->info));
758  if (!sti->info)
759  goto fail;
760 
761 #if FF_API_R_FRAME_RATE
762  sti->info->last_dts = AV_NOPTS_VALUE;
763 #endif
766 
767  /* default pts setting is MPEG-like */
768  avpriv_set_pts_info(st, 33, 1, 90000);
769  /* we set the current DTS to 0 so that formats without any timestamps
770  * but durations get some timestamps, formats with some unknown
771  * timestamps have their first few packets buffered and the
772  * timestamps corrected before they are returned to the user */
773  sti->cur_dts = RELATIVE_TS_BASE;
774  } else {
775  sti->cur_dts = AV_NOPTS_VALUE;
776  }
777 
778  st->index = s->nb_streams;
780  st->duration = AV_NOPTS_VALUE;
781  sti->first_dts = AV_NOPTS_VALUE;
782  sti->probe_packets = s->max_probe_packets;
785 
788  for (int i = 0; i < MAX_REORDER_DELAY + 1; i++)
789  sti->pts_buffer[i] = AV_NOPTS_VALUE;
790 
791  st->sample_aspect_ratio = (AVRational) { 0, 1 };
792 
794 
795  sti->need_context_update = 1;
796 
797  s->streams[s->nb_streams++] = st;
798  return st;
799 fail:
800  free_stream(&st);
801  return NULL;
802 }
803 
805 {
807  int ret;
808 
809  av_log(ac, AV_LOG_TRACE, "new_program: id=0x%04x\n", id);
810 
811  for (unsigned i = 0; i < ac->nb_programs; i++)
812  if (ac->programs[i]->id == id)
813  program = ac->programs[i];
814 
815  if (!program) {
816  program = av_mallocz(sizeof(AVProgram));
817  if (!program)
818  return NULL;
820  if (ret < 0) {
821  av_free(program);
822  return NULL;
823  }
824  program->discard = AVDISCARD_NONE;
825  program->pmt_version = -1;
826  program->id = id;
827  program->pts_wrap_reference = AV_NOPTS_VALUE;
828  program->pts_wrap_behavior = AV_PTS_WRAP_IGNORE;
829  program->start_time =
830  program->end_time = AV_NOPTS_VALUE;
831  }
832  return program;
833 }
834 
836  int64_t start, int64_t end, const char *title)
837 {
838  FFFormatContext *const si = ffformatcontext(s);
839  AVChapter *chapter = NULL;
840  int ret;
841 
842  if (end != AV_NOPTS_VALUE && start > end) {
843  av_log(s, AV_LOG_ERROR, "Chapter end time %"PRId64" before start %"PRId64"\n", end, start);
844  return NULL;
845  }
846 
847  if (!s->nb_chapters) {
848  si->chapter_ids_monotonic = 1;
849  } else if (!si->chapter_ids_monotonic || s->chapters[s->nb_chapters-1]->id >= id) {
850  si->chapter_ids_monotonic = 0;
851  for (unsigned i = 0; i < s->nb_chapters; i++)
852  if (s->chapters[i]->id == id)
853  chapter = s->chapters[i];
854  }
855 
856  if (!chapter) {
857  chapter = av_mallocz(sizeof(AVChapter));
858  if (!chapter)
859  return NULL;
860  ret = av_dynarray_add_nofree(&s->chapters, &s->nb_chapters, chapter);
861  if (ret < 0) {
862  av_free(chapter);
863  return NULL;
864  }
865  }
866  av_dict_set(&chapter->metadata, "title", title, 0);
867  chapter->id = id;
868  chapter->time_base = time_base;
869  chapter->start = start;
870  chapter->end = end;
871 
872  return chapter;
873 }
874 
875 void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
876 {
878  void *tmp;
879 
880  if (idx >= ac->nb_streams) {
881  av_log(ac, AV_LOG_ERROR, "stream index %d is not valid\n", idx);
882  return;
883  }
884 
885  for (unsigned i = 0; i < ac->nb_programs; i++) {
886  if (ac->programs[i]->id != progid)
887  continue;
888  program = ac->programs[i];
889  for (unsigned j = 0; j < program->nb_stream_indexes; j++)
890  if (program->stream_index[j] == idx)
891  return;
892 
893  tmp = av_realloc_array(program->stream_index, program->nb_stream_indexes+1, sizeof(unsigned int));
894  if (!tmp)
895  return;
896  program->stream_index = tmp;
897  program->stream_index[program->nb_stream_indexes++] = idx;
898  return;
899  }
900 }
901 
902 uint64_t ff_ntp_time(void)
903 {
904  return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US;
905 }
906 
907 uint64_t ff_get_formatted_ntp_time(uint64_t ntp_time_us)
908 {
909  uint64_t ntp_ts, frac_part, sec;
910  uint32_t usec;
911 
912  //current ntp time in seconds and micro seconds
913  sec = ntp_time_us / 1000000;
914  usec = ntp_time_us % 1000000;
915 
916  //encoding in ntp timestamp format
917  frac_part = usec * 0xFFFFFFFFULL;
918  frac_part /= 1000000;
919 
920  if (sec > 0xFFFFFFFFULL)
921  av_log(NULL, AV_LOG_WARNING, "NTP time format roll over detected\n");
922 
923  ntp_ts = sec << 32;
924  ntp_ts |= frac_part;
925 
926  return ntp_ts;
927 }
928 
929 uint64_t ff_parse_ntp_time(uint64_t ntp_ts)
930 {
931  uint64_t sec = ntp_ts >> 32;
932  uint64_t frac_part = ntp_ts & 0xFFFFFFFFULL;
933  uint64_t usec = (frac_part * 1000000) / 0xFFFFFFFFULL;
934 
935  return (sec * 1000000) + usec;
936 }
937 
938 int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags)
939 {
940  const char *p;
941  char *q, buf1[20], c;
942  int nd, len, percentd_found;
943 
944  q = buf;
945  p = path;
946  percentd_found = 0;
947  for (;;) {
948  c = *p++;
949  if (c == '\0')
950  break;
951  if (c == '%') {
952  do {
953  nd = 0;
954  while (av_isdigit(*p)) {
955  if (nd >= INT_MAX / 10 - 255)
956  goto fail;
957  nd = nd * 10 + *p++ - '0';
958  }
959  c = *p++;
960  } while (av_isdigit(c));
961 
962  switch (c) {
963  case '%':
964  goto addchar;
965  case 'd':
966  if (!(flags & AV_FRAME_FILENAME_FLAGS_MULTIPLE) && percentd_found)
967  goto fail;
968  percentd_found = 1;
969  if (number < 0)
970  nd += 1;
971  snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
972  len = strlen(buf1);
973  if ((q - buf + len) > buf_size - 1)
974  goto fail;
975  memcpy(q, buf1, len);
976  q += len;
977  break;
978  default:
979  goto fail;
980  }
981  } else {
982 addchar:
983  if ((q - buf) < buf_size - 1)
984  *q++ = c;
985  }
986  }
987  if (!percentd_found)
988  goto fail;
989  *q = '\0';
990  return 0;
991 fail:
992  *q = '\0';
993  return -1;
994 }
995 
996 int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
997 {
998  return av_get_frame_filename2(buf, buf_size, path, number, 0);
999 }
1000 
1001 void av_url_split(char *proto, int proto_size,
1002  char *authorization, int authorization_size,
1003  char *hostname, int hostname_size,
1004  int *port_ptr, char *path, int path_size, const char *url)
1005 {
1006  const char *p, *ls, *at, *at2, *col, *brk;
1007 
1008  if (port_ptr)
1009  *port_ptr = -1;
1010  if (proto_size > 0)
1011  proto[0] = 0;
1012  if (authorization_size > 0)
1013  authorization[0] = 0;
1014  if (hostname_size > 0)
1015  hostname[0] = 0;
1016  if (path_size > 0)
1017  path[0] = 0;
1018 
1019  /* parse protocol */
1020  if ((p = strchr(url, ':'))) {
1021  av_strlcpy(proto, url, FFMIN(proto_size, p + 1 - url));
1022  p++; /* skip ':' */
1023  if (*p == '/')
1024  p++;
1025  if (*p == '/')
1026  p++;
1027  } else {
1028  /* no protocol means plain filename */
1029  av_strlcpy(path, url, path_size);
1030  return;
1031  }
1032 
1033  /* separate path from hostname */
1034  ls = p + strcspn(p, "/?#");
1035  av_strlcpy(path, ls, path_size);
1036 
1037  /* the rest is hostname, use that to parse auth/port */
1038  if (ls != p) {
1039  /* authorization (user[:pass]@hostname) */
1040  at2 = p;
1041  while ((at = strchr(p, '@')) && at < ls) {
1042  av_strlcpy(authorization, at2,
1043  FFMIN(authorization_size, at + 1 - at2));
1044  p = at + 1; /* skip '@' */
1045  }
1046 
1047  if (*p == '[' && (brk = strchr(p, ']')) && brk < ls) {
1048  /* [host]:port */
1049  av_strlcpy(hostname, p + 1,
1050  FFMIN(hostname_size, brk - p));
1051  if (brk[1] == ':' && port_ptr)
1052  *port_ptr = atoi(brk + 2);
1053  } else if ((col = strchr(p, ':')) && col < ls) {
1054  av_strlcpy(hostname, p,
1055  FFMIN(col + 1 - p, hostname_size));
1056  if (port_ptr)
1057  *port_ptr = atoi(col + 1);
1058  } else
1059  av_strlcpy(hostname, p,
1060  FFMIN(ls + 1 - p, hostname_size));
1061  }
1062 }
1063 
1064 int ff_mkdir_p(const char *path)
1065 {
1066  int ret = 0;
1067  char *temp = av_strdup(path);
1068  char *pos = temp;
1069  char tmp_ch = '\0';
1070 
1071  if (!path || !temp) {
1072  return -1;
1073  }
1074 
1075  if (!av_strncasecmp(temp, "/", 1) || !av_strncasecmp(temp, "\\", 1)) {
1076  pos++;
1077  } else if (!av_strncasecmp(temp, "./", 2) || !av_strncasecmp(temp, ".\\", 2)) {
1078  pos += 2;
1079  }
1080 
1081  for ( ; *pos != '\0'; ++pos) {
1082  if (*pos == '/' || *pos == '\\') {
1083  tmp_ch = *pos;
1084  *pos = '\0';
1085  ret = mkdir(temp, 0755);
1086  *pos = tmp_ch;
1087  }
1088  }
1089 
1090  if ((*(pos - 1) != '/') || (*(pos - 1) != '\\')) {
1091  ret = mkdir(temp, 0755);
1092  }
1093 
1094  av_free(temp);
1095  return ret;
1096 }
1097 
1098 char *ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase)
1099 {
1100  static const char hex_table_uc[16] = { '0', '1', '2', '3',
1101  '4', '5', '6', '7',
1102  '8', '9', 'A', 'B',
1103  'C', 'D', 'E', 'F' };
1104  static const char hex_table_lc[16] = { '0', '1', '2', '3',
1105  '4', '5', '6', '7',
1106  '8', '9', 'a', 'b',
1107  'c', 'd', 'e', 'f' };
1108  const char *hex_table = lowercase ? hex_table_lc : hex_table_uc;
1109 
1110  for (int i = 0; i < s; i++) {
1111  buff[i * 2] = hex_table[src[i] >> 4];
1112  buff[i * 2 + 1] = hex_table[src[i] & 0xF];
1113  }
1114 
1115  return buff;
1116 }
1117 
1118 int ff_hex_to_data(uint8_t *data, const char *p)
1119 {
1120  int c, len, v;
1121 
1122  len = 0;
1123  v = 1;
1124  for (;;) {
1125  p += strspn(p, SPACE_CHARS);
1126  if (*p == '\0')
1127  break;
1128  c = av_toupper((unsigned char) *p++);
1129  if (c >= '0' && c <= '9')
1130  c = c - '0';
1131  else if (c >= 'A' && c <= 'F')
1132  c = c - 'A' + 10;
1133  else
1134  break;
1135  v = (v << 4) | c;
1136  if (v & 0x100) {
1137  if (data)
1138  data[len] = v;
1139  len++;
1140  v = 1;
1141  }
1142  }
1143  return len;
1144 }
1145 
1146 void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits,
1147  unsigned int pts_num, unsigned int pts_den)
1148 {
1149  FFStream *const sti = ffstream(st);
1150  AVRational new_tb;
1151  if (av_reduce(&new_tb.num, &new_tb.den, pts_num, pts_den, INT_MAX)) {
1152  if (new_tb.num != pts_num)
1154  "st:%d removing common factor %d from timebase\n",
1155  st->index, pts_num / new_tb.num);
1156  } else
1158  "st:%d has too large timebase, reducing\n", st->index);
1159 
1160  if (new_tb.num <= 0 || new_tb.den <= 0) {
1162  "Ignoring attempt to set invalid timebase %d/%d for st:%d\n",
1163  new_tb.num, new_tb.den,
1164  st->index);
1165  return;
1166  }
1167  st->time_base = new_tb;
1168  sti->avctx->pkt_timebase = new_tb;
1169  st->pts_wrap_bits = pts_wrap_bits;
1170 }
1171 
1172 void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
1173  void *context)
1174 {
1175  const char *ptr = str;
1176 
1177  /* Parse key=value pairs. */
1178  for (;;) {
1179  const char *key;
1180  char *dest = NULL, *dest_end;
1181  int key_len, dest_len = 0;
1182 
1183  /* Skip whitespace and potential commas. */
1184  while (*ptr && (av_isspace(*ptr) || *ptr == ','))
1185  ptr++;
1186  if (!*ptr)
1187  break;
1188 
1189  key = ptr;
1190 
1191  if (!(ptr = strchr(key, '=')))
1192  break;
1193  ptr++;
1194  key_len = ptr - key;
1195 
1196  callback_get_buf(context, key, key_len, &dest, &dest_len);
1197  dest_end = dest + dest_len - 1;
1198 
1199  if (*ptr == '\"') {
1200  ptr++;
1201  while (*ptr && *ptr != '\"') {
1202  if (*ptr == '\\') {
1203  if (!ptr[1])
1204  break;
1205  if (dest && dest < dest_end)
1206  *dest++ = ptr[1];
1207  ptr += 2;
1208  } else {
1209  if (dest && dest < dest_end)
1210  *dest++ = *ptr;
1211  ptr++;
1212  }
1213  }
1214  if (*ptr == '\"')
1215  ptr++;
1216  } else {
1217  for (; *ptr && !(av_isspace(*ptr) || *ptr == ','); ptr++)
1218  if (dest && dest < dest_end)
1219  *dest++ = *ptr;
1220  }
1221  if (dest)
1222  *dest = 0;
1223  }
1224 }
1225 
1227 {
1228  for (unsigned i = 0; i < s->nb_streams; i++)
1229  if (s->streams[i]->id == id)
1230  return i;
1231  return -1;
1232 }
1233 
1235  int std_compliance)
1236 {
1237  if (ofmt) {
1238  unsigned int codec_tag;
1239  if (ofmt->query_codec)
1240  return ofmt->query_codec(codec_id, std_compliance);
1241  else if (ofmt->codec_tag)
1242  return !!av_codec_get_tag2(ofmt->codec_tag, codec_id, &codec_tag);
1243  else if (codec_id == ofmt->video_codec ||
1244  codec_id == ofmt->audio_codec ||
1245  codec_id == ofmt->subtitle_codec ||
1246  codec_id == ofmt->data_codec)
1247  return 1;
1248  }
1249  return AVERROR_PATCHWELCOME;
1250 }
1251 
1253 {
1254 #if CONFIG_NETWORK
1255  int ret;
1256  if ((ret = ff_network_init()) < 0)
1257  return ret;
1258  if ((ret = ff_tls_init()) < 0)
1259  return ret;
1260 #endif
1261  return 0;
1262 }
1263 
1265 {
1266 #if CONFIG_NETWORK
1267  ff_network_close();
1268  ff_tls_deinit();
1269 #endif
1270  return 0;
1271 }
1272 
1274  uint64_t channel_layout, int32_t sample_rate,
1276 {
1277  uint32_t flags = 0;
1278  int size = 4;
1279  uint8_t *data;
1280  if (!pkt)
1281  return AVERROR(EINVAL);
1282  if (channels) {
1283  size += 4;
1285  }
1286  if (channel_layout) {
1287  size += 8;
1289  }
1290  if (sample_rate) {
1291  size += 4;
1293  }
1294  if (width || height) {
1295  size += 8;
1297  }
1299  if (!data)
1300  return AVERROR(ENOMEM);
1301  bytestream_put_le32(&data, flags);
1302  if (channels)
1303  bytestream_put_le32(&data, channels);
1304  if (channel_layout)
1305  bytestream_put_le64(&data, channel_layout);
1306  if (sample_rate)
1307  bytestream_put_le32(&data, sample_rate);
1308  if (width || height) {
1309  bytestream_put_le32(&data, width);
1310  bytestream_put_le32(&data, height);
1311  }
1312  return 0;
1313 }
1314 
1316 {
1317  AVRational undef = {0, 1};
1318  AVRational stream_sample_aspect_ratio = stream ? stream->sample_aspect_ratio : undef;
1319  AVRational codec_sample_aspect_ratio = stream && stream->codecpar ? stream->codecpar->sample_aspect_ratio : undef;
1320  AVRational frame_sample_aspect_ratio = frame ? frame->sample_aspect_ratio : codec_sample_aspect_ratio;
1321 
1322  av_reduce(&stream_sample_aspect_ratio.num, &stream_sample_aspect_ratio.den,
1323  stream_sample_aspect_ratio.num, stream_sample_aspect_ratio.den, INT_MAX);
1324  if (stream_sample_aspect_ratio.num <= 0 || stream_sample_aspect_ratio.den <= 0)
1325  stream_sample_aspect_ratio = undef;
1326 
1327  av_reduce(&frame_sample_aspect_ratio.num, &frame_sample_aspect_ratio.den,
1328  frame_sample_aspect_ratio.num, frame_sample_aspect_ratio.den, INT_MAX);
1329  if (frame_sample_aspect_ratio.num <= 0 || frame_sample_aspect_ratio.den <= 0)
1330  frame_sample_aspect_ratio = undef;
1331 
1332  if (stream_sample_aspect_ratio.num)
1333  return stream_sample_aspect_ratio;
1334  else
1335  return frame_sample_aspect_ratio;
1336 }
1337 
1339 {
1340  AVRational fr = st->r_frame_rate;
1341  AVCodecContext *const avctx = ffstream(st)->avctx;
1342  AVRational codec_fr = avctx->framerate;
1343  AVRational avg_fr = st->avg_frame_rate;
1344 
1345  if (avg_fr.num > 0 && avg_fr.den > 0 && fr.num > 0 && fr.den > 0 &&
1346  av_q2d(avg_fr) < 70 && av_q2d(fr) > 210) {
1347  fr = avg_fr;
1348  }
1349 
1350 
1351  if (avctx->ticks_per_frame > 1) {
1352  if ( codec_fr.num > 0 && codec_fr.den > 0 &&
1353  (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))
1354  fr = codec_fr;
1355  }
1356 
1357  return fr;
1358 }
1359 
1360 /**
1361  * Matches a stream specifier (but ignores requested index).
1362  *
1363  * @param indexptr set to point to the requested stream index if there is one
1364  *
1365  * @return <0 on error
1366  * 0 if st is NOT a matching stream
1367  * >0 if st is a matching stream
1368  */
1370  const char *spec, const char **indexptr, AVProgram **p)
1371 {
1372  int match = 1; /* Stores if the specifier matches so far. */
1373  while (*spec) {
1374  if (*spec <= '9' && *spec >= '0') { /* opt:index */
1375  if (indexptr)
1376  *indexptr = spec;
1377  return match;
1378  } else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||
1379  *spec == 't' || *spec == 'V') { /* opt:[vasdtV] */
1380  enum AVMediaType type;
1381  int nopic = 0;
1382 
1383  switch (*spec++) {
1384  case 'v': type = AVMEDIA_TYPE_VIDEO; break;
1385  case 'a': type = AVMEDIA_TYPE_AUDIO; break;
1386  case 's': type = AVMEDIA_TYPE_SUBTITLE; break;
1387  case 'd': type = AVMEDIA_TYPE_DATA; break;
1388  case 't': type = AVMEDIA_TYPE_ATTACHMENT; break;
1389  case 'V': type = AVMEDIA_TYPE_VIDEO; nopic = 1; break;
1390  default: av_assert0(0);
1391  }
1392  if (*spec && *spec++ != ':') /* If we are not at the end, then another specifier must follow. */
1393  return AVERROR(EINVAL);
1394 
1395  if (type != st->codecpar->codec_type)
1396  match = 0;
1397  if (nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC))
1398  match = 0;
1399  } else if (*spec == 'p' && *(spec + 1) == ':') {
1400  int prog_id;
1401  int found = 0;
1402  char *endptr;
1403  spec += 2;
1404  prog_id = strtol(spec, &endptr, 0);
1405  /* Disallow empty id and make sure that if we are not at the end, then another specifier must follow. */
1406  if (spec == endptr || (*endptr && *endptr++ != ':'))
1407  return AVERROR(EINVAL);
1408  spec = endptr;
1409  if (match) {
1410  for (unsigned i = 0; i < s->nb_programs; i++) {
1411  if (s->programs[i]->id != prog_id)
1412  continue;
1413 
1414  for (unsigned j = 0; j < s->programs[i]->nb_stream_indexes; j++) {
1415  if (st->index == s->programs[i]->stream_index[j]) {
1416  found = 1;
1417  if (p)
1418  *p = s->programs[i];
1419  i = s->nb_programs;
1420  break;
1421  }
1422  }
1423  }
1424  }
1425  if (!found)
1426  match = 0;
1427  } else if (*spec == '#' ||
1428  (*spec == 'i' && *(spec + 1) == ':')) {
1429  int stream_id;
1430  char *endptr;
1431  spec += 1 + (*spec == 'i');
1432  stream_id = strtol(spec, &endptr, 0);
1433  if (spec == endptr || *endptr) /* Disallow empty id and make sure we are at the end. */
1434  return AVERROR(EINVAL);
1435  return match && (stream_id == st->id);
1436  } else if (*spec == 'm' && *(spec + 1) == ':') {
1438  char *key, *val;
1439  int ret;
1440 
1441  if (match) {
1442  spec += 2;
1443  val = strchr(spec, ':');
1444 
1445  key = val ? av_strndup(spec, val - spec) : av_strdup(spec);
1446  if (!key)
1447  return AVERROR(ENOMEM);
1448 
1449  tag = av_dict_get(st->metadata, key, NULL, 0);
1450  if (tag) {
1451  if (!val || !strcmp(tag->value, val + 1))
1452  ret = 1;
1453  else
1454  ret = 0;
1455  } else
1456  ret = 0;
1457 
1458  av_freep(&key);
1459  }
1460  return match && ret;
1461  } else if (*spec == 'u' && *(spec + 1) == '\0') {
1462  AVCodecParameters *par = st->codecpar;
1463  int val;
1464  switch (par->codec_type) {
1465  case AVMEDIA_TYPE_AUDIO:
1466  val = par->sample_rate && par->channels;
1467  if (par->format == AV_SAMPLE_FMT_NONE)
1468  return 0;
1469  break;
1470  case AVMEDIA_TYPE_VIDEO:
1471  val = par->width && par->height;
1472  if (par->format == AV_PIX_FMT_NONE)
1473  return 0;
1474  break;
1475  case AVMEDIA_TYPE_UNKNOWN:
1476  val = 0;
1477  break;
1478  default:
1479  val = 1;
1480  break;
1481  }
1482  return match && (par->codec_id != AV_CODEC_ID_NONE && val != 0);
1483  } else {
1484  return AVERROR(EINVAL);
1485  }
1486  }
1487 
1488  return match;
1489 }
1490 
1491 
1493  const char *spec)
1494 {
1495  int ret, index;
1496  char *endptr;
1497  const char *indexptr = NULL;
1498  AVProgram *p = NULL;
1499  int nb_streams;
1500 
1501  ret = match_stream_specifier(s, st, spec, &indexptr, &p);
1502  if (ret < 0)
1503  goto error;
1504 
1505  if (!indexptr)
1506  return ret;
1507 
1508  index = strtol(indexptr, &endptr, 0);
1509  if (*endptr) { /* We can't have anything after the requested index. */
1510  ret = AVERROR(EINVAL);
1511  goto error;
1512  }
1513 
1514  /* This is not really needed but saves us a loop for simple stream index specifiers. */
1515  if (spec == indexptr)
1516  return (index == st->index);
1517 
1518  /* If we requested a matching stream index, we have to ensure st is that. */
1519  nb_streams = p ? p->nb_stream_indexes : s->nb_streams;
1520  for (int i = 0; i < nb_streams && index >= 0; i++) {
1521  AVStream *candidate = p ? s->streams[p->stream_index[i]] : s->streams[i];
1522  ret = match_stream_specifier(s, candidate, spec, NULL, NULL);
1523  if (ret < 0)
1524  goto error;
1525  if (ret > 0 && index-- == 0 && st == candidate)
1526  return 1;
1527  }
1528  return 0;
1529 
1530 error:
1531  if (ret == AVERROR(EINVAL))
1532  av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
1533  return ret;
1534 }
1535 
1537 {
1538  static const uint8_t avci100_1080p_extradata[] = {
1539  // SPS
1540  0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
1541  0xb6, 0xd4, 0x20, 0x22, 0x33, 0x19, 0xc6, 0x63,
1542  0x23, 0x21, 0x01, 0x11, 0x98, 0xce, 0x33, 0x19,
1543  0x18, 0x21, 0x02, 0x56, 0xb9, 0x3d, 0x7d, 0x7e,
1544  0x4f, 0xe3, 0x3f, 0x11, 0xf1, 0x9e, 0x08, 0xb8,
1545  0x8c, 0x54, 0x43, 0xc0, 0x78, 0x02, 0x27, 0xe2,
1546  0x70, 0x1e, 0x30, 0x10, 0x10, 0x14, 0x00, 0x00,
1547  0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0xca,
1548  0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1549  // PPS
1550  0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x33, 0x48,
1551  0xd0
1552  };
1553  static const uint8_t avci100_1080i_extradata[] = {
1554  // SPS
1555  0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
1556  0xb6, 0xd4, 0x20, 0x22, 0x33, 0x19, 0xc6, 0x63,
1557  0x23, 0x21, 0x01, 0x11, 0x98, 0xce, 0x33, 0x19,
1558  0x18, 0x21, 0x03, 0x3a, 0x46, 0x65, 0x6a, 0x65,
1559  0x24, 0xad, 0xe9, 0x12, 0x32, 0x14, 0x1a, 0x26,
1560  0x34, 0xad, 0xa4, 0x41, 0x82, 0x23, 0x01, 0x50,
1561  0x2b, 0x1a, 0x24, 0x69, 0x48, 0x30, 0x40, 0x2e,
1562  0x11, 0x12, 0x08, 0xc6, 0x8c, 0x04, 0x41, 0x28,
1563  0x4c, 0x34, 0xf0, 0x1e, 0x01, 0x13, 0xf2, 0xe0,
1564  0x3c, 0x60, 0x20, 0x20, 0x28, 0x00, 0x00, 0x03,
1565  0x00, 0x08, 0x00, 0x00, 0x03, 0x01, 0x94, 0x20,
1566  // PPS
1567  0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x33, 0x48,
1568  0xd0
1569  };
1570  static const uint8_t avci50_1080p_extradata[] = {
1571  // SPS
1572  0x00, 0x00, 0x00, 0x01, 0x67, 0x6e, 0x10, 0x28,
1573  0xa6, 0xd4, 0x20, 0x32, 0x33, 0x0c, 0x71, 0x18,
1574  0x88, 0x62, 0x10, 0x19, 0x19, 0x86, 0x38, 0x8c,
1575  0x44, 0x30, 0x21, 0x02, 0x56, 0x4e, 0x6f, 0x37,
1576  0xcd, 0xf9, 0xbf, 0x81, 0x6b, 0xf3, 0x7c, 0xde,
1577  0x6e, 0x6c, 0xd3, 0x3c, 0x05, 0xa0, 0x22, 0x7e,
1578  0x5f, 0xfc, 0x00, 0x0c, 0x00, 0x13, 0x8c, 0x04,
1579  0x04, 0x05, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00,
1580  0x00, 0x03, 0x00, 0x32, 0x84, 0x00, 0x00, 0x00,
1581  // PPS
1582  0x00, 0x00, 0x00, 0x01, 0x68, 0xee, 0x31, 0x12,
1583  0x11
1584  };
1585  static const uint8_t avci50_1080i_extradata[] = {
1586  // SPS
1587  0x00, 0x00, 0x00, 0x01, 0x67, 0x6e, 0x10, 0x28,
1588  0xa6, 0xd4, 0x20, 0x32, 0x33, 0x0c, 0x71, 0x18,
1589  0x88, 0x62, 0x10, 0x19, 0x19, 0x86, 0x38, 0x8c,
1590  0x44, 0x30, 0x21, 0x02, 0x56, 0x4e, 0x6e, 0x61,
1591  0x87, 0x3e, 0x73, 0x4d, 0x98, 0x0c, 0x03, 0x06,
1592  0x9c, 0x0b, 0x73, 0xe6, 0xc0, 0xb5, 0x18, 0x63,
1593  0x0d, 0x39, 0xe0, 0x5b, 0x02, 0xd4, 0xc6, 0x19,
1594  0x1a, 0x79, 0x8c, 0x32, 0x34, 0x24, 0xf0, 0x16,
1595  0x81, 0x13, 0xf7, 0xff, 0x80, 0x02, 0x00, 0x01,
1596  0xf1, 0x80, 0x80, 0x80, 0xa0, 0x00, 0x00, 0x03,
1597  0x00, 0x20, 0x00, 0x00, 0x06, 0x50, 0x80, 0x00,
1598  // PPS
1599  0x00, 0x00, 0x00, 0x01, 0x68, 0xee, 0x31, 0x12,
1600  0x11
1601  };
1602  static const uint8_t avci100_720p_extradata[] = {
1603  // SPS
1604  0x00, 0x00, 0x00, 0x01, 0x67, 0x7a, 0x10, 0x29,
1605  0xb6, 0xd4, 0x20, 0x2a, 0x33, 0x1d, 0xc7, 0x62,
1606  0xa1, 0x08, 0x40, 0x54, 0x66, 0x3b, 0x8e, 0xc5,
1607  0x42, 0x02, 0x10, 0x25, 0x64, 0x2c, 0x89, 0xe8,
1608  0x85, 0xe4, 0x21, 0x4b, 0x90, 0x83, 0x06, 0x95,
1609  0xd1, 0x06, 0x46, 0x97, 0x20, 0xc8, 0xd7, 0x43,
1610  0x08, 0x11, 0xc2, 0x1e, 0x4c, 0x91, 0x0f, 0x01,
1611  0x40, 0x16, 0xec, 0x07, 0x8c, 0x04, 0x04, 0x05,
1612  0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03,
1613  0x00, 0x64, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00,
1614  // PPS
1615  0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x31, 0x12,
1616  0x11
1617  };
1618  static const uint8_t avci50_720p_extradata[] = {
1619  // SPS
1620  0x00, 0x00, 0x00, 0x01, 0x67, 0x6e, 0x10, 0x20,
1621  0xa6, 0xd4, 0x20, 0x32, 0x33, 0x0c, 0x71, 0x18,
1622  0x88, 0x62, 0x10, 0x19, 0x19, 0x86, 0x38, 0x8c,
1623  0x44, 0x30, 0x21, 0x02, 0x56, 0x4e, 0x6f, 0x37,
1624  0xcd, 0xf9, 0xbf, 0x81, 0x6b, 0xf3, 0x7c, 0xde,
1625  0x6e, 0x6c, 0xd3, 0x3c, 0x0f, 0x01, 0x6e, 0xff,
1626  0xc0, 0x00, 0xc0, 0x01, 0x38, 0xc0, 0x40, 0x40,
1627  0x50, 0x00, 0x00, 0x03, 0x00, 0x10, 0x00, 0x00,
1628  0x06, 0x48, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
1629  // PPS
1630  0x00, 0x00, 0x00, 0x01, 0x68, 0xee, 0x31, 0x12,
1631  0x11
1632  };
1633 
1634  const uint8_t *data = NULL;
1635  int ret, size = 0;
1636 
1637  if (st->codecpar->width == 1920) {
1639  data = avci100_1080p_extradata;
1640  size = sizeof(avci100_1080p_extradata);
1641  } else {
1642  data = avci100_1080i_extradata;
1643  size = sizeof(avci100_1080i_extradata);
1644  }
1645  } else if (st->codecpar->width == 1440) {
1647  data = avci50_1080p_extradata;
1648  size = sizeof(avci50_1080p_extradata);
1649  } else {
1650  data = avci50_1080i_extradata;
1651  size = sizeof(avci50_1080i_extradata);
1652  }
1653  } else if (st->codecpar->width == 1280) {
1654  data = avci100_720p_extradata;
1655  size = sizeof(avci100_720p_extradata);
1656  } else if (st->codecpar->width == 960) {
1657  data = avci50_720p_extradata;
1658  size = sizeof(avci50_720p_extradata);
1659  }
1660 
1661  if (!size)
1662  return 0;
1663 
1664  if ((ret = ff_alloc_extradata(st->codecpar, size)) < 0)
1665  return ret;
1666  memcpy(st->codecpar->extradata, data, size);
1667 
1668  return 0;
1669 }
1670 
1672  enum AVPacketSideDataType type, size_t *size)
1673 {
1674  for (int i = 0; i < st->nb_side_data; i++) {
1675  if (st->side_data[i].type == type) {
1676  if (size)
1677  *size = st->side_data[i].size;
1678  return st->side_data[i].data;
1679  }
1680  }
1681  if (size)
1682  *size = 0;
1683  return NULL;
1684 }
1685 
1687  uint8_t *data, size_t size)
1688 {
1689  AVPacketSideData *sd, *tmp;
1690 
1691  for (int i = 0; i < st->nb_side_data; i++) {
1692  sd = &st->side_data[i];
1693 
1694  if (sd->type == type) {
1695  av_freep(&sd->data);
1696  sd->data = data;
1697  sd->size = size;
1698  return 0;
1699  }
1700  }
1701 
1702  if ((unsigned)st->nb_side_data + 1 >= INT_MAX / sizeof(*st->side_data))
1703  return AVERROR(ERANGE);
1704 
1705  tmp = av_realloc(st->side_data, (st->nb_side_data + 1) * sizeof(*tmp));
1706  if (!tmp) {
1707  return AVERROR(ENOMEM);
1708  }
1709 
1710  st->side_data = tmp;
1711  st->nb_side_data++;
1712 
1713  sd = &st->side_data[st->nb_side_data - 1];
1714  sd->type = type;
1715  sd->data = data;
1716  sd->size = size;
1717 
1718  return 0;
1719 }
1720 
1722  size_t size)
1723 {
1724  int ret;
1725  uint8_t *data = av_malloc(size);
1726 
1727  if (!data)
1728  return NULL;
1729 
1731  if (ret < 0) {
1732  av_freep(&data);
1733  return NULL;
1734  }
1735 
1736  return data;
1737 }
1738 
1739 int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
1740 {
1741  int ret;
1742  const AVBitStreamFilter *bsf;
1743  FFStream *const sti = ffstream(st);
1744  AVBSFContext *bsfc;
1745 
1746  av_assert0(!sti->bsfc);
1747 
1748  if (!(bsf = av_bsf_get_by_name(name))) {
1749  av_log(NULL, AV_LOG_ERROR, "Unknown bitstream filter '%s'\n", name);
1750  return AVERROR_BSF_NOT_FOUND;
1751  }
1752 
1753  if ((ret = av_bsf_alloc(bsf, &bsfc)) < 0)
1754  return ret;
1755 
1756  bsfc->time_base_in = st->time_base;
1757  if ((ret = avcodec_parameters_copy(bsfc->par_in, st->codecpar)) < 0) {
1758  av_bsf_free(&bsfc);
1759  return ret;
1760  }
1761 
1762  if (args && bsfc->filter->priv_class) {
1763  const AVOption *opt = av_opt_next(bsfc->priv_data, NULL);
1764  const char * shorthand[2] = {NULL};
1765 
1766  if (opt)
1767  shorthand[0] = opt->name;
1768 
1769  if ((ret = av_opt_set_from_string(bsfc->priv_data, args, shorthand, "=", ":")) < 0) {
1770  av_bsf_free(&bsfc);
1771  return ret;
1772  }
1773  }
1774 
1775  if ((ret = av_bsf_init(bsfc)) < 0) {
1776  av_bsf_free(&bsfc);
1777  return ret;
1778  }
1779 
1780  sti->bsfc = bsfc;
1781 
1783  "Automatically inserted bitstream filter '%s'; args='%s'\n",
1784  name, args ? args : "");
1785  return 1;
1786 }
1787 
1789 {
1790  if (!s->oformat)
1791  return AVERROR(EINVAL);
1792 
1793  if (!(s->oformat->flags & AVFMT_NOFILE))
1794  return s->io_open(s, &s->pb, url, AVIO_FLAG_WRITE, options);
1795  return 0;
1796 }
1797 
1799 {
1800  if (*pb)
1801  s->io_close(s, *pb);
1802  *pb = NULL;
1803 }
1804 
1805 int ff_is_http_proto(const char *filename) {
1806  const char *proto = avio_find_protocol_name(filename);
1807  return proto ? (!av_strcasecmp(proto, "http") || !av_strcasecmp(proto, "https")) : 0;
1808 }
1809 
1810 int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds)
1811 {
1812  AVDictionaryEntry *entry;
1813  int64_t parsed_timestamp;
1814  int ret;
1815  if ((entry = av_dict_get(s->metadata, "creation_time", NULL, 0))) {
1816  if ((ret = av_parse_time(&parsed_timestamp, entry->value, 0)) >= 0) {
1817  *timestamp = return_seconds ? parsed_timestamp / 1000000 : parsed_timestamp;
1818  return 1;
1819  } else {
1820  av_log(s, AV_LOG_WARNING, "Failed to parse creation_time %s\n", entry->value);
1821  return ret;
1822  }
1823  }
1824  return 0;
1825 }
1826 
1828 {
1829  int64_t timestamp;
1830  int ret = ff_parse_creation_time_metadata(s, &timestamp, 0);
1831  if (ret == 1)
1832  return avpriv_dict_set_timestamp(&s->metadata, "creation_time", timestamp);
1833  return ret;
1834 }
1835 
1836 int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t *palette)
1837 {
1838  uint8_t *side_data;
1839  size_t size;
1840 
1842  if (side_data) {
1843  if (size != AVPALETTE_SIZE) {
1844  av_log(s, AV_LOG_ERROR, "Invalid palette side data\n");
1845  return AVERROR_INVALIDDATA;
1846  }
1847  memcpy(palette, side_data, AVPALETTE_SIZE);
1848  return 1;
1849  }
1850 
1851  if (ret == CONTAINS_PAL) {
1852  for (int i = 0; i < AVPALETTE_COUNT; i++)
1853  palette[i] = AV_RL32(pkt->data + pkt->size - AVPALETTE_SIZE + i*4);
1854  return 1;
1855  }
1856 
1857  return 0;
1858 }
1859 
1861 {
1862  int ret;
1863  char *str;
1864 
1865  ret = av_bprint_finalize(buf, &str);
1866  if (ret < 0)
1867  return ret;
1868  if (!av_bprint_is_complete(buf)) {
1869  av_free(str);
1870  return AVERROR(ENOMEM);
1871  }
1872 
1873  par->extradata = str;
1874  /* Note: the string is NUL terminated (so extradata can be read as a
1875  * string), but the ending character is not accounted in the size (in
1876  * binary formats you are likely not supposed to mux that character). When
1877  * extradata is copied, it is also padded with AV_INPUT_BUFFER_PADDING_SIZE
1878  * zeros. */
1879  par->extradata_size = buf->len;
1880  return 0;
1881 }
1882 
1884  AVStream *ost, const AVStream *ist,
1886 {
1887  const AVCodecContext *const dec_ctx = cffstream(ist)->avctx;
1888  AVCodecContext *const enc_ctx = ffstream(ost)->avctx;
1889 
1890  enc_ctx->time_base = ist->time_base;
1891  /*
1892  * Avi is a special case here because it supports variable fps but
1893  * having the fps and timebase differe significantly adds quite some
1894  * overhead
1895  */
1896  if (!strcmp(ofmt->name, "avi")) {
1897 #if FF_API_R_FRAME_RATE
1898  if (copy_tb == AVFMT_TBCF_AUTO && ist->r_frame_rate.num
1899  && av_q2d(ist->r_frame_rate) >= av_q2d(ist->avg_frame_rate)
1900  && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(ist->time_base)
1901  && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(dec_ctx->time_base)
1902  && av_q2d(ist->time_base) < 1.0/500 && av_q2d(dec_ctx->time_base) < 1.0/500
1903  || copy_tb == AVFMT_TBCF_R_FRAMERATE) {
1904  enc_ctx->time_base.num = ist->r_frame_rate.den;
1905  enc_ctx->time_base.den = 2*ist->r_frame_rate.num;
1906  enc_ctx->ticks_per_frame = 2;
1907  } else
1908 #endif
1910  && av_q2d(ist->time_base) < 1.0/500
1911  || copy_tb == AVFMT_TBCF_DECODER) {
1912  enc_ctx->time_base = dec_ctx->time_base;
1913  enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
1914  enc_ctx->time_base.den *= 2;
1915  enc_ctx->ticks_per_frame = 2;
1916  }
1917  } else if (!(ofmt->flags & AVFMT_VARIABLE_FPS)
1918  && !av_match_name(ofmt->name, "mov,mp4,3gp,3g2,psp,ipod,ismv,f4v")) {
1921  && av_q2d(ist->time_base) < 1.0/500
1922  || copy_tb == AVFMT_TBCF_DECODER) {
1923  enc_ctx->time_base = dec_ctx->time_base;
1924  enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
1925  }
1926  }
1927 
1928  if ((enc_ctx->codec_tag == AV_RL32("tmcd") || ost->codecpar->codec_tag == AV_RL32("tmcd"))
1930  && dec_ctx->time_base.num > 0
1931  && 121LL*dec_ctx->time_base.num > dec_ctx->time_base.den) {
1932  enc_ctx->time_base = dec_ctx->time_base;
1933  }
1934 
1935  av_reduce(&enc_ctx->time_base.num, &enc_ctx->time_base.den,
1936  enc_ctx->time_base.num, enc_ctx->time_base.den, INT_MAX);
1937 
1938  return 0;
1939 }
1940 
1942 {
1943  // See avformat_transfer_internal_stream_timing_info() TODO.
1944  return cffstream(st)->avctx->time_base;
1945 }
1946 
1948 {
1949  av_assert0(url);
1950  av_freep(&s->url);
1951  s->url = url;
1952 }
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
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:417
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
ff_data_to_hex
char * ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase)
Definition: utils.c:1098
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:377
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:496
AVChapter::metadata
AVDictionary * metadata
Definition: avformat.h:1072
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:724
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:76
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:1038
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:1064
FFStream::first_dts
int64_t first_dts
Timestamp corresponding to the last dts sync point.
Definition: internal.h:425
ff_ntp_time
uint64_t ff_ntp_time(void)
Get the current time since NTP epoch in microseconds.
Definition: utils.c:902
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:71
FFStream::last_IP_pts
int64_t last_IP_pts
Definition: internal.h:393
ffformatcontext
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition: internal.h:186
thread.h
AVStream::priv_data
void * priv_data
Definition: avformat.h:866
AVFMT_VARIABLE_FPS
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:470
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:827
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:906
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:1681
AVFMT_TBCF_DECODER
@ AVFMT_TBCF_DECODER
Definition: avformat.h:2747
av_stream_get_parser
struct AVCodecParserContext * av_stream_get_parser(const AVStream *st)
Definition: utils.c:94
avpriv_toupper4
unsigned int avpriv_toupper4(unsigned int x)
Definition: utils.c:877
FFFormatContext::raw_packet_buffer
struct PacketList * raw_packet_buffer
Raw packets from the demuxer, prior to parsing and decoding.
Definition: internal.h:101
AVCodecTag::id
enum AVCodecID id
Definition: internal.h:51
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
Definition: avformat.h:804
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:2746
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1177
index
fg index
Definition: ffmpeg_filter.c:168
AVPacketSideData
Definition: packet.h:314
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:373
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:938
AVOption
AVOption.
Definition: opt.h:247
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:924
AVChapter::start
int64_t start
Definition: avformat.h:1071
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:163
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:449
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:269
LIBAVFORMAT_VERSION_MICRO
#define LIBAVFORMAT_VERSION_MICRO
Definition: version.h:36
FFStream::bsfc
AVBSFContext * bsfc
bitstream filter to run on stream
Definition: internal.h:208
AVFormatContext::programs
AVProgram ** programs
Definition: avformat.h:1278
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:835
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:448
cffstream
static const av_always_inline FFStream * cffstream(const AVStream *st)
Definition: internal.h:434
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:370
av_get_frame_filename
int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
Definition: utils.c:996
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:425
sample_rate
sample_rate
Definition: ffmpeg_filter.c:156
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_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:508
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
FFStream::bsf
AVBSFContext * bsf
Definition: internal.h:228
ff_free_stream
void ff_free_stream(AVFormatContext *s, AVStream *st)
Definition: utils.c:671
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:219
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_format_io_close
void ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: utils.c:1798
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:226
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
RELATIVE_TS_BASE
#define RELATIVE_TS_BASE
Definition: internal.h:456
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:86
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:429
AV_CODEC_ID_PCM_S16BE
@ AV_CODEC_ID_PCM_S16BE
Definition: codec_id.h:315
fail
#define fail()
Definition: checkasm.h:127
av_shrink_packet
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition: avpacket.c:114
avformat_version
unsigned avformat_version(void)
Return the LIBAVFORMAT_VERSION_INT constant.
Definition: utils.c:59
AVStreamParseType
AVStreamParseType
Definition: avformat.h:778
free_stream
static void free_stream(AVStream **pst)
Definition: utils.c:635
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:486
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: defs.h:48
AVChapter
Definition: avformat.h:1068
val
static double val(void *priv, double ch)
Definition: aeval.c:76
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
ist
fg inputs[0] ist
Definition: ffmpeg_filter.c:182
av_new_program
AVProgram * av_new_program(AVFormatContext *ac, int id)
Definition: utils.c:804
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:900
AV_PTS_WRAP_IGNORE
#define AV_PTS_WRAP_IGNORE
Options for behavior on timestamp wrap detection.
Definition: avformat.h:846
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:1836
avformat_network_init
int avformat_network_init(void)
Do global initialization of network libraries.
Definition: utils.c:1252
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:933
FFStream::priv_pts
FFFrac * priv_pts
Definition: internal.h:239
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:1561
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:1315
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:426
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:1273
RAW_PACKET_BUFFER_SIZE
#define RAW_PACKET_BUFFER_SIZE
Remaining size available for raw_packet_buffer, in bytes.
Definition: internal.h:132
AVCodecTag
Definition: internal.h:50
AVOutputFormat::data_codec
enum AVCodecID data_codec
default data codec
Definition: avformat.h:603
AVProgram::id
int id
Definition: avformat.h:1034
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:1234
AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
@ AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
Definition: packet.h:450
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:1071
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:250
s
#define s(width, name)
Definition: cbs_vp9.c:257
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
FFFormatContext::raw_packet_buffer_remaining_size
int raw_packet_buffer_remaining_size
Definition: internal.h:133
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:1277
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:212
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:448
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:506
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:604
FFFormatContext::raw_packet_buffer_end
struct PacketList * raw_packet_buffer_end
Definition: internal.h:102
ff_find_stream_index
int ff_find_stream_index(AVFormatContext *s, int id)
Find stream index based on format-specific stream ID.
Definition: utils.c:1226
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:408
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:289
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:521
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:1118
match_stream_specifier
static int match_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec, const char **indexptr, AVProgram **p)
Matches a stream specifier (but ignores requested index).
Definition: utils.c:1369
FFFormatContext
Definition: internal.h:72
FFStream::need_parsing
enum AVStreamParseType need_parsing
Definition: internal.h:402
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:1109
FFStream::pub
AVStream pub
The public context.
Definition: internal.h:195
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:1004
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:1788
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:880
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:1646
AVPacketSideData::type
enum AVPacketSideDataType type
Definition: packet.h:317
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:1686
av_opt_set_from_string
int av_opt_set_from_string(void *ctx, const char *opts, const char *const *shorthand, const char *key_val_sep, const char *pairs_sep)
Parse the key-value pairs list in opts.
Definition: opt.c:1562
AVPALETTE_SIZE
#define AVPALETTE_SIZE
Definition: pixfmt.h:32
src
#define src
Definition: vp8dsp.c:255
AVERROR_BSF_NOT_FOUND
#define AVERROR_BSF_NOT_FOUND
Bitstream filter not found.
Definition: error.h:51
AV_CODEC_ID_PCM_S64BE
@ AV_CODEC_ID_PCM_S64BE
Definition: codec_id.h:346
avpriv_stream_set_need_parsing
void avpriv_stream_set_need_parsing(AVStream *st, enum AVStreamParseType type)
Definition: utils.c:99
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:1146
AVProgram::stream_index
unsigned int * stream_index
Definition: avformat.h:1037
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:915
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:1271
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1614
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:1172
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:587
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:907
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:425
FFFormatContext::inject_global_side_data
int inject_global_side_data
Definition: internal.h:151
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:902
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:919
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:267
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1165
FFFormatContext::id3v2_meta
AVDictionary * id3v2_meta
ID3v2 tag useful for MP3 demuxing.
Definition: internal.h:173
AVOutputFormat::flags
int flags
can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:515
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
FFFormatContext::parse_queue
struct PacketList * parse_queue
Packets split by the parser get queued here.
Definition: internal.h:106
FFFormatContext::packet_buffer_end
struct PacketList * packet_buffer_end
Definition: internal.h:90
options
const OptionDef options[]
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:1827
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:1492
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:121
FFFrac::val
int64_t val
Definition: internal.h:68
FFStream
Definition: internal.h:191
ff_copy_whiteblacklists
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src)
Copies the whilelists from one context to the other.
Definition: utils.c:114
bps
unsigned bps
Definition: movenc.c:1596
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:163
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
NTP_OFFSET_US
#define NTP_OFFSET_US
Definition: internal.h:505
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:1338
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:1941
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:463
AVTimebaseSource
AVTimebaseSource
Definition: avformat.h:2745
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:81
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:913
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:1739
AV_DISPOSITION_HEARING_IMPAIRED
#define AV_DISPOSITION_HEARING_IMPAIRED
stream for hearing impaired audiences
Definition: avformat.h:817
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:104
FFStream::pts_wrap_behavior
int pts_wrap_behavior
Options for behavior, when a wrap is detected.
Definition: internal.h:350
AVPacketSideDataType
AVPacketSideDataType
Definition: packet.h:40
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:399
AV_FRAME_FILENAME_FLAGS_MULTIPLE
#define AV_FRAME_FILENAME_FLAGS_MULTIPLE
Allow multiple d.
Definition: avformat.h:2595
FFStream::probe_data
AVProbeData probe_data
Definition: internal.h:386
AVStream::side_data
AVPacketSideData * side_data
An array of side data that applies to the whole stream (i.e.
Definition: avformat.h:953
FFStream::extract_extradata
struct FFStream::@258 extract_extradata
SANE_CHUNK_SIZE
#define SANE_CHUNK_SIZE
Definition: utils.c:153
ffio_limit
int ffio_limit(AVIOContext *s, int size)
Definition: aviobuf.c:1051
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
bprint.h
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:48
AVOutputFormat
Definition: avformat.h:495
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
avio_internal.h
FFFormatContext::parse_queue_end
struct PacketList * parse_queue_end
Definition: internal.h:107
width
static int width
Definition: utils.c:158
AVChapter::id
int64_t id
unique ID to identify the chapter
Definition: avformat.h:1069
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:246
internal.h
AVCodecParameters::height
int height
Definition: codec_par.h:127
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:1553
avformat_mutex
static AVMutex avformat_mutex
Definition: utils.c:52
AV_CODEC_ID_PCM_F64BE
@ AV_CODEC_ID_PCM_F64BE
Definition: codec_id.h:336
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:1001
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:365
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:1033
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
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:196
av_opt_next
const AVOption * av_opt_next(const void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
Definition: opt.c:45
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:134
AVCodecParserContext
Definition: avcodec.h:2775
AVBSFContext::priv_data
void * priv_data
Opaque filter-specific private data.
Definition: bsf.h:62
ff_tls_deinit
void ff_tls_deinit(void)
Definition: network.c:46
AVStream::disposition
int disposition
AV_DISPOSITION_* bit field.
Definition: avformat.h:904
AV_DISPOSITION_VISUAL_IMPAIRED
#define AV_DISPOSITION_VISUAL_IMPAIRED
stream for visual impaired audiences
Definition: avformat.h:818
tag
uint32_t tag
Definition: movenc.c:1595
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:864
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:857
pixfmt.h
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:1805
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:957
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:1860
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:1671
dict.h
network.h
FFStream::info
struct FFStream::@259 * info
Stream information used internally by avformat_find_stream_info()
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
ost
OutputStream * ost
Definition: ffmpeg_filter.c:163
FFFormatContext::chapter_ids_monotonic
int chapter_ids_monotonic
Set if chapter ids are strictly monotonic.
Definition: internal.h:183
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
FFFormatContext::packet_buffer
struct PacketList * packet_buffer
This buffer is only needed when packets were already buffered but not decoded, for example to get the...
Definition: internal.h:89
avformat_network_deinit
int avformat_network_deinit(void)
Undo the initialization done by avformat_network_init.
Definition: utils.c:1264
av_program_add_stream_index
void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
Definition: utils.c:875
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:858
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:1883
AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT
@ AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT
Definition: packet.h:447
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:225
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:218
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:679
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:625
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:599
av_format_ffversion
const char av_format_ffversion[]
Definition: utils.c:50
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:507
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:993
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:1947
avformat_license
const char * avformat_license(void)
Return the libavformat license.
Definition: utils.c:70
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:274
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
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
FFFormatContext::pkt
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
Definition: internal.h:128
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:65
AV_CODEC_ID_PCM_F64LE
@ AV_CODEC_ID_PCM_F64LE
Definition: codec_id.h:337
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:408
AVDictionaryEntry
Definition: dict.h:79
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
AVPacket
This structure stores compressed data.
Definition: packet.h:350
ff_flush_packet_queue
void ff_flush_packet_queue(AVFormatContext *s)
Definition: utils.c:299
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
av_dict_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:217
FFStream::cur_dts
int64_t cur_dts
Definition: internal.h:426
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:393
format
fg outputs[0] format
Definition: ffmpeg_filter.c:175
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:1721
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:156
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:929
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:235
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
FFStream::last_dts
int64_t last_dts
Definition: internal.h:246
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:927
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
FFStream::parser
struct AVCodecParserContext * parser
Definition: internal.h:403
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:1810
ffio_read_size
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:674
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:890
avstring.h
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:578
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:1013
AVChapter::time_base
AVRational time_base
time base in which the start/end timestamps are specified
Definition: avformat.h:1070
AVCodecTag::tag
unsigned int tag
Definition: internal.h:52
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:338
AV_CODEC_ID_PCM_S24BE
@ AV_CODEC_ID_PCM_S24BE
Definition: codec_id.h:327
avpriv_packet_list_put
int avpriv_packet_list_put(PacketList **packet_buffer, PacketList **plast_pktl, AVPacket *pkt, int(*copy)(AVPacket *dst, const AVPacket *src), int flags)
Append an AVPacket to the list.
Definition: avpacket.c:531
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
avpriv_packet_list_free
void avpriv_packet_list_free(PacketList **pkt_buf, PacketList **pkt_buf_end)
Wipe the list and unref all the packets in it.
Definition: avpacket.c:587
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:1536
append_packet_chunked
static int append_packet_chunked(AVIOContext *s, AVPacket *pkt, int size)
Definition: utils.c:157