FFmpeg
flvdec.c
Go to the documentation of this file.
1 /*
2  * FLV demuxer
3  * Copyright (c) 2003 The FFmpeg Project
4  *
5  * This demuxer will generate a 1 byte extradata for VP6F content.
6  * It is composed of:
7  * - upper 4 bits: difference between encoded width and visible width
8  * - lower 4 bits: difference between encoded height and visible height
9  *
10  * This file is part of FFmpeg.
11  *
12  * FFmpeg is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * FFmpeg is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with FFmpeg; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  */
26 
27 #include "libavutil/avassert.h"
28 #include "libavutil/avstring.h"
30 #include "libavutil/dict.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/internal.h"
35 #include "libavutil/intfloat.h"
36 #include "libavutil/intreadwrite.h"
38 #include "avformat.h"
39 #include "demux.h"
40 #include "internal.h"
41 #include "flv.h"
42 
43 #define VALIDATE_INDEX_TS_THRESH 2500
44 
45 #define RESYNC_BUFFER_SIZE (1<<20)
46 
47 #define MAX_DEPTH 16 ///< arbitrary limit to prevent unbounded recursion
48 
49 typedef struct FLVMasteringMeta {
50  double r_x;
51  double r_y;
52  double g_x;
53  double g_y;
54  double b_x;
55  double b_y;
56  double white_x;
57  double white_y;
58  double max_luminance;
59  double min_luminance;
61 
62 typedef struct FLVMetaVideoColor {
65  uint64_t primaries;
66  uint64_t max_cll;
67  uint64_t max_fall;
70 
71 typedef struct FLVContext {
72  const AVClass *class; ///< Class for private options.
73  int trust_metadata; ///< configure streams according onMetaData
74  int trust_datasize; ///< trust data size of FLVTag
75  int dump_full_metadata; ///< Dump full metadata of the onMetadata
76  int wrong_dts; ///< wrong dts due to negative cts
81  struct {
84  } validate_index[2];
88 
90 
93 
104 
107 } FLVContext;
108 
109 /* AMF date type */
110 typedef struct amf_date {
111  double milliseconds;
112  int16_t timezone;
113 } amf_date;
114 
115 static int probe(const AVProbeData *p, int live)
116 {
117  const uint8_t *d = p->buf;
118  unsigned offset = AV_RB32(d + 5);
119 
120  if (d[0] == 'F' &&
121  d[1] == 'L' &&
122  d[2] == 'V' &&
123  d[3] < 5 && d[5] == 0 &&
124  offset + 100 < p->buf_size &&
125  offset > 8) {
126  int is_live = !memcmp(d + offset + 40, "NGINX RTMP", 10);
127 
128  if (live == is_live)
129  return AVPROBE_SCORE_MAX;
130  }
131  return 0;
132 }
133 
134 static int flv_probe(const AVProbeData *p)
135 {
136  return probe(p, 0);
137 }
138 
139 static int live_flv_probe(const AVProbeData *p)
140 {
141  return probe(p, 1);
142 }
143 
144 static int kux_probe(const AVProbeData *p)
145 {
146  const uint8_t *d = p->buf;
147 
148  if (d[0] == 'K' &&
149  d[1] == 'D' &&
150  d[2] == 'K' &&
151  d[3] == 0 &&
152  d[4] == 0) {
153  return AVPROBE_SCORE_EXTENSION + 1;
154  }
155  return 0;
156 }
157 
159 {
160  FLVContext *flv = s->priv_data;
161  AVStream *stream = NULL;
162  unsigned int i = 0;
163 
164  if (flv->last_keyframe_stream_index < 0) {
165  av_log(s, AV_LOG_DEBUG, "keyframe stream hasn't been created\n");
166  return;
167  }
168 
169  av_assert0(flv->last_keyframe_stream_index <= s->nb_streams);
170  stream = s->streams[flv->last_keyframe_stream_index];
171 
172  if (ffstream(stream)->nb_index_entries == 0) {
173  for (i = 0; i < flv->keyframe_count; i++) {
174  av_log(s, AV_LOG_TRACE, "keyframe filepositions = %"PRId64" times = %"PRId64"\n",
177  flv->keyframe_times[i], 0, 0, AVINDEX_KEYFRAME);
178  }
179  } else
180  av_log(s, AV_LOG_WARNING, "Skipping duplicate index\n");
181 
182  if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
183  av_freep(&flv->keyframe_times);
185  flv->keyframe_count = 0;
186  }
187 }
188 
190 {
191  FFFormatContext *const si = ffformatcontext(s);
192  FLVContext *flv = s->priv_data;
194  if (!st)
195  return NULL;
197  if (s->nb_streams>=3 ||( s->nb_streams==2
198  && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE
199  && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE
200  && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_DATA
201  && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_DATA))
202  s->ctx_flags &= ~AVFMTCTX_NOHEADER;
204  st->codecpar->bit_rate = flv->audio_bit_rate;
206  }
208  st->codecpar->bit_rate = flv->video_bit_rate;
210  st->avg_frame_rate = flv->framerate;
211  }
212 
213 
214  avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
215  flv->last_keyframe_stream_index = s->nb_streams - 1;
217  return st;
218 }
219 
221 {
222  int bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
223  int flv_codecid = flags & FLV_AUDIO_CODECID_MASK;
224  int codec_id;
225 
226  if (!apar->codec_id && !apar->codec_tag)
227  return 1;
228 
229  if (apar->bits_per_coded_sample != bits_per_coded_sample)
230  return 0;
231 
232  switch (flv_codecid) {
233  // no distinction between S16 and S8 PCM codec flags
234  case FLV_CODECID_PCM:
235  codec_id = bits_per_coded_sample == 8
237 #if HAVE_BIGENDIAN
239 #else
241 #endif
242  return codec_id == apar->codec_id;
243  case FLV_CODECID_PCM_LE:
244  codec_id = bits_per_coded_sample == 8
247  return codec_id == apar->codec_id;
248  case FLV_CODECID_AAC:
249  return apar->codec_id == AV_CODEC_ID_AAC;
250  case FLV_CODECID_ADPCM:
251  return apar->codec_id == AV_CODEC_ID_ADPCM_SWF;
252  case FLV_CODECID_SPEEX:
253  return apar->codec_id == AV_CODEC_ID_SPEEX;
254  case FLV_CODECID_MP3:
255  return apar->codec_id == AV_CODEC_ID_MP3;
259  return apar->codec_id == AV_CODEC_ID_NELLYMOSER;
261  return apar->sample_rate == 8000 &&
264  return apar->sample_rate == 8000 &&
266  default:
267  return apar->codec_tag == (flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
268  }
269 }
270 
272  AVCodecParameters *apar, int flv_codecid)
273 {
274  switch (flv_codecid) {
275  // no distinction between S16 and S8 PCM codec flags
276  case FLV_CODECID_PCM:
277  apar->codec_id = apar->bits_per_coded_sample == 8
279 #if HAVE_BIGENDIAN
281 #else
283 #endif
284  break;
285  case FLV_CODECID_PCM_LE:
286  apar->codec_id = apar->bits_per_coded_sample == 8
289  break;
290  case FLV_CODECID_AAC:
291  apar->codec_id = AV_CODEC_ID_AAC;
292  break;
293  case FLV_CODECID_ADPCM:
295  break;
296  case FLV_CODECID_SPEEX:
297  apar->codec_id = AV_CODEC_ID_SPEEX;
298  apar->sample_rate = 16000;
299  break;
300  case FLV_CODECID_MP3:
301  apar->codec_id = AV_CODEC_ID_MP3;
303  break;
305  // in case metadata does not otherwise declare samplerate
306  apar->sample_rate = 8000;
308  break;
310  apar->sample_rate = 16000;
312  break;
315  break;
317  apar->sample_rate = 8000;
319  break;
321  apar->sample_rate = 8000;
323  break;
324  default:
325  avpriv_request_sample(s, "Audio codec (%x)",
326  flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
327  apar->codec_tag = flv_codecid >> FLV_AUDIO_CODECID_OFFSET;
328  }
329 }
330 
331 static int flv_same_video_codec(AVCodecParameters *vpar, uint32_t flv_codecid)
332 {
333  if (!vpar->codec_id && !vpar->codec_tag)
334  return 1;
335 
336  switch (flv_codecid) {
337  case MKBETAG('h', 'v', 'c', '1'):
338  return vpar->codec_id == AV_CODEC_ID_HEVC;
339  case MKBETAG('a', 'v', '0', '1'):
340  return vpar->codec_id == AV_CODEC_ID_AV1;
341  case MKBETAG('v', 'p', '0', '9'):
342  return vpar->codec_id == AV_CODEC_ID_VP9;
343  case FLV_CODECID_H263:
344  return vpar->codec_id == AV_CODEC_ID_FLV1;
345  case FLV_CODECID_SCREEN:
346  return vpar->codec_id == AV_CODEC_ID_FLASHSV;
347  case FLV_CODECID_SCREEN2:
348  return vpar->codec_id == AV_CODEC_ID_FLASHSV2;
349  case FLV_CODECID_VP6:
350  return vpar->codec_id == AV_CODEC_ID_VP6F;
351  case FLV_CODECID_VP6A:
352  return vpar->codec_id == AV_CODEC_ID_VP6A;
353  case FLV_CODECID_H264:
354  return vpar->codec_id == AV_CODEC_ID_H264;
355  default:
356  return vpar->codec_tag == flv_codecid;
357  }
358 }
359 
361  uint32_t flv_codecid, int read)
362 {
363  FFStream *const vstreami = ffstream(vstream);
364  int ret = 0;
365  AVCodecParameters *par = vstream->codecpar;
366  enum AVCodecID old_codec_id = vstream->codecpar->codec_id;
367 
368  switch (flv_codecid) {
369  case MKBETAG('h', 'v', 'c', '1'):
370  par->codec_id = AV_CODEC_ID_HEVC;
372  break;
373  case MKBETAG('a', 'v', '0', '1'):
374  par->codec_id = AV_CODEC_ID_AV1;
376  break;
377  case MKBETAG('v', 'p', '0', '9'):
378  par->codec_id = AV_CODEC_ID_VP9;
380  break;
381  case FLV_CODECID_H263:
382  par->codec_id = AV_CODEC_ID_FLV1;
383  break;
385  par->codec_id = AV_CODEC_ID_H263;
386  break; // Really mean it this time
387  case FLV_CODECID_SCREEN:
389  break;
390  case FLV_CODECID_SCREEN2:
392  break;
393  case FLV_CODECID_VP6:
394  par->codec_id = AV_CODEC_ID_VP6F;
395  case FLV_CODECID_VP6A:
396  if (flv_codecid == FLV_CODECID_VP6A)
397  par->codec_id = AV_CODEC_ID_VP6A;
398  if (read) {
399  if (par->extradata_size != 1) {
400  ff_alloc_extradata(par, 1);
401  }
402  if (par->extradata)
403  par->extradata[0] = avio_r8(s->pb);
404  else
405  avio_skip(s->pb, 1);
406  }
407  ret = 1; // 1 byte body size adjustment for flv_read_packet()
408  break;
409  case FLV_CODECID_H264:
410  par->codec_id = AV_CODEC_ID_H264;
412  break;
413  case FLV_CODECID_MPEG4:
415  break;
416  default:
417  avpriv_request_sample(s, "Video codec (%x)", flv_codecid);
418  par->codec_tag = flv_codecid;
419  }
420 
421  if (!vstreami->need_context_update && par->codec_id != old_codec_id) {
422  avpriv_request_sample(s, "Changing the codec id midstream");
423  return AVERROR_PATCHWELCOME;
424  }
425 
426  return ret;
427 }
428 
429 static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize)
430 {
431  int ret;
432  int length = avio_rb16(ioc);
433  if (length >= buffsize) {
434  avio_skip(ioc, length);
435  return -1;
436  }
437 
438  ret = avio_read(ioc, buffer, length);
439  if (ret < 0)
440  return ret;
441  if (ret < length)
442  return AVERROR_INVALIDDATA;
443 
444  buffer[length] = '\0';
445 
446  return length;
447 }
448 
450 {
451  FLVContext *flv = s->priv_data;
452  unsigned int timeslen = 0, fileposlen = 0, i;
453  char str_val[256];
454  int64_t *times = NULL;
455  int64_t *filepositions = NULL;
456  int ret = AVERROR(ENOSYS);
457  int64_t initial_pos = avio_tell(ioc);
458 
459  if (flv->keyframe_count > 0) {
460  av_log(s, AV_LOG_DEBUG, "keyframes have been parsed\n");
461  return 0;
462  }
463  av_assert0(!flv->keyframe_times);
465 
466  if (s->flags & AVFMT_FLAG_IGNIDX)
467  return 0;
468 
469  while (avio_tell(ioc) < max_pos - 2 &&
470  amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
471  int64_t **current_array;
472  unsigned int arraylen;
473  int factor;
474 
475  // Expect array object in context
476  if (avio_r8(ioc) != AMF_DATA_TYPE_ARRAY)
477  break;
478 
479  arraylen = avio_rb32(ioc);
480  if (arraylen>>28)
481  break;
482 
483  if (!strcmp(KEYFRAMES_TIMESTAMP_TAG , str_val) && !times) {
484  current_array = &times;
485  timeslen = arraylen;
486  factor = 1000;
487  } else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) &&
488  !filepositions) {
489  current_array = &filepositions;
490  fileposlen = arraylen;
491  factor = 1;
492  } else
493  // unexpected metatag inside keyframes, will not use such
494  // metadata for indexing
495  break;
496 
497  if (!(*current_array = av_mallocz(sizeof(**current_array) * arraylen))) {
498  ret = AVERROR(ENOMEM);
499  goto finish;
500  }
501 
502  for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) {
503  double d;
504  if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER)
505  goto invalid;
506  d = av_int2double(avio_rb64(ioc)) * factor;
507  if (isnan(d) || d < INT64_MIN || d > INT64_MAX)
508  goto invalid;
509  if (avio_feof(ioc))
510  goto invalid;
511  current_array[0][i] = d;
512  }
513  if (times && filepositions) {
514  // All done, exiting at a position allowing amf_parse_object
515  // to finish parsing the object
516  ret = 0;
517  break;
518  }
519  }
520 
521  if (timeslen == fileposlen && fileposlen>1 && max_pos <= filepositions[0]) {
522  for (i = 0; i < FFMIN(2,fileposlen); i++) {
523  flv->validate_index[i].pos = filepositions[i];
524  flv->validate_index[i].dts = times[i];
525  flv->validate_count = i + 1;
526  }
527  flv->keyframe_times = times;
528  flv->keyframe_filepositions = filepositions;
529  flv->keyframe_count = timeslen;
530  times = NULL;
531  filepositions = NULL;
532  } else {
533 invalid:
534  av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n");
535  }
536 
537 finish:
538  av_freep(&times);
539  av_freep(&filepositions);
540  avio_seek(ioc, initial_pos, SEEK_SET);
541  return ret;
542 }
543 
545  AVStream *vstream, const char *key,
546  int64_t max_pos, int depth)
547 {
548  AVCodecParameters *apar, *vpar;
549  FLVContext *flv = s->priv_data;
550  AVIOContext *ioc;
551  AMFDataType amf_type;
552  FLVMetaVideoColor *meta_video_color = flv->metaVideoColor;
553  char str_val[1024];
554  double num_val;
555  amf_date date;
556 
557  if (depth > MAX_DEPTH)
558  return AVERROR_PATCHWELCOME;
559 
560  num_val = 0;
561  ioc = s->pb;
562  if (avio_feof(ioc))
563  return AVERROR_EOF;
564  amf_type = avio_r8(ioc);
565 
566  switch (amf_type) {
568  num_val = av_int2double(avio_rb64(ioc));
569  break;
570  case AMF_DATA_TYPE_BOOL:
571  num_val = avio_r8(ioc);
572  break;
574  if (amf_get_string(ioc, str_val, sizeof(str_val)) < 0) {
575  av_log(s, AV_LOG_ERROR, "AMF_DATA_TYPE_STRING parsing failed\n");
576  return -1;
577  }
578  break;
580  if (key &&
581  (ioc->seekable & AVIO_SEEKABLE_NORMAL) &&
582  !strcmp(KEYFRAMES_TAG, key) && depth == 1)
583  if (parse_keyframes_index(s, ioc, max_pos) < 0)
584  av_log(s, AV_LOG_ERROR, "Keyframe index parsing failed\n");
585  else
587  while (avio_tell(ioc) < max_pos - 2 &&
588  amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
589  if (amf_parse_object(s, astream, vstream, str_val, max_pos,
590  depth + 1) < 0)
591  return -1; // if we couldn't skip, bomb out.
592  if (avio_r8(ioc) != AMF_END_OF_OBJECT) {
593  av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_OBJECT\n");
594  return -1;
595  }
596  break;
597  case AMF_DATA_TYPE_NULL:
600  break; // these take up no additional space
602  {
603  unsigned v;
604  avio_skip(ioc, 4); // skip 32-bit max array index
605  while (avio_tell(ioc) < max_pos - 2 &&
606  amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
607  // this is the only case in which we would want a nested
608  // parse to not skip over the object
609  if (amf_parse_object(s, astream, vstream, str_val, max_pos,
610  depth + 1) < 0)
611  return -1;
612  v = avio_r8(ioc);
613  if (v != AMF_END_OF_OBJECT) {
614  av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_MIXEDARRAY, found %d\n", v);
615  return -1;
616  }
617  break;
618  }
619  case AMF_DATA_TYPE_ARRAY:
620  {
621  unsigned int arraylen, i;
622 
623  arraylen = avio_rb32(ioc);
624  for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++)
626  depth + 1) < 0)
627  return -1; // if we couldn't skip, bomb out.
628  }
629  break;
630  case AMF_DATA_TYPE_DATE:
631  // timestamp (double) and UTC offset (int16)
632  date.milliseconds = av_int2double(avio_rb64(ioc));
633  date.timezone = avio_rb16(ioc);
634  break;
635  default: // unsupported type, we couldn't skip
636  av_log(s, AV_LOG_ERROR, "unsupported amf type %d\n", amf_type);
637  return -1;
638  }
639 
640  if (key) {
641  apar = astream ? astream->codecpar : NULL;
642  vpar = vstream ? vstream->codecpar : NULL;
643 
644  // stream info doesn't live any deeper than the first object
645  if (depth == 1) {
646  if (amf_type == AMF_DATA_TYPE_NUMBER ||
647  amf_type == AMF_DATA_TYPE_BOOL) {
648  if (!strcmp(key, "duration"))
649  s->duration = num_val * AV_TIME_BASE;
650  else if (!strcmp(key, "videodatarate") &&
651  0 <= (int)(num_val * 1024.0))
652  flv->video_bit_rate = num_val * 1024.0;
653  else if (!strcmp(key, "audiodatarate") &&
654  0 <= (int)(num_val * 1024.0))
655  flv->audio_bit_rate = num_val * 1024.0;
656  else if (!strcmp(key, "framerate")) {
657  flv->framerate = av_d2q(num_val, 1000);
658  if (vstream)
659  vstream->avg_frame_rate = flv->framerate;
660  } else if (flv->trust_metadata) {
661  if (!strcmp(key, "videocodecid") && vpar) {
662  int ret = flv_set_video_codec(s, vstream, num_val, 0);
663  if (ret < 0)
664  return ret;
665  } else if (!strcmp(key, "audiocodecid") && apar) {
666  int id = ((int)num_val) << FLV_AUDIO_CODECID_OFFSET;
667  flv_set_audio_codec(s, astream, apar, id);
668  } else if (!strcmp(key, "audiosamplerate") && apar) {
669  apar->sample_rate = num_val;
670  } else if (!strcmp(key, "audiosamplesize") && apar) {
671  apar->bits_per_coded_sample = num_val;
672  } else if (!strcmp(key, "stereo") && apar) {
673  av_channel_layout_default(&apar->ch_layout, num_val + 1);
674  } else if (!strcmp(key, "width") && vpar) {
675  vpar->width = num_val;
676  } else if (!strcmp(key, "height") && vpar) {
677  vpar->height = num_val;
678  } else if (!strcmp(key, "datastream")) {
680  if (!st)
681  return AVERROR(ENOMEM);
683  }
684  }
685  }
686  if (amf_type == AMF_DATA_TYPE_STRING) {
687  if (!strcmp(key, "encoder")) {
688  int version = -1;
689  if (1 == sscanf(str_val, "Open Broadcaster Software v0.%d", &version)) {
690  if (version > 0 && version <= 655)
691  flv->broken_sizes = 1;
692  }
693  } else if (!strcmp(key, "metadatacreator")) {
694  if ( !strcmp (str_val, "MEGA")
695  || !strncmp(str_val, "FlixEngine", 10))
696  flv->broken_sizes = 1;
697  }
698  }
699  }
700 
701  if (meta_video_color) {
702  if (amf_type == AMF_DATA_TYPE_NUMBER ||
703  amf_type == AMF_DATA_TYPE_BOOL) {
704  if (!strcmp(key, "colorPrimaries")) {
705  meta_video_color->primaries = num_val;
706  } else if (!strcmp(key, "transferCharacteristics")) {
707  meta_video_color->transfer_characteristics = num_val;
708  } else if (!strcmp(key, "matrixCoefficients")) {
709  meta_video_color->matrix_coefficients = num_val;
710  } else if (!strcmp(key, "maxFall")) {
711  meta_video_color->max_fall = num_val;
712  } else if (!strcmp(key, "maxCLL")) {
713  meta_video_color->max_cll = num_val;
714  } else if (!strcmp(key, "redX")) {
715  meta_video_color->mastering_meta.r_x = num_val;
716  } else if (!strcmp(key, "redY")) {
717  meta_video_color->mastering_meta.r_y = num_val;
718  } else if (!strcmp(key, "greenX")) {
719  meta_video_color->mastering_meta.g_x = num_val;
720  } else if (!strcmp(key, "greenY")) {
721  meta_video_color->mastering_meta.g_y = num_val;
722  } else if (!strcmp(key, "blueX")) {
723  meta_video_color->mastering_meta.b_x = num_val;
724  } else if (!strcmp(key, "blueY")) {
725  meta_video_color->mastering_meta.b_y = num_val;
726  } else if (!strcmp(key, "whitePointX")) {
727  meta_video_color->mastering_meta.white_x = num_val;
728  } else if (!strcmp(key, "whitePointY")) {
729  meta_video_color->mastering_meta.white_y = num_val;
730  } else if (!strcmp(key, "maxLuminance")) {
731  meta_video_color->mastering_meta.max_luminance = num_val;
732  } else if (!strcmp(key, "minLuminance")) {
733  meta_video_color->mastering_meta.min_luminance = num_val;
734  }
735  }
736  }
737 
738  if (amf_type == AMF_DATA_TYPE_OBJECT && s->nb_streams == 1 &&
739  ((!apar && !strcmp(key, "audiocodecid")) ||
740  (!vpar && !strcmp(key, "videocodecid"))))
741  s->ctx_flags &= ~AVFMTCTX_NOHEADER; //If there is either audio/video missing, codecid will be an empty object
742 
743  if ((!strcmp(key, "duration") ||
744  !strcmp(key, "filesize") ||
745  !strcmp(key, "width") ||
746  !strcmp(key, "height") ||
747  !strcmp(key, "videodatarate") ||
748  !strcmp(key, "framerate") ||
749  !strcmp(key, "videocodecid") ||
750  !strcmp(key, "audiodatarate") ||
751  !strcmp(key, "audiosamplerate") ||
752  !strcmp(key, "audiosamplesize") ||
753  !strcmp(key, "stereo") ||
754  !strcmp(key, "audiocodecid") ||
755  !strcmp(key, "datastream")) && !flv->dump_full_metadata)
756  return 0;
757 
758  s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
759  if (amf_type == AMF_DATA_TYPE_BOOL) {
760  av_strlcpy(str_val, num_val > 0 ? "true" : "false",
761  sizeof(str_val));
762  av_dict_set(&s->metadata, key, str_val, 0);
763  } else if (amf_type == AMF_DATA_TYPE_NUMBER) {
764  snprintf(str_val, sizeof(str_val), "%.f", num_val);
765  av_dict_set(&s->metadata, key, str_val, 0);
766  } else if (amf_type == AMF_DATA_TYPE_STRING) {
767  av_dict_set(&s->metadata, key, str_val, 0);
768  } else if ( amf_type == AMF_DATA_TYPE_DATE
769  && isfinite(date.milliseconds)
770  && date.milliseconds > INT64_MIN/1000
771  && date.milliseconds < INT64_MAX/1000
772  ) {
773  // timezone is ignored, since there is no easy way to offset the UTC
774  // timestamp into the specified timezone
775  avpriv_dict_set_timestamp(&s->metadata, key, 1000 * (int64_t)date.milliseconds);
776  }
777  }
778 
779  return 0;
780 }
781 
782 #define TYPE_ONTEXTDATA 1
783 #define TYPE_ONCAPTION 2
784 #define TYPE_ONCAPTIONINFO 3
785 #define TYPE_UNKNOWN 9
786 
788 {
789  FLVContext *flv = s->priv_data;
791  AVStream *stream, *astream, *vstream;
792  AVStream av_unused *dstream;
793  AVIOContext *ioc;
794  int i;
795  char buffer[32];
796 
797  astream = NULL;
798  vstream = NULL;
799  dstream = NULL;
800  ioc = s->pb;
801 
802  // first object needs to be "onMetaData" string
803  type = avio_r8(ioc);
804  if (type != AMF_DATA_TYPE_STRING ||
805  amf_get_string(ioc, buffer, sizeof(buffer)) < 0)
806  return TYPE_UNKNOWN;
807 
808  if (!strcmp(buffer, "onTextData"))
809  return TYPE_ONTEXTDATA;
810 
811  if (!strcmp(buffer, "onCaption"))
812  return TYPE_ONCAPTION;
813 
814  if (!strcmp(buffer, "onCaptionInfo"))
815  return TYPE_ONCAPTIONINFO;
816 
817  if (strcmp(buffer, "onMetaData") && strcmp(buffer, "onCuePoint") && strcmp(buffer, "|RtmpSampleAccess")) {
818  av_log(s, AV_LOG_DEBUG, "Unknown type %s\n", buffer);
819  return TYPE_UNKNOWN;
820  }
821 
822  // find the streams now so that amf_parse_object doesn't need to do
823  // the lookup every time it is called.
824  for (i = 0; i < s->nb_streams; i++) {
825  stream = s->streams[i];
826  if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
827  vstream = stream;
829  } else if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
830  astream = stream;
831  if (flv->last_keyframe_stream_index == -1)
833  } else if (stream->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
834  dstream = stream;
835  }
836 
837  // parse the second object (we want a mixed array)
838  if (amf_parse_object(s, astream, vstream, buffer, next_pos, 0) < 0)
839  return -1;
840 
841  return 0;
842 }
843 
845 {
846  FFFormatContext *const si = ffformatcontext(s);
847  int flags;
848  FLVContext *flv = s->priv_data;
849  int offset;
850  int pre_tag_size = 0;
851 
852  /* Actual FLV data at 0xe40000 in KUX file */
853  if(!strcmp(s->iformat->name, "kux"))
854  avio_skip(s->pb, 0xe40000);
855 
856  avio_skip(s->pb, 4);
857  flags = avio_r8(s->pb);
858 
860 
861  s->ctx_flags |= AVFMTCTX_NOHEADER;
862 
863  offset = avio_rb32(s->pb);
864  avio_seek(s->pb, offset, SEEK_SET);
865 
866  /* Annex E. The FLV File Format
867  * E.3 TheFLVFileBody
868  * Field Type Comment
869  * PreviousTagSize0 UI32 Always 0
870  * */
871  pre_tag_size = avio_rb32(s->pb);
872  if (pre_tag_size) {
873  av_log(s, AV_LOG_WARNING, "Read FLV header error, input file is not a standard flv format, first PreviousTagSize0 always is 0\n");
874  }
875 
876  s->start_time = 0;
877  flv->sum_flv_tag_size = 0;
878  flv->last_keyframe_stream_index = -1;
879 
880  return 0;
881 }
882 
884 {
885  int i;
886  FLVContext *flv = s->priv_data;
887  for (i=0; i<FLV_STREAM_TYPE_NB; i++)
888  av_freep(&flv->new_extradata[i]);
889  av_freep(&flv->keyframe_times);
891  av_freep(&flv->metaVideoColor);
892  return 0;
893 }
894 
896 {
897  int ret;
898  if (!size)
899  return 0;
900 
901  if ((ret = ff_get_extradata(s, st->codecpar, s->pb, size)) < 0)
902  return ret;
903  ffstream(st)->need_context_update = 1;
904  return 0;
905 }
906 
907 static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream,
908  int size)
909 {
910  if (!size)
911  return 0;
912 
913  av_free(flv->new_extradata[stream]);
914  flv->new_extradata[stream] = av_mallocz(size +
916  if (!flv->new_extradata[stream])
917  return AVERROR(ENOMEM);
918  flv->new_extradata_size[stream] = size;
919  avio_read(pb, flv->new_extradata[stream], size);
920  return 0;
921 }
922 
924 {
926  "Found invalid index entries, clearing the index.\n");
927  for (unsigned i = 0; i < s->nb_streams; i++) {
928  FFStream *const sti = ffstream(s->streams[i]);
929  int out = 0;
930  /* Remove all index entries that point to >= pos */
931  for (int j = 0; j < sti->nb_index_entries; j++)
932  if (sti->index_entries[j].pos < pos)
933  sti->index_entries[out++] = sti->index_entries[j];
934  sti->nb_index_entries = out;
935  }
936 }
937 
938 static int amf_skip_tag(AVIOContext *pb, AMFDataType type, int depth)
939 {
940  int nb = -1, ret, parse_name = 1;
941 
942  if (depth > MAX_DEPTH)
943  return AVERROR_PATCHWELCOME;
944 
945  if (avio_feof(pb))
946  return AVERROR_EOF;
947 
948  switch (type) {
950  avio_skip(pb, 8);
951  break;
952  case AMF_DATA_TYPE_BOOL:
953  avio_skip(pb, 1);
954  break;
956  avio_skip(pb, avio_rb16(pb));
957  break;
958  case AMF_DATA_TYPE_ARRAY:
959  parse_name = 0;
961  nb = avio_rb32(pb);
962  if (nb < 0)
963  return AVERROR_INVALIDDATA;
965  while(!pb->eof_reached && (nb-- > 0 || type != AMF_DATA_TYPE_ARRAY)) {
966  if (parse_name) {
967  int size = avio_rb16(pb);
968  if (!size) {
969  avio_skip(pb, 1);
970  break;
971  }
972  avio_skip(pb, size);
973  }
974  if ((ret = amf_skip_tag(pb, avio_r8(pb), depth + 1)) < 0)
975  return ret;
976  }
977  break;
978  case AMF_DATA_TYPE_NULL:
980  break;
981  default:
982  return AVERROR_INVALIDDATA;
983  }
984  return 0;
985 }
986 
988  int64_t dts, int64_t next)
989 {
990  AVIOContext *pb = s->pb;
991  AVStream *st = NULL;
992  char buf[20];
993  int ret = AVERROR_INVALIDDATA;
994  int i, length = -1;
995  int array = 0;
996 
997  switch (avio_r8(pb)) {
998  case AMF_DATA_TYPE_ARRAY:
999  array = 1;
1001  avio_seek(pb, 4, SEEK_CUR);
1002  case AMF_DATA_TYPE_OBJECT:
1003  break;
1004  default:
1005  goto skip;
1006  }
1007 
1008  while (array || (ret = amf_get_string(pb, buf, sizeof(buf))) > 0) {
1009  AMFDataType type = avio_r8(pb);
1010  if (type == AMF_DATA_TYPE_STRING && (array || !strcmp(buf, "text"))) {
1011  length = avio_rb16(pb);
1012  ret = av_get_packet(pb, pkt, length);
1013  if (ret < 0)
1014  goto skip;
1015  else
1016  break;
1017  } else {
1018  if ((ret = amf_skip_tag(pb, type, 0)) < 0)
1019  goto skip;
1020  }
1021  }
1022 
1023  if (length < 0) {
1025  goto skip;
1026  }
1027 
1028  for (i = 0; i < s->nb_streams; i++) {
1029  st = s->streams[i];
1031  break;
1032  }
1033 
1034  if (i == s->nb_streams) {
1036  if (!st)
1037  return AVERROR(ENOMEM);
1039  }
1040 
1041  pkt->dts = dts;
1042  pkt->pts = dts;
1043  pkt->size = ret;
1044 
1045  pkt->stream_index = st->index;
1047 
1048 skip:
1049  avio_seek(s->pb, next + 4, SEEK_SET);
1050 
1051  return ret;
1052 }
1053 
1055 {
1056  FLVContext *flv = s->priv_data;
1057  int64_t i;
1058  int64_t pos = avio_tell(s->pb);
1059 
1060  for (i=0; !avio_feof(s->pb); i++) {
1061  int j = i & (RESYNC_BUFFER_SIZE-1);
1062  int j1 = j + RESYNC_BUFFER_SIZE;
1063  flv->resync_buffer[j ] =
1064  flv->resync_buffer[j1] = avio_r8(s->pb);
1065 
1066  if (i >= 8 && pos) {
1067  uint8_t *d = flv->resync_buffer + j1 - 8;
1068  if (d[0] == 'F' &&
1069  d[1] == 'L' &&
1070  d[2] == 'V' &&
1071  d[3] < 5 && d[5] == 0) {
1072  av_log(s, AV_LOG_WARNING, "Concatenated FLV detected, might fail to demux, decode and seek %"PRId64"\n", flv->last_ts);
1073  flv->time_offset = flv->last_ts + 1;
1074  flv->time_pos = avio_tell(s->pb);
1075  }
1076  }
1077 
1078  if (i > 22) {
1079  unsigned lsize2 = AV_RB32(flv->resync_buffer + j1 - 4);
1080  if (lsize2 >= 11 && lsize2 + 8LL < FFMIN(i, RESYNC_BUFFER_SIZE)) {
1081  unsigned size2 = AV_RB24(flv->resync_buffer + j1 - lsize2 + 1 - 4);
1082  unsigned lsize1 = AV_RB32(flv->resync_buffer + j1 - lsize2 - 8);
1083  if (lsize1 >= 11 && lsize1 + 8LL + lsize2 < FFMIN(i, RESYNC_BUFFER_SIZE)) {
1084  unsigned size1 = AV_RB24(flv->resync_buffer + j1 - lsize1 + 1 - lsize2 - 8);
1085  if (size1 == lsize1 - 11 && size2 == lsize2 - 11) {
1086  avio_seek(s->pb, pos + i - lsize1 - lsize2 - 8, SEEK_SET);
1087  return 1;
1088  }
1089  }
1090  }
1091  }
1092  }
1093  return AVERROR_EOF;
1094 }
1095 
1097 {
1098  FLVContext *flv = s->priv_data;
1099  AMFDataType type;
1100  AVIOContext *ioc;
1101  char buffer[32];
1102  ioc = s->pb;
1103 
1104  // first object needs to be "colorInfo" string
1105  type = avio_r8(ioc);
1106  if (type != AMF_DATA_TYPE_STRING ||
1107  amf_get_string(ioc, buffer, sizeof(buffer)) < 0)
1108  return TYPE_UNKNOWN;
1109 
1110  if (strcmp(buffer, "colorInfo")) {
1111  av_log(s, AV_LOG_DEBUG, "Unknown type %s\n", buffer);
1112  return TYPE_UNKNOWN;
1113  }
1114 
1115  av_free(flv->metaVideoColor);
1116  if (!(flv->metaVideoColor = av_mallocz(sizeof(FLVMetaVideoColor)))) {
1117  return AVERROR(ENOMEM);
1118  }
1119  flv->meta_color_info_flag = 1;
1120  amf_parse_object(s, NULL, NULL, buffer, next_pos, 0); // parse metadata
1121  return 0;
1122 }
1123 
1125 {
1126  FLVContext *flv = s->priv_data;
1127  const FLVMetaVideoColor* meta_video_color = flv->metaVideoColor;
1128  const FLVMasteringMeta *mastering_meta = &meta_video_color->mastering_meta;
1129 
1130  int has_mastering_primaries, has_mastering_luminance;
1131  // Mastering primaries are CIE 1931 coords, and must be > 0.
1132  has_mastering_primaries =
1133  mastering_meta->r_x > 0 && mastering_meta->r_y > 0 &&
1134  mastering_meta->g_x > 0 && mastering_meta->g_y > 0 &&
1135  mastering_meta->b_x > 0 && mastering_meta->b_y > 0 &&
1136  mastering_meta->white_x > 0 && mastering_meta->white_y > 0;
1137  has_mastering_luminance = mastering_meta->max_luminance > 0 && mastering_meta->min_luminance > 0;
1138 
1139  if (meta_video_color->matrix_coefficients != AVCOL_SPC_RESERVED)
1140  st->codecpar->color_space = meta_video_color->matrix_coefficients;
1141  if (meta_video_color->primaries != AVCOL_PRI_RESERVED &&
1142  meta_video_color->primaries != AVCOL_PRI_RESERVED0)
1143  st->codecpar->color_primaries = meta_video_color->primaries;
1144  if (meta_video_color->transfer_characteristics != AVCOL_TRC_RESERVED &&
1145  meta_video_color->transfer_characteristics != AVCOL_TRC_RESERVED0)
1146  st->codecpar->color_trc = meta_video_color->transfer_characteristics;
1147 
1148  if (meta_video_color->max_cll && meta_video_color->max_fall) {
1149  size_t size = 0;
1151  if (!metadata)
1152  return AVERROR(ENOMEM);
1154  AV_PKT_DATA_CONTENT_LIGHT_LEVEL, metadata, size, 0)) {
1155  av_freep(&metadata);
1156  return AVERROR(ENOMEM);
1157  }
1158  metadata->MaxCLL = meta_video_color->max_cll;
1159  metadata->MaxFALL = meta_video_color->max_fall;
1160  }
1161 
1162  if (has_mastering_primaries || has_mastering_luminance) {
1163  AVMasteringDisplayMetadata *metadata;
1167  sizeof(AVMasteringDisplayMetadata), 0);
1168  if (!sd)
1169  return AVERROR(ENOMEM);
1170  metadata = (AVMasteringDisplayMetadata*)sd->data;
1171  memset(metadata, 0, sizeof(AVMasteringDisplayMetadata));
1172  // hdrCll
1173  if (has_mastering_luminance) {
1174  metadata->max_luminance = av_d2q(mastering_meta->max_luminance, INT_MAX);
1175  metadata->min_luminance = av_d2q(mastering_meta->min_luminance, INT_MAX);
1176  metadata->has_luminance = 1;
1177  }
1178  // hdrMdcv
1179  if (has_mastering_primaries) {
1180  metadata->display_primaries[0][0] = av_d2q(mastering_meta->r_x, INT_MAX);
1181  metadata->display_primaries[0][1] = av_d2q(mastering_meta->r_y, INT_MAX);
1182  metadata->display_primaries[1][0] = av_d2q(mastering_meta->g_x, INT_MAX);
1183  metadata->display_primaries[1][1] = av_d2q(mastering_meta->g_y, INT_MAX);
1184  metadata->display_primaries[2][0] = av_d2q(mastering_meta->b_x, INT_MAX);
1185  metadata->display_primaries[2][1] = av_d2q(mastering_meta->b_y, INT_MAX);
1186  metadata->white_point[0] = av_d2q(mastering_meta->white_x, INT_MAX);
1187  metadata->white_point[1] = av_d2q(mastering_meta->white_y, INT_MAX);
1188  metadata->has_primaries = 1;
1189  }
1190  }
1191  return 0;
1192 }
1193 
1195 {
1196  FLVContext *flv = s->priv_data;
1197  int ret, i, size, flags;
1198  enum FlvTagType type;
1199  int stream_type=-1;
1200  int64_t next, pos, meta_pos;
1201  int64_t dts, pts = AV_NOPTS_VALUE;
1202  int av_uninit(channels);
1203  int av_uninit(sample_rate);
1204  AVStream *st = NULL;
1205  int last = -1;
1206  int orig_size;
1207  int enhanced_flv = 0;
1208  uint32_t video_codec_id = 0;
1209 
1210 retry:
1211  /* pkt size is repeated at end. skip it */
1212  pos = avio_tell(s->pb);
1213  type = (avio_r8(s->pb) & 0x1F);
1214  orig_size =
1215  size = avio_rb24(s->pb);
1216  flv->sum_flv_tag_size += size + 11LL;
1217  dts = avio_rb24(s->pb);
1218  dts |= (unsigned)avio_r8(s->pb) << 24;
1219  av_log(s, AV_LOG_TRACE, "type:%d, size:%d, last:%d, dts:%"PRId64" pos:%"PRId64"\n", type, size, last, dts, avio_tell(s->pb));
1220  if (avio_feof(s->pb))
1221  return AVERROR_EOF;
1222  avio_skip(s->pb, 3); /* stream id, always 0 */
1223  flags = 0;
1224 
1225  if (flv->validate_next < flv->validate_count) {
1226  int64_t validate_pos = flv->validate_index[flv->validate_next].pos;
1227  if (pos == validate_pos) {
1228  if (FFABS(dts - flv->validate_index[flv->validate_next].dts) <=
1230  flv->validate_next++;
1231  } else {
1232  clear_index_entries(s, validate_pos);
1233  flv->validate_count = 0;
1234  }
1235  } else if (pos > validate_pos) {
1236  clear_index_entries(s, validate_pos);
1237  flv->validate_count = 0;
1238  }
1239  }
1240 
1241  if (size == 0) {
1242  ret = FFERROR_REDO;
1243  goto leave;
1244  }
1245 
1246  next = size + avio_tell(s->pb);
1247 
1248  if (type == FLV_TAG_TYPE_AUDIO) {
1249  stream_type = FLV_STREAM_TYPE_AUDIO;
1250  flags = avio_r8(s->pb);
1251  size--;
1252  } else if (type == FLV_TAG_TYPE_VIDEO) {
1253  stream_type = FLV_STREAM_TYPE_VIDEO;
1254  flags = avio_r8(s->pb);
1255  video_codec_id = flags & FLV_VIDEO_CODECID_MASK;
1256  /*
1257  * Reference Enhancing FLV 2023-03-v1.0.0-B.8
1258  * https://github.com/veovera/enhanced-rtmp/blob/main/enhanced-rtmp-v1.pdf
1259  * */
1260  enhanced_flv = (flags >> 7) & 1;
1261  size--;
1262  if (enhanced_flv) {
1263  video_codec_id = avio_rb32(s->pb);
1264  size -= 4;
1265  }
1266 
1267  if (enhanced_flv && stream_type == FLV_STREAM_TYPE_VIDEO && (flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_VIDEO_INFO_CMD) {
1268  int pkt_type = flags & 0x0F;
1269  if (pkt_type == PacketTypeMetadata) {
1270  int ret = flv_parse_video_color_info(s, st, next);
1271  av_log(s, AV_LOG_DEBUG, "enhanced flv parse metadata ret %d and skip\n", ret);
1272  }
1273  goto skip;
1275  goto skip;
1276  }
1277  } else if (type == FLV_TAG_TYPE_META) {
1278  stream_type=FLV_STREAM_TYPE_SUBTITLE;
1279  if (size > 13 + 1 + 4) { // Header-type metadata stuff
1280  int type;
1281  meta_pos = avio_tell(s->pb);
1282  type = flv_read_metabody(s, next);
1283  if (type == 0 && dts == 0 || type < 0) {
1284  if (type < 0 && flv->validate_count &&
1285  flv->validate_index[0].pos > next &&
1286  flv->validate_index[0].pos - 4 < next) {
1287  av_log(s, AV_LOG_WARNING, "Adjusting next position due to index mismatch\n");
1288  next = flv->validate_index[0].pos - 4;
1289  }
1290  goto skip;
1291  } else if (type == TYPE_ONTEXTDATA) {
1292  avpriv_request_sample(s, "OnTextData packet");
1293  return flv_data_packet(s, pkt, dts, next);
1294  } else if (type == TYPE_ONCAPTION) {
1295  return flv_data_packet(s, pkt, dts, next);
1296  } else if (type == TYPE_UNKNOWN) {
1297  stream_type = FLV_STREAM_TYPE_DATA;
1298  }
1299  avio_seek(s->pb, meta_pos, SEEK_SET);
1300  }
1301  } else {
1303  "Skipping flv packet: type %d, size %d, flags %d.\n",
1304  type, size, flags);
1305 skip:
1306  if (avio_seek(s->pb, next, SEEK_SET) != next) {
1307  // This can happen if flv_read_metabody above read past
1308  // next, on a non-seekable input, and the preceding data has
1309  // been flushed out from the IO buffer.
1310  av_log(s, AV_LOG_ERROR, "Unable to seek to the next packet\n");
1311  return AVERROR_INVALIDDATA;
1312  }
1313  ret = FFERROR_REDO;
1314  goto leave;
1315  }
1316 
1317  /* skip empty data packets */
1318  if (!size) {
1319  ret = FFERROR_REDO;
1320  goto leave;
1321  }
1322 
1323  /* now find stream */
1324  for (i = 0; i < s->nb_streams; i++) {
1325  st = s->streams[i];
1326  if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1327  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
1328  (s->audio_codec_id || flv_same_audio_codec(st->codecpar, flags)))
1329  break;
1330  } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1331  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
1332  (s->video_codec_id || flv_same_video_codec(st->codecpar, video_codec_id)))
1333  break;
1334  } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1336  break;
1337  } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1339  break;
1340  }
1341  }
1342  if (i == s->nb_streams) {
1344  st = create_stream(s, stream_types[stream_type]);
1345  if (!st)
1346  return AVERROR(ENOMEM);
1347  }
1348  av_log(s, AV_LOG_TRACE, "%d %X %d \n", stream_type, flags, st->discard);
1349 
1350  if (flv->time_pos <= pos) {
1351  dts += flv->time_offset;
1352  }
1353 
1354  if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1356  stream_type == FLV_STREAM_TYPE_AUDIO))
1358 
1359  if ((st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || stream_type == FLV_STREAM_TYPE_AUDIO)) ||
1361  st->discard >= AVDISCARD_ALL) {
1362  avio_seek(s->pb, next, SEEK_SET);
1363  ret = FFERROR_REDO;
1364  goto leave;
1365  }
1366 
1367  // if not streamed and no duration from metadata then seek to end to find
1368  // the duration from the timestamps
1369  if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1370  (!s->duration || s->duration == AV_NOPTS_VALUE) &&
1371  !flv->searched_for_end) {
1372  int size;
1373  const int64_t pos = avio_tell(s->pb);
1374  // Read the last 4 bytes of the file, this should be the size of the
1375  // previous FLV tag. Use the timestamp of its payload as duration.
1376  int64_t fsize = avio_size(s->pb);
1377 retry_duration:
1378  avio_seek(s->pb, fsize - 4, SEEK_SET);
1379  size = avio_rb32(s->pb);
1380  if (size > 0 && size < fsize) {
1381  // Seek to the start of the last FLV tag at position (fsize - 4 - size)
1382  // but skip the byte indicating the type.
1383  avio_seek(s->pb, fsize - 3 - size, SEEK_SET);
1384  if (size == avio_rb24(s->pb) + 11) {
1385  uint32_t ts = avio_rb24(s->pb);
1386  ts |= (unsigned)avio_r8(s->pb) << 24;
1387  if (ts)
1388  s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
1389  else if (fsize >= 8 && fsize - 8 >= size) {
1390  fsize -= size+4;
1391  goto retry_duration;
1392  }
1393  }
1394  }
1395 
1396  avio_seek(s->pb, pos, SEEK_SET);
1397  flv->searched_for_end = 1;
1398  }
1399 
1400  if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1401  int bits_per_coded_sample;
1403  sample_rate = 44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >>
1405  bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
1407  !st->codecpar->sample_rate ||
1410  st->codecpar->sample_rate = sample_rate;
1411  st->codecpar->bits_per_coded_sample = bits_per_coded_sample;
1412  }
1413  if (!st->codecpar->codec_id) {
1414  flv_set_audio_codec(s, st, st->codecpar,
1416  flv->last_sample_rate =
1417  sample_rate = st->codecpar->sample_rate;
1418  flv->last_channels =
1420  } else {
1422  if (!par) {
1423  ret = AVERROR(ENOMEM);
1424  goto leave;
1425  }
1426  par->sample_rate = sample_rate;
1427  par->bits_per_coded_sample = bits_per_coded_sample;
1429  sample_rate = par->sample_rate;
1431  }
1432  } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1433  int ret = flv_set_video_codec(s, st, video_codec_id, 1);
1434  if (ret < 0)
1435  return ret;
1436  size -= ret;
1437  } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1439  } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1440  st->codecpar->codec_id = AV_CODEC_ID_NONE; // Opaque AMF data
1441  }
1442 
1443  if (st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1447  st->codecpar->codec_id == AV_CODEC_ID_AV1 ||
1448  st->codecpar->codec_id == AV_CODEC_ID_VP9) {
1449  int type = 0;
1450  if (enhanced_flv && stream_type == FLV_STREAM_TYPE_VIDEO) {
1451  type = flags & 0x0F;
1452  } else {
1453  type = avio_r8(s->pb);
1454  size--;
1455  }
1456 
1457  if (size < 0) {
1459  goto leave;
1460  }
1461 
1462  if (enhanced_flv && stream_type == FLV_STREAM_TYPE_VIDEO && flv->meta_color_info_flag) {
1463  flv_update_video_color_info(s, st); // update av packet side data
1464  flv->meta_color_info_flag = 0;
1465  }
1466 
1469  // sign extension
1470  int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000;
1471  pts = av_sat_add64(dts, cts);
1472  if (cts < 0) { // dts might be wrong
1473  if (!flv->wrong_dts)
1475  "Negative cts, previous timestamps might be wrong.\n");
1476  flv->wrong_dts = 1;
1477  } else if (FFABS(dts - pts) > 1000*60*15) {
1479  "invalid timestamps %"PRId64" %"PRId64"\n", dts, pts);
1480  dts = pts = AV_NOPTS_VALUE;
1481  }
1482  size -= 3;
1483  }
1484  if (type == 0 && (!st->codecpar->extradata || st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1487  AVDictionaryEntry *t;
1488 
1489  if (st->codecpar->extradata) {
1490  if ((ret = flv_queue_extradata(flv, s->pb, stream_type, size)) < 0)
1491  return ret;
1492  ret = FFERROR_REDO;
1493  goto leave;
1494  }
1495  if ((ret = flv_get_extradata(s, st, size)) < 0)
1496  return ret;
1497 
1498  /* Workaround for buggy Omnia A/XE encoder */
1499  t = av_dict_get(s->metadata, "Encoder", NULL, 0);
1500  if (st->codecpar->codec_id == AV_CODEC_ID_AAC && t && !strcmp(t->value, "Omnia A/XE"))
1501  st->codecpar->extradata_size = 2;
1502 
1503  ret = FFERROR_REDO;
1504  goto leave;
1505  }
1506  }
1507 
1508  /* skip empty data packets */
1509  if (!size) {
1510  ret = FFERROR_REDO;
1511  goto leave;
1512  }
1513 
1514  ret = av_get_packet(s->pb, pkt, size);
1515  if (ret < 0)
1516  return ret;
1517  pkt->dts = dts;
1518  pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts;
1519  pkt->stream_index = st->index;
1520  pkt->pos = pos;
1521  if (flv->new_extradata[stream_type]) {
1523  flv->new_extradata[stream_type],
1524  flv->new_extradata_size[stream_type]);
1525  if (ret >= 0) {
1526  flv->new_extradata[stream_type] = NULL;
1527  flv->new_extradata_size[stream_type] = 0;
1528  }
1529  }
1530  if (stream_type == FLV_STREAM_TYPE_AUDIO &&
1531  (sample_rate != flv->last_sample_rate ||
1532  channels != flv->last_channels)) {
1533  flv->last_sample_rate = sample_rate;
1534  flv->last_channels = channels;
1535  ff_add_param_change(pkt, channels, 0, sample_rate, 0, 0);
1536  }
1537 
1538  if (stream_type == FLV_STREAM_TYPE_AUDIO ||
1540  stream_type == FLV_STREAM_TYPE_SUBTITLE ||
1541  stream_type == FLV_STREAM_TYPE_DATA)
1543 
1544 leave:
1545  last = avio_rb32(s->pb);
1546  if (!flv->trust_datasize) {
1547  if (last != orig_size + 11 && last != orig_size + 10 &&
1548  !avio_feof(s->pb) &&
1549  (last != orig_size || !last) && last != flv->sum_flv_tag_size &&
1550  !flv->broken_sizes) {
1551  av_log(s, AV_LOG_ERROR, "Packet mismatch %d %d %"PRId64"\n", last, orig_size + 11, flv->sum_flv_tag_size);
1552  avio_seek(s->pb, pos + 1, SEEK_SET);
1553  ret = resync(s);
1555  if (ret >= 0) {
1556  goto retry;
1557  }
1558  }
1559  }
1560 
1561  if (ret >= 0)
1562  flv->last_ts = pkt->dts;
1563 
1564  return ret;
1565 }
1566 
1567 static int flv_read_seek(AVFormatContext *s, int stream_index,
1568  int64_t ts, int flags)
1569 {
1570  FLVContext *flv = s->priv_data;
1571  flv->validate_count = 0;
1572  return avio_seek_time(s->pb, stream_index, ts, flags);
1573 }
1574 
1575 #define OFFSET(x) offsetof(FLVContext, x)
1576 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1577 static const AVOption options[] = {
1578  { "flv_metadata", "Allocate streams according to the onMetaData array", OFFSET(trust_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1579  { "flv_full_metadata", "Dump full metadata of the onMetadata", OFFSET(dump_full_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1580  { "flv_ignore_prevtag", "Ignore the Size of previous tag", OFFSET(trust_datasize), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1581  { NULL }
1582 };
1583 
1584 static const AVClass flv_kux_class = {
1585  .class_name = "(live) flv/kux demuxer",
1586  .item_name = av_default_item_name,
1587  .option = options,
1588  .version = LIBAVUTIL_VERSION_INT,
1589 };
1590 
1592  .p.name = "flv",
1593  .p.long_name = NULL_IF_CONFIG_SMALL("FLV (Flash Video)"),
1594  .p.extensions = "flv",
1595  .p.priv_class = &flv_kux_class,
1596  .priv_data_size = sizeof(FLVContext),
1597  .read_probe = flv_probe,
1602 };
1603 
1605  .p.name = "live_flv",
1606  .p.long_name = NULL_IF_CONFIG_SMALL("live RTMP FLV (Flash Video)"),
1607  .p.extensions = "flv",
1608  .p.priv_class = &flv_kux_class,
1609  .p.flags = AVFMT_TS_DISCONT,
1610  .priv_data_size = sizeof(FLVContext),
1616 };
1617 
1619  .p.name = "kux",
1620  .p.long_name = NULL_IF_CONFIG_SMALL("KUX (YouKu)"),
1621  .p.extensions = "kux",
1622  .p.priv_class = &flv_kux_class,
1623  .priv_data_size = sizeof(FLVContext),
1624  .read_probe = kux_probe,
1629 };
AVCOL_PRI_RESERVED
@ AVCOL_PRI_RESERVED
Definition: pixfmt.h:590
FLV_CODECID_PCM_ALAW
@ FLV_CODECID_PCM_ALAW
Definition: flv.h:104
AV_CODEC_ID_PCM_S16LE
@ AV_CODEC_ID_PCM_S16LE
Definition: codec_id.h:334
AVMasteringDisplayMetadata::has_primaries
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
Definition: mastering_display_metadata.h:62
FLVContext::audio_bit_rate
int64_t audio_bit_rate
Definition: flvdec.c:97
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:429
AMF_DATA_TYPE_OBJECT_END
@ AMF_DATA_TYPE_OBJECT_END
Definition: flv.h:147
AMF_END_OF_OBJECT
#define AMF_END_OF_OBJECT
Definition: flv.h:53
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_CODEC_ID_VP6F
@ AV_CODEC_ID_VP6F
Definition: codec_id.h:144
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
FLV_CODECID_SPEEX
@ FLV_CODECID_SPEEX
Definition: flv.h:107
AVMasteringDisplayMetadata::max_luminance
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:57
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:69
FLV_TAG_TYPE_VIDEO
@ FLV_TAG_TYPE_VIDEO
Definition: flv.h:67
FLVMasteringMeta::g_y
double g_y
Definition: flvdec.c:53
FLVContext::pos
int64_t pos
Definition: flvdec.c:83
FLVMasteringMeta::r_x
double r_x
Definition: flvdec.c:50
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
FLVMetaVideoColor::max_cll
uint64_t max_cll
Definition: flvdec.c:66
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
PacketTypeCodedFrames
@ PacketTypeCodedFrames
Definition: flv.h:123
clear_index_entries
static void clear_index_entries(AVFormatContext *s, int64_t pos)
Definition: flvdec.c:923
FLVContext::validate_next
int validate_next
Definition: flvdec.c:85
out
FILE * out
Definition: movenc.c:55
FLV_CODECID_SCREEN
@ FLV_CODECID_SCREEN
Definition: flv.h:112
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
AVFMT_FLAG_IGNIDX
#define AVFMT_FLAG_IGNIDX
Ignore index.
Definition: avformat.h:1453
ffformatcontext
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition: internal.h:127
AVCodecParameters::color_space
enum AVColorSpace color_space
Definition: codec_par.h:169
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
AV_PKT_DATA_NEW_EXTRADATA
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition: packet.h:56
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:819
FLV_FRAME_KEY
@ FLV_FRAME_KEY
key frame (for AVC, a seekable frame)
Definition: flv.h:131
AV_PKT_DATA_MASTERING_DISPLAY_METADATA
@ AV_PKT_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata (based on SMPTE-2086:2014).
Definition: packet.h:219
av_int2double
static av_always_inline double av_int2double(uint64_t i)
Reinterpret a 64-bit integer as a double.
Definition: intfloat.h:60
AVMasteringDisplayMetadata::display_primaries
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
Definition: mastering_display_metadata.h:42
AVMasteringDisplayMetadata::has_luminance
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
Definition: mastering_display_metadata.h:67
TYPE_ONCAPTIONINFO
#define TYPE_ONCAPTIONINFO
Definition: flvdec.c:784
flv_data_packet
static int flv_data_packet(AVFormatContext *s, AVPacket *pkt, int64_t dts, int64_t next)
Definition: flvdec.c:987
int64_t
long long int64_t
Definition: coverity.c:34
dict_internal.h
av_unused
#define av_unused
Definition: attributes.h:131
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:111
FLVContext::time_offset
int64_t time_offset
Definition: flvdec.c:102
FLVContext::trust_metadata
int trust_metadata
configure streams according onMetaData
Definition: flvdec.c:73
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:390
flv_read_packet
static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: flvdec.c:1194
TYPE_ONCAPTION
#define TYPE_ONCAPTION
Definition: flvdec.c:783
AVOption
AVOption.
Definition: opt.h:429
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:837
FLVContext::resync_buffer
uint8_t resync_buffer[2 *RESYNC_BUFFER_SIZE]
Definition: flvdec.c:89
FLV_STREAM_TYPE_SUBTITLE
@ FLV_STREAM_TYPE_SUBTITLE
Definition: flv.h:74
amf_date
Definition: flvdec.c:110
PacketTypeMetadata
@ PacketTypeMetadata
Definition: flv.h:126
AMF_DATA_TYPE_UNDEFINED
@ AMF_DATA_TYPE_UNDEFINED
Definition: flv.h:144
AMF_DATA_TYPE_DATE
@ AMF_DATA_TYPE_DATE
Definition: flv.h:149
flv_set_audio_codec
static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, AVCodecParameters *apar, int flv_codecid)
Definition: flvdec.c:271
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:59
AVProbeData::buf_size
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:454
FLVMasteringMeta::b_y
double b_y
Definition: flvdec.c:55
FLVContext::trust_datasize
int trust_datasize
trust data size of FLVTag
Definition: flvdec.c:74
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:327
intfloat.h
codec_type
enum AVMediaType codec_type
Definition: rtp.c:37
AMF_DATA_TYPE_OBJECT
@ AMF_DATA_TYPE_OBJECT
Definition: flv.h:142
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:323
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:594
ff_live_flv_demuxer
const FFInputFormat ff_live_flv_demuxer
Definition: flvdec.c:1604
FLV_CODECID_PCM_LE
@ FLV_CODECID_PCM_LE
Definition: flv.h:100
options
static const AVOption options[]
Definition: flvdec.c:1577
AVINDEX_KEYFRAME
#define AVINDEX_KEYFRAME
Definition: avformat.h:610
FLVMasteringMeta
Definition: flvdec.c:49
ff_get_extradata
int ff_get_extradata(void *logctx, 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: demux_utils.c:338
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:107
AVCodecParameters::color_primaries
enum AVColorPrimaries color_primaries
Definition: codec_par.h:167
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:463
FLVMetaVideoColor::primaries
uint64_t primaries
Definition: flvdec.c:65
FLVContext::video_bit_rate
int64_t video_bit_rate
Definition: flvdec.c:96
FLVContext::searched_for_end
int searched_for_end
Definition: flvdec.c:87
AVCOL_SPC_RESERVED
@ AVCOL_SPC_RESERVED
reserved for future use by ITU-T and ISO/IEC just like 15-255 are
Definition: pixfmt.h:644
FLVContext::keyframe_times
int64_t * keyframe_times
Definition: flvdec.c:98
FLVContext::keyframe_filepositions
int64_t * keyframe_filepositions
Definition: flvdec.c:99
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: avformat.c:867
finish
static void finish(void)
Definition: movenc.c:374
OFFSET
#define OFFSET(x)
Definition: flvdec.c:1575
av_packet_add_side_data
int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as a packet side data.
Definition: packet.c:197
AV_CODEC_ID_SPEEX
@ AV_CODEC_ID_SPEEX
Definition: codec_id.h:481
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:358
FLVContext::last_ts
int64_t last_ts
Definition: flvdec.c:101
AV_CODEC_ID_PCM_S16BE
@ AV_CODEC_ID_PCM_S16BE
Definition: codec_id.h:335
avio_seek_time
int64_t avio_seek_time(AVIOContext *h, int stream_index, int64_t timestamp, int flags)
Seek to a given timestamp relative to some component stream.
Definition: aviobuf.c:1232
read_seek
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:151
av_add_index_entry
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
Definition: seek.c:122
TYPE_ONTEXTDATA
#define TYPE_ONTEXTDATA
Definition: flvdec.c:782
flv_read_seek
static int flv_read_seek(AVFormatContext *s, int stream_index, int64_t ts, int flags)
Definition: flvdec.c:1567
read_close
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:143
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:494
FLV_FRAME_VIDEO_INFO_CMD
@ FLV_FRAME_VIDEO_INFO_CMD
video info/command frame
Definition: flv.h:135
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
pts
static int64_t pts
Definition: transcode_aac.c:644
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:447
FLV_STREAM_TYPE_DATA
@ FLV_STREAM_TYPE_DATA
Definition: flv.h:75
FLV_AUDIO_CODECID_OFFSET
#define FLV_AUDIO_CODECID_OFFSET
Definition: flv.h:34
AVCodecParameters::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: codec_par.h:168
VD
#define VD
Definition: flvdec.c:1576
avassert.h
AMFDataType
AMFDataType
Definition: flv.h:138
parse_keyframes_index
static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, int64_t max_pos)
Definition: flvdec.c:449
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:761
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:235
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
FLV_STEREO
@ FLV_STEREO
Definition: flv.h:81
VALIDATE_INDEX_TS_THRESH
#define VALIDATE_INDEX_TS_THRESH
Definition: flvdec.c:43
AVCOL_PRI_RESERVED0
@ AVCOL_PRI_RESERVED0
Definition: pixfmt.h:587
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_read_callback.c:42
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:62
FLVContext::new_extradata_size
int new_extradata_size[FLV_STREAM_TYPE_NB]
Definition: flvdec.c:78
AVMasteringDisplayMetadata::white_point
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
Definition: mastering_display_metadata.h:47
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
AMF_DATA_TYPE_UNSUPPORTED
@ AMF_DATA_TYPE_UNSUPPORTED
Definition: flv.h:151
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:553
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:453
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:222
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:134
create_stream
static AVStream * create_stream(AVFormatContext *s, int codec_type)
Definition: flvdec.c:189
FLVContext::dts
int64_t dts
Definition: flvdec.c:82
amf_skip_tag
static int amf_skip_tag(AVIOContext *pb, AMFDataType type, int depth)
Definition: flvdec.c:938
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
FLV_AUDIO_CHANNEL_MASK
#define FLV_AUDIO_CHANNEL_MASK
Definition: flv.h:45
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
AVPacketSideData::data
uint8_t * data
Definition: packet.h:391
channels
channels
Definition: aptx.h:31
FLVContext::time_pos
int64_t time_pos
Definition: flvdec.c:103
isfinite
#define isfinite(x)
Definition: libm.h:359
AV_CODEC_ID_PCM_MULAW
@ AV_CODEC_ID_PCM_MULAW
Definition: codec_id.h:340
FLVMasteringMeta::g_x
double g_x
Definition: flvdec.c:52
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
live_flv_probe
static int live_flv_probe(const AVProbeData *p)
Definition: flvdec.c:139
KEYFRAMES_TIMESTAMP_TAG
#define KEYFRAMES_TIMESTAMP_TAG
Definition: flv.h:56
key
const char * key
Definition: hwcontext_opencl.c:189
AVCodecParameters::nb_coded_side_data
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition: codec_par.h:86
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
FLVContext::sum_flv_tag_size
int64_t sum_flv_tag_size
Definition: flvdec.c:92
FLV_VIDEO_FRAMETYPE_MASK
#define FLV_VIDEO_FRAMETYPE_MASK
Definition: flv.h:51
fsize
static int64_t fsize(FILE *f)
Definition: audiomatch.c:29
AVDISCARD_BIDIR
@ AVDISCARD_BIDIR
discard all bidirectional frames
Definition: defs.h:218
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
av_content_light_metadata_alloc
AVContentLightMetadata * av_content_light_metadata_alloc(size_t *size)
Allocate an AVContentLightMetadata structure and set its fields to default values.
Definition: mastering_display_metadata.c:72
TYPE_UNKNOWN
#define TYPE_UNKNOWN
Definition: flvdec.c:785
FLV_CODECID_AAC
@ FLV_CODECID_AAC
Definition: flv.h:106
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
FFFormatContext
Definition: internal.h:64
FFStream::need_parsing
enum AVStreamParseType need_parsing
Definition: internal.h:325
FLVMasteringMeta::r_y
double r_y
Definition: flvdec.c:51
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:221
AVFormatContext
Format I/O context.
Definition: avformat.h:1300
AV_CODEC_ID_PCM_ALAW
@ AV_CODEC_ID_PCM_ALAW
Definition: codec_id.h:341
flv_read_close
static int flv_read_close(AVFormatContext *s)
Definition: flvdec.c:883
AV_CODEC_ID_FLASHSV2
@ AV_CODEC_ID_FLASHSV2
Definition: codec_id.h:183
internal.h
FLVMasteringMeta::white_y
double white_y
Definition: flvdec.c:57
AVCOL_TRC_RESERVED0
@ AVCOL_TRC_RESERVED0
Definition: pixfmt.h:612
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:771
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:540
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
add_keyframes_index
static void add_keyframes_index(AVFormatContext *s)
Definition: flvdec.c:158
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:284
avcodec_parameters_free
void avcodec_parameters_free(AVCodecParameters **ppar)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
Definition: codec_par.c:66
AVFMTCTX_NOHEADER
#define AVFMTCTX_NOHEADER
signal that no header is present (streams are added dynamically)
Definition: avformat.h:1251
AMF_DATA_TYPE_BOOL
@ AMF_DATA_TYPE_BOOL
Definition: flv.h:140
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
flv_read_header
static int flv_read_header(AVFormatContext *s)
Definition: flvdec.c:844
FLV_CODECID_VP6
@ FLV_CODECID_VP6
Definition: flv.h:113
isnan
#define isnan(x)
Definition: libm.h:340
flv_same_audio_codec
static int flv_same_audio_codec(AVCodecParameters *apar, int flags)
Definition: flvdec.c:220
FLVContext::meta_color_info_flag
int meta_color_info_flag
Definition: flvdec.c:106
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
avio_rb64
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:908
FFStream::nb_index_entries
int nb_index_entries
Definition: internal.h:190
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:451
options
Definition: swscale.c:42
flv.h
FLVContext::last_channels
int last_channels
Definition: flvdec.c:80
AMF_DATA_TYPE_ARRAY
@ AMF_DATA_TYPE_ARRAY
Definition: flv.h:148
AV_CODEC_ID_FLASHSV
@ AV_CODEC_ID_FLASHSV
Definition: codec_id.h:138
flv_parse_video_color_info
static int flv_parse_video_color_info(AVFormatContext *s, AVStream *st, int64_t next_pos)
Definition: flvdec.c:1096
FLVContext::keyframe_count
int keyframe_count
Definition: flvdec.c:95
FLV_FRAME_DISP_INTER
@ FLV_FRAME_DISP_INTER
disposable inter frame (H.263 only)
Definition: flv.h:133
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:180
AV_CODEC_ID_VP6A
@ AV_CODEC_ID_VP6A
Definition: codec_id.h:158
AV_PKT_DATA_CONTENT_LIGHT_LEVEL
@ AV_PKT_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: packet.h:232
AVPROBE_SCORE_EXTENSION
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition: avformat.h:461
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:184
FLVContext::metaVideoColor
FLVMetaVideoColor * metaVideoColor
Definition: flvdec.c:105
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
FLVMasteringMeta::white_x
double white_x
Definition: flvdec.c:56
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:73
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:448
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: defs.h:220
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
avio_rb24
unsigned int avio_rb24(AVIOContext *s)
Definition: aviobuf.c:754
AVMediaType
AVMediaType
Definition: avutil.h:199
AVPacket::size
int size
Definition: packet.h:540
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
KEYFRAMES_BYTEOFFSET_TAG
#define KEYFRAMES_BYTEOFFSET_TAG
Definition: flv.h:57
FLV_CODECID_PCM
@ FLV_CODECID_PCM
Definition: flv.h:97
AVIOContext::seekable
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:261
FFStream
Definition: internal.h:132
FLV_STREAM_TYPE_VIDEO
@ FLV_STREAM_TYPE_VIDEO
Definition: flv.h:72
flv_update_video_color_info
static int flv_update_video_color_info(AVFormatContext *s, AVStream *st)
Definition: flvdec.c:1124
FLV_CODECID_MP3
@ FLV_CODECID_MP3
Definition: flv.h:99
FLVMetaVideoColor::mastering_meta
FLVMasteringMeta mastering_meta
Definition: flvdec.c:68
AV_CODEC_ID_H263
@ AV_CODEC_ID_H263
Definition: codec_id.h:56
AV_CODEC_ID_ADPCM_SWF
@ AV_CODEC_ID_ADPCM_SWF
Definition: codec_id.h:386
size
int size
Definition: twinvq_data.h:10344
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: demux_utils.c:154
FLVMetaVideoColor
Definition: flvdec.c:62
FLVContext
Definition: flvdec.c:71
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
MKBETAG
#define MKBETAG(a, b, c, d)
Definition: macros.h:56
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
ff_flv_demuxer
const FFInputFormat ff_flv_demuxer
Definition: flvdec.c:1591
FLV_TAG_TYPE_AUDIO
@ FLV_TAG_TYPE_AUDIO
Definition: flv.h:66
MAX_DEPTH
#define MAX_DEPTH
arbitrary limit to prevent unbounded recursion
Definition: flvdec.c:47
amf_date::timezone
int16_t timezone
Definition: flvdec.c:112
FLV_CODECID_VP6A
@ FLV_CODECID_VP6A
Definition: flv.h:114
KEYFRAMES_TAG
#define KEYFRAMES_TAG
Definition: flv.h:55
FLVMetaVideoColor::transfer_characteristics
uint64_t transfer_characteristics
Definition: flvdec.c:64
FFInputFormat::p
AVInputFormat p
The public AVInputFormat.
Definition: demux.h:46
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:538
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:603
FLV_CODECID_ADPCM
@ FLV_CODECID_ADPCM
Definition: flv.h:98
av_packet_side_data_add
AVPacketSideData * av_packet_side_data_add(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, void *data, size_t size, int flags)
Wrap existing data as packet side data.
Definition: packet.c:699
offset
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 offset
Definition: writing_filters.txt:86
FLV_HEADER_FLAG_HASVIDEO
@ FLV_HEADER_FLAG_HASVIDEO
Definition: flv.h:61
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:545
FLVContext::validate_index
struct FLVContext::@386 validate_index[2]
version
version
Definition: libkvazaar.c:321
FLVMetaVideoColor::max_fall
uint64_t max_fall
Definition: flvdec.c:67
FLVMasteringMeta::b_x
double b_x
Definition: flvdec.c:54
FFERROR_REDO
#define FFERROR_REDO
Returned by demuxers to indicate that data was consumed but discarded (ignored streams or junk data).
Definition: demux.h:176
FLVMetaVideoColor::matrix_coefficients
uint64_t matrix_coefficients
Definition: flvdec.c:63
kux_probe
static int kux_probe(const AVProbeData *p)
Definition: flvdec.c:144
av_channel_layout_default
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
Definition: channel_layout.c:837
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:56
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:532
FLV_CODECID_NELLYMOSER_8KHZ_MONO
@ FLV_CODECID_NELLYMOSER_8KHZ_MONO
Definition: flv.h:102
FLVContext::last_keyframe_stream_index
int last_keyframe_stream_index
Definition: flvdec.c:94
flv_read_metabody
static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
Definition: flvdec.c:787
internal.h
AVCodecParameters::height
int height
Definition: codec_par.h:135
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
resync
static int resync(AVFormatContext *s)
Definition: flvdec.c:1054
FLVContext::framerate
AVRational framerate
Definition: flvdec.c:100
flv_probe
static int flv_probe(const AVProbeData *p)
Definition: flvdec.c:134
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:228
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_d2q
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
Definition: rational.c:106
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
FLV_AUDIO_SAMPLERATE_OFFSET
#define FLV_AUDIO_SAMPLERATE_OFFSET
Definition: flv.h:33
demux.h
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
FLVContext::wrong_dts
int wrong_dts
wrong dts due to negative cts
Definition: flvdec.c:76
AVCodecParameters::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
Definition: codec_par.h:81
FLV_HEADER_FLAG_HASAUDIO
@ FLV_HEADER_FLAG_HASAUDIO
Definition: flv.h:62
flv_queue_extradata
static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream, int size)
Definition: flvdec.c:907
AMF_DATA_TYPE_MIXEDARRAY
@ AMF_DATA_TYPE_MIXEDARRAY
Definition: flv.h:146
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:91
AMF_DATA_TYPE_STRING
@ AMF_DATA_TYPE_STRING
Definition: flv.h:141
FLVContext::new_extradata
uint8_t * new_extradata[FLV_STREAM_TYPE_NB]
Definition: flvdec.c:77
FFFormatContext::missing_streams
int missing_streams
Definition: internal.h:124
av_uninit
#define av_uninit(x)
Definition: attributes.h:154
array
static int array[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:116
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:748
probe
static int probe(const AVProbeData *p, int live)
Definition: flvdec.c:115
flv_kux_class
static const AVClass flv_kux_class
Definition: flvdec.c:1584
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:231
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:80
avio_rb16
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:746
av_channel_layout_check
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
Definition: channel_layout.c:781
FLVMasteringMeta::min_luminance
double min_luminance
Definition: flvdec.c:59
AVSTREAM_PARSE_HEADERS
@ AVSTREAM_PARSE_HEADERS
Only parse headers, do not repack.
Definition: avformat.h:594
FLV_STREAM_TYPE_AUDIO
@ FLV_STREAM_TYPE_AUDIO
Definition: flv.h:73
pos
unsigned int pos
Definition: spdifenc.c:414
avformat.h
dict.h
av_packet_side_data_new
AVPacketSideData * av_packet_side_data_new(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, size_t size, int flags)
Allocate a new packet side data.
Definition: packet.c:706
AV_CODEC_ID_TEXT
@ AV_CODEC_ID_TEXT
raw UTF-8 text
Definition: codec_id.h:558
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
amf_get_string
static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize)
Definition: flvdec.c:429
av_sat_add64
#define av_sat_add64
Definition: common.h:139
FLVMasteringMeta::max_luminance
double max_luminance
Definition: flvdec.c:58
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:754
FLV_CODECID_PCM_MULAW
@ FLV_CODECID_PCM_MULAW
Definition: flv.h:105
channel_layout.h
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:41
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
FLV_TAG_TYPE_META
@ FLV_TAG_TYPE_META
Definition: flv.h:68
FLV_CODECID_SCREEN2
@ FLV_CODECID_SCREEN2
Definition: flv.h:115
flv_set_video_codec
static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, uint32_t flv_codecid, int read)
Definition: flvdec.c:360
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:612
amf_parse_object
static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vstream, const char *key, int64_t max_pos, int depth)
Definition: flvdec.c:544
AVIndexEntry::pos
int64_t pos
Definition: avformat.h:603
AVIOContext::eof_reached
int eof_reached
true if was unable to read due to error or eof
Definition: avio.h:238
flv_same_video_codec
static int flv_same_video_codec(AVCodecParameters *vpar, uint32_t flv_codecid)
Definition: flvdec.c:331
AVMasteringDisplayMetadata::min_luminance
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:52
AVPacket::stream_index
int stream_index
Definition: packet.h:541
FLV_CODECID_NELLYMOSER
@ FLV_CODECID_NELLYMOSER
Definition: flv.h:103
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:318
factor
static const int factor[16]
Definition: vf_pp7.c:80
FFStream::index_entries
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: internal.h:188
FLV_CODECID_H264
@ FLV_CODECID_H264
Definition: flv.h:116
ff_kux_demuxer
const FFInputFormat ff_kux_demuxer
Definition: flvdec.c:1618
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
read_probe
static int read_probe(const AVProbeData *p)
Definition: cdg.c:30
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: codec_par.h:110
AVFMT_TS_DISCONT
#define AVFMT_TS_DISCONT
Format allows timestamp discontinuities.
Definition: avformat.h:481
mem.h
AV_CODEC_ID_PCM_U8
@ AV_CODEC_ID_PCM_U8
Definition: codec_id.h:339
mastering_display_metadata.h
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
FLV_CODECID_H263
@ FLV_CODECID_H263
Definition: flv.h:111
AVCOL_TRC_RESERVED
@ AVCOL_TRC_RESERVED
Definition: pixfmt.h:615
FLV_STREAM_TYPE_NB
@ FLV_STREAM_TYPE_NB
Definition: flv.h:76
flv_get_extradata
static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size)
Definition: flvdec.c:895
AMF_DATA_TYPE_NUMBER
@ AMF_DATA_TYPE_NUMBER
Definition: flv.h:139
FLV_CODECID_MPEG4
@ FLV_CODECID_MPEG4
Definition: flv.h:118
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVDictionaryEntry
Definition: dict.h:89
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVContentLightMetadata::MaxFALL
unsigned MaxFALL
Max average light level per frame (cd/m^2).
Definition: mastering_display_metadata.h:116
AVPacket
This structure stores compressed data.
Definition: packet.h:516
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
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:88
FLV_AUDIO_CODECID_MASK
#define FLV_AUDIO_CODECID_MASK
Definition: flv.h:48
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:559
FFInputFormat
Definition: demux.h:42
FLV_AUDIO_SAMPLERATE_MASK
#define FLV_AUDIO_SAMPLERATE_MASK
Definition: flv.h:47
int32_t
int32_t
Definition: audioconvert.c:56
FLV_VIDEO_CODECID_MASK
#define FLV_VIDEO_CODECID_MASK
Definition: flv.h:50
AVSTREAM_PARSE_FULL
@ AVSTREAM_PARSE_FULL
full parsing and repack
Definition: avformat.h:593
FLV_CODECID_NELLYMOSER_16KHZ_MONO
@ FLV_CODECID_NELLYMOSER_16KHZ_MONO
Definition: flv.h:101
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:177
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
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:85
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:97
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
FLV_CODECID_REALH263
@ FLV_CODECID_REALH263
Definition: flv.h:117
FLVContext::validate_count
int validate_count
Definition: flvdec.c:86
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
FLV_AUDIO_SAMPLESIZE_MASK
#define FLV_AUDIO_SAMPLESIZE_MASK
Definition: flv.h:46
AVDictionaryEntry::value
char * value
Definition: dict.h:91
avstring.h
FlvTagType
FlvTagType
Definition: flv.h:65
AV_CODEC_ID_FLV1
@ AV_CODEC_ID_FLV1
Definition: codec_id.h:73
amf_date::milliseconds
double milliseconds
Definition: flvdec.c:111
AV_RB24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
Definition: bytestream.h:97
snprintf
#define snprintf
Definition: snprintf.h:34
FLVContext::dump_full_metadata
int dump_full_metadata
Dump full metadata of the onMetadata.
Definition: flvdec.c:75
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:278
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:375
FLVContext::last_sample_rate
int last_sample_rate
Definition: flvdec.c:79
max_pos
static const int32_t max_pos[4]
Size of the MP-MLQ fixed excitation codebooks.
Definition: g723_1dec.c:97
read
static uint32_t BS_FUNC() read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.
Definition: bitstream_template.h:231
AMF_DATA_TYPE_NULL
@ AMF_DATA_TYPE_NULL
Definition: flv.h:143
AVFMT_EVENT_FLAG_METADATA_UPDATED
#define AVFMT_EVENT_FLAG_METADATA_UPDATED
Definition: avformat.h:1677
RESYNC_BUFFER_SIZE
#define RESYNC_BUFFER_SIZE
Definition: flvdec.c:45
AV_CODEC_ID_NELLYMOSER
@ AV_CODEC_ID_NELLYMOSER
Definition: codec_id.h:479
FLVContext::broken_sizes
int broken_sizes
Definition: flvdec.c:91
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:227
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:346