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  float r_x;
51  float r_y;
52  float g_x;
53  float g_y;
54  float b_x;
55  float b_y;
56  float white_x;
57  float white_y;
61 
62 typedef struct FLVMetaVideoColor {
66  uint16_t max_cll;
67  uint16_t max_fall;
70 
75 };
76 
77 typedef struct FLVContext {
78  const AVClass *class; ///< Class for private options.
79  int trust_metadata; ///< configure streams according onMetaData
80  int trust_datasize; ///< trust data size of FLVTag
81  int dump_full_metadata; ///< Dump full metadata of the onMetadata
82  int wrong_dts; ///< wrong dts due to negative cts
87  struct {
90  } validate_index[2];
94 
96 
99 
110 
113 
114  uint8_t **mt_extradata;
117 } FLVContext;
118 
119 /* AMF date type */
120 typedef struct amf_date {
121  double milliseconds;
122  int16_t timezone;
123 } amf_date;
124 
125 static int probe(const AVProbeData *p, int live)
126 {
127  const uint8_t *d = p->buf;
128  unsigned offset = AV_RB32(d + 5);
129 
130  if (d[0] == 'F' &&
131  d[1] == 'L' &&
132  d[2] == 'V' &&
133  d[3] < 5 && d[5] == 0 &&
134  offset + 100 < p->buf_size &&
135  offset > 8) {
136  int is_live = !memcmp(d + offset + 40, "NGINX RTMP", 10);
137 
138  if (live == is_live)
139  return AVPROBE_SCORE_MAX;
140  }
141  return 0;
142 }
143 
144 static int flv_probe(const AVProbeData *p)
145 {
146  return probe(p, 0);
147 }
148 
149 static int live_flv_probe(const AVProbeData *p)
150 {
151  return probe(p, 1);
152 }
153 
154 static int kux_probe(const AVProbeData *p)
155 {
156  const uint8_t *d = p->buf;
157 
158  if (d[0] == 'K' &&
159  d[1] == 'D' &&
160  d[2] == 'K' &&
161  d[3] == 0 &&
162  d[4] == 0) {
163  return AVPROBE_SCORE_EXTENSION + 1;
164  }
165  return 0;
166 }
167 
169 {
170  FLVContext *flv = s->priv_data;
171  AVStream *stream = NULL;
172  unsigned int i = 0;
173 
174  if (flv->last_keyframe_stream_index < 0) {
175  av_log(s, AV_LOG_DEBUG, "keyframe stream hasn't been created\n");
176  return;
177  }
178 
179  av_assert0(flv->last_keyframe_stream_index <= s->nb_streams);
180  stream = s->streams[flv->last_keyframe_stream_index];
181 
182  if (ffstream(stream)->nb_index_entries == 0) {
183  for (i = 0; i < flv->keyframe_count; i++) {
184  av_log(s, AV_LOG_TRACE, "keyframe filepositions = %"PRId64" times = %"PRId64"\n",
187  flv->keyframe_times[i], 0, 0, AVINDEX_KEYFRAME);
188  }
189  } else
190  av_log(s, AV_LOG_WARNING, "Skipping duplicate index\n");
191 
192  if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
193  av_freep(&flv->keyframe_times);
195  flv->keyframe_count = 0;
196  }
197 }
198 
199 static AVStream *create_stream(AVFormatContext *s, int codec_type, int track_idx)
200 {
201  FFFormatContext *const si = ffformatcontext(s);
202  FLVContext *flv = s->priv_data;
204  if (!st)
205  return NULL;
207  st->id = track_idx;
208  avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
209  if (track_idx)
210  return st;
211 
212  if (s->nb_streams>=3 ||( s->nb_streams==2
213  && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE
214  && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE
215  && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_DATA
216  && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_DATA))
217  s->ctx_flags &= ~AVFMTCTX_NOHEADER;
219  st->codecpar->bit_rate = flv->audio_bit_rate;
221  }
223  st->codecpar->bit_rate = flv->video_bit_rate;
225  st->avg_frame_rate = flv->framerate;
226  }
227 
228  flv->last_keyframe_stream_index = s->nb_streams - 1;
230  return st;
231 }
232 
233 static int flv_same_audio_codec(AVCodecParameters *apar, int flags, uint32_t codec_fourcc)
234 {
235  int bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
236  int flv_codecid = flags & FLV_AUDIO_CODECID_MASK;
237  int codec_id;
238 
239  switch (codec_fourcc) {
240  case MKBETAG('m', 'p', '4', 'a'):
241  return apar->codec_id == AV_CODEC_ID_AAC;
242  case MKBETAG('O', 'p', 'u', 's'):
243  return apar->codec_id == AV_CODEC_ID_OPUS;
244  case MKBETAG('.', 'm', 'p', '3'):
245  return apar->codec_id == AV_CODEC_ID_MP3;
246  case MKBETAG('f', 'L', 'a', 'C'):
247  return apar->codec_id == AV_CODEC_ID_FLAC;
248  case MKBETAG('a', 'c', '-', '3'):
249  return apar->codec_id == AV_CODEC_ID_AC3;
250  case MKBETAG('e', 'c', '-', '3'):
251  return apar->codec_id == AV_CODEC_ID_EAC3;
252  case 0:
253  // Not enhanced flv, continue as normal.
254  break;
255  default:
256  // Unknown FOURCC
257  return 0;
258  }
259 
260  if (!apar->codec_id && !apar->codec_tag)
261  return 1;
262 
263  if (apar->bits_per_coded_sample != bits_per_coded_sample)
264  return 0;
265 
266  switch (flv_codecid) {
267  // no distinction between S16 and S8 PCM codec flags
268  case FLV_CODECID_PCM:
269  codec_id = bits_per_coded_sample == 8
271 #if HAVE_BIGENDIAN
273 #else
275 #endif
276  return codec_id == apar->codec_id;
277  case FLV_CODECID_PCM_LE:
278  codec_id = bits_per_coded_sample == 8
281  return codec_id == apar->codec_id;
282  case FLV_CODECID_AAC:
283  return apar->codec_id == AV_CODEC_ID_AAC;
284  case FLV_CODECID_ADPCM:
285  return apar->codec_id == AV_CODEC_ID_ADPCM_SWF;
286  case FLV_CODECID_SPEEX:
287  return apar->codec_id == AV_CODEC_ID_SPEEX;
288  case FLV_CODECID_MP3:
289  return apar->codec_id == AV_CODEC_ID_MP3;
293  return apar->codec_id == AV_CODEC_ID_NELLYMOSER;
295  return apar->sample_rate == 8000 &&
298  return apar->sample_rate == 8000 &&
300  default:
301  return apar->codec_tag == (flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
302  }
303 }
304 
306  AVCodecParameters *apar, int flv_codecid)
307 {
308  switch (flv_codecid) {
309  // no distinction between S16 and S8 PCM codec flags
310  case FLV_CODECID_PCM:
311  apar->codec_id = apar->bits_per_coded_sample == 8
313 #if HAVE_BIGENDIAN
315 #else
317 #endif
318  break;
319  case FLV_CODECID_PCM_LE:
320  apar->codec_id = apar->bits_per_coded_sample == 8
323  break;
324  case FLV_CODECID_AAC:
325  apar->codec_id = AV_CODEC_ID_AAC;
326  break;
327  case FLV_CODECID_ADPCM:
329  break;
330  case FLV_CODECID_SPEEX:
331  apar->codec_id = AV_CODEC_ID_SPEEX;
332  apar->sample_rate = 16000;
333  break;
334  case FLV_CODECID_MP3:
335  apar->codec_id = AV_CODEC_ID_MP3;
337  break;
339  // in case metadata does not otherwise declare samplerate
340  apar->sample_rate = 8000;
342  break;
344  apar->sample_rate = 16000;
346  break;
349  break;
351  apar->sample_rate = 8000;
353  break;
355  apar->sample_rate = 8000;
357  break;
358  case MKBETAG('m', 'p', '4', 'a'):
359  apar->codec_id = AV_CODEC_ID_AAC;
360  return;
361  case MKBETAG('O', 'p', 'u', 's'):
362  apar->codec_id = AV_CODEC_ID_OPUS;
363  apar->sample_rate = 48000;
364  return;
365  case MKBETAG('.', 'm', 'p', '3'):
366  apar->codec_id = AV_CODEC_ID_MP3;
367  return;
368  case MKBETAG('f', 'L', 'a', 'C'):
369  apar->codec_id = AV_CODEC_ID_FLAC;
370  return;
371  case MKBETAG('a', 'c', '-', '3'):
372  apar->codec_id = AV_CODEC_ID_AC3;
373  return;
374  case MKBETAG('e', 'c', '-', '3'):
375  apar->codec_id = AV_CODEC_ID_EAC3;
376  return;
377  default:
378  avpriv_request_sample(s, "Audio codec (%x)",
379  flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
380  apar->codec_tag = flv_codecid >> FLV_AUDIO_CODECID_OFFSET;
381  }
382 }
383 
384 static int flv_same_video_codec(AVCodecParameters *vpar, uint32_t flv_codecid)
385 {
386  if (!vpar->codec_id && !vpar->codec_tag)
387  return 1;
388 
389  switch (flv_codecid) {
390  case FLV_CODECID_X_HEVC:
391  case MKBETAG('h', 'v', 'c', '1'):
392  return vpar->codec_id == AV_CODEC_ID_HEVC;
393  case MKBETAG('a', 'v', '0', '1'):
394  return vpar->codec_id == AV_CODEC_ID_AV1;
395  case MKBETAG('v', 'p', '0', '9'):
396  return vpar->codec_id == AV_CODEC_ID_VP9;
397  case FLV_CODECID_H263:
398  return vpar->codec_id == AV_CODEC_ID_FLV1;
399  case FLV_CODECID_SCREEN:
400  return vpar->codec_id == AV_CODEC_ID_FLASHSV;
401  case FLV_CODECID_SCREEN2:
402  return vpar->codec_id == AV_CODEC_ID_FLASHSV2;
403  case FLV_CODECID_VP6:
404  return vpar->codec_id == AV_CODEC_ID_VP6F;
405  case FLV_CODECID_VP6A:
406  return vpar->codec_id == AV_CODEC_ID_VP6A;
407  case FLV_CODECID_H264:
408  case MKBETAG('a', 'v', 'c', '1'):
409  return vpar->codec_id == AV_CODEC_ID_H264;
410  default:
411  return vpar->codec_tag == flv_codecid;
412  }
413 }
414 
416  uint32_t flv_codecid, int read)
417 {
418  FFStream *const vstreami = ffstream(vstream);
419  int ret = 0;
420  AVCodecParameters *par = vstream->codecpar;
421  enum AVCodecID old_codec_id = vstream->codecpar->codec_id;
422 
423  switch (flv_codecid) {
424  case FLV_CODECID_X_HEVC:
425  case MKBETAG('h', 'v', 'c', '1'):
426  par->codec_id = AV_CODEC_ID_HEVC;
428  break;
429  case MKBETAG('a', 'v', '0', '1'):
430  par->codec_id = AV_CODEC_ID_AV1;
432  break;
433  case MKBETAG('v', 'p', '0', '9'):
434  par->codec_id = AV_CODEC_ID_VP9;
436  break;
437  case FLV_CODECID_H263:
438  par->codec_id = AV_CODEC_ID_FLV1;
439  break;
441  par->codec_id = AV_CODEC_ID_H263;
442  break; // Really mean it this time
443  case FLV_CODECID_SCREEN:
445  break;
446  case FLV_CODECID_SCREEN2:
448  break;
449  case FLV_CODECID_VP6:
450  par->codec_id = AV_CODEC_ID_VP6F;
451  case FLV_CODECID_VP6A:
452  if (flv_codecid == FLV_CODECID_VP6A)
453  par->codec_id = AV_CODEC_ID_VP6A;
454  if (read) {
455  if (par->extradata_size != 1) {
456  ff_alloc_extradata(par, 1);
457  }
458  if (par->extradata)
459  par->extradata[0] = avio_r8(s->pb);
460  else
461  avio_skip(s->pb, 1);
462  }
463  ret = 1; // 1 byte body size adjustment for flv_read_packet()
464  break;
465  case FLV_CODECID_H264:
466  case MKBETAG('a', 'v', 'c', '1'):
467  par->codec_id = AV_CODEC_ID_H264;
469  break;
470  case FLV_CODECID_MPEG4:
472  break;
473  default:
474  avpriv_request_sample(s, "Video codec (%x)", flv_codecid);
475  par->codec_tag = flv_codecid;
476  }
477 
478  if (!vstreami->need_context_update && par->codec_id != old_codec_id) {
479  avpriv_request_sample(s, "Changing the codec id midstream");
480  return AVERROR_PATCHWELCOME;
481  }
482 
483  return ret;
484 }
485 
486 static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize)
487 {
488  int ret;
489  int length = avio_rb16(ioc);
490  if (length >= buffsize) {
491  avio_skip(ioc, length);
492  return AVERROR_INVALIDDATA;
493  }
494 
495  ret = avio_read(ioc, buffer, length);
496  if (ret < 0)
497  return ret;
498  if (ret < length)
499  return AVERROR_INVALIDDATA;
500 
501  buffer[length] = '\0';
502 
503  return length;
504 }
505 
507 {
508  FLVContext *flv = s->priv_data;
509  unsigned int timeslen = 0, fileposlen = 0, i;
510  char str_val[256];
511  int64_t *times = NULL;
512  int64_t *filepositions = NULL;
513  int ret = AVERROR(ENOSYS);
514  int64_t initial_pos = avio_tell(ioc);
515 
516  if (flv->keyframe_count > 0) {
517  av_log(s, AV_LOG_DEBUG, "keyframes have been parsed\n");
518  return 0;
519  }
520  av_assert0(!flv->keyframe_times);
522 
523  if (s->flags & AVFMT_FLAG_IGNIDX)
524  return 0;
525 
526  while (avio_tell(ioc) < max_pos - 2 &&
527  amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
528  int64_t **current_array;
529  unsigned int arraylen;
530  int factor;
531 
532  // Expect array object in context
533  if (avio_r8(ioc) != AMF_DATA_TYPE_ARRAY)
534  break;
535 
536  arraylen = avio_rb32(ioc);
537  if (arraylen>>28)
538  break;
539 
540  if (!strcmp(KEYFRAMES_TIMESTAMP_TAG , str_val) && !times) {
541  current_array = &times;
542  timeslen = arraylen;
543  factor = 1000;
544  } else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) &&
545  !filepositions) {
546  current_array = &filepositions;
547  fileposlen = arraylen;
548  factor = 1;
549  } else
550  // unexpected metatag inside keyframes, will not use such
551  // metadata for indexing
552  break;
553 
554  if (!(*current_array = av_mallocz(sizeof(**current_array) * arraylen))) {
555  ret = AVERROR(ENOMEM);
556  goto finish;
557  }
558 
559  for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) {
560  double d;
561  if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER)
562  goto invalid;
563  d = av_int2double(avio_rb64(ioc)) * factor;
564  if (isnan(d) || d < INT64_MIN || d > INT64_MAX)
565  goto invalid;
566  if (avio_feof(ioc))
567  goto invalid;
568  current_array[0][i] = d;
569  }
570  if (times && filepositions) {
571  // All done, exiting at a position allowing amf_parse_object
572  // to finish parsing the object
573  ret = 0;
574  break;
575  }
576  }
577 
578  if (timeslen == fileposlen && fileposlen>1 && max_pos <= filepositions[0]) {
579  for (i = 0; i < FFMIN(2,fileposlen); i++) {
580  flv->validate_index[i].pos = filepositions[i];
581  flv->validate_index[i].dts = times[i];
582  flv->validate_count = i + 1;
583  }
584  flv->keyframe_times = times;
585  flv->keyframe_filepositions = filepositions;
586  flv->keyframe_count = timeslen;
587  times = NULL;
588  filepositions = NULL;
589  } else {
590 invalid:
591  av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n");
592  }
593 
594 finish:
595  av_freep(&times);
596  av_freep(&filepositions);
597  avio_seek(ioc, initial_pos, SEEK_SET);
598  return ret;
599 }
600 
602  AVStream *vstream, const char *key,
603  int64_t max_pos, int depth)
604 {
605  AVCodecParameters *apar, *vpar;
606  FLVContext *flv = s->priv_data;
607  AVIOContext *ioc;
608  AMFDataType amf_type;
609  char str_val[1024];
610  double num_val;
611  amf_date date;
612 
613  if (depth > MAX_DEPTH)
614  return AVERROR_PATCHWELCOME;
615 
616  num_val = 0;
617  ioc = s->pb;
618  if (avio_feof(ioc))
619  return AVERROR_EOF;
620  amf_type = avio_r8(ioc);
621 
622  switch (amf_type) {
624  num_val = av_int2double(avio_rb64(ioc));
625  break;
626  case AMF_DATA_TYPE_BOOL:
627  num_val = avio_r8(ioc);
628  break;
630  if (amf_get_string(ioc, str_val, sizeof(str_val)) < 0) {
631  av_log(s, AV_LOG_ERROR, "AMF_DATA_TYPE_STRING parsing failed\n");
632  return -1;
633  }
634  break;
636  if (key &&
637  (ioc->seekable & AVIO_SEEKABLE_NORMAL) &&
638  !strcmp(KEYFRAMES_TAG, key) && depth == 1)
639  if (parse_keyframes_index(s, ioc, max_pos) < 0)
640  av_log(s, AV_LOG_ERROR, "Keyframe index parsing failed\n");
641  else
643  while (avio_tell(ioc) < max_pos - 2 &&
644  amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
645  if (amf_parse_object(s, astream, vstream, str_val, max_pos,
646  depth + 1) < 0)
647  return -1; // if we couldn't skip, bomb out.
648  if (avio_r8(ioc) != AMF_END_OF_OBJECT) {
649  av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_OBJECT\n");
650  return -1;
651  }
652  break;
653  case AMF_DATA_TYPE_NULL:
656  break; // these take up no additional space
658  {
659  unsigned v;
660  avio_skip(ioc, 4); // skip 32-bit max array index
661  while (avio_tell(ioc) < max_pos - 2 &&
662  amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
663  // this is the only case in which we would want a nested
664  // parse to not skip over the object
665  if (amf_parse_object(s, astream, vstream, str_val, max_pos,
666  depth + 1) < 0)
667  return -1;
668  v = avio_r8(ioc);
669  if (v != AMF_END_OF_OBJECT) {
670  av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_MIXEDARRAY, found %d\n", v);
671  return -1;
672  }
673  break;
674  }
675  case AMF_DATA_TYPE_ARRAY:
676  {
677  unsigned int arraylen, i;
678 
679  arraylen = avio_rb32(ioc);
680  for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++)
682  depth + 1) < 0)
683  return -1; // if we couldn't skip, bomb out.
684  }
685  break;
686  case AMF_DATA_TYPE_DATE:
687  // timestamp (double) and UTC offset (int16)
688  date.milliseconds = av_int2double(avio_rb64(ioc));
689  date.timezone = avio_rb16(ioc);
690  break;
691  default: // unsupported type, we couldn't skip
692  av_log(s, AV_LOG_ERROR, "unsupported amf type %d\n", amf_type);
693  return -1;
694  }
695 
696  if (key) {
697  apar = astream ? astream->codecpar : NULL;
698  vpar = vstream ? vstream->codecpar : NULL;
699 
700  // stream info doesn't live any deeper than the first object
701  if (depth == 1) {
702  if (amf_type == AMF_DATA_TYPE_NUMBER ||
703  amf_type == AMF_DATA_TYPE_BOOL) {
704  if (!strcmp(key, "duration"))
705  s->duration = num_val * AV_TIME_BASE;
706  else if (!strcmp(key, "videodatarate") &&
707  0 <= (int)(num_val * 1024.0))
708  flv->video_bit_rate = num_val * 1024.0;
709  else if (!strcmp(key, "audiodatarate") &&
710  0 <= (int)(num_val * 1024.0))
711  flv->audio_bit_rate = num_val * 1024.0;
712  else if (!strcmp(key, "framerate")) {
713  flv->framerate = av_d2q(num_val, 1000);
714  if (vstream)
715  vstream->avg_frame_rate = flv->framerate;
716  } else if (flv->trust_metadata) {
717  if (!strcmp(key, "videocodecid") && vpar) {
718  int ret = flv_set_video_codec(s, vstream, num_val, 0);
719  if (ret < 0)
720  return ret;
721  } else if (!strcmp(key, "audiocodecid") && apar) {
722  int id = ((int)num_val) << FLV_AUDIO_CODECID_OFFSET;
723  flv_set_audio_codec(s, astream, apar, id);
724  } else if (!strcmp(key, "audiosamplerate") && apar) {
725  apar->sample_rate = num_val;
726  } else if (!strcmp(key, "audiosamplesize") && apar) {
727  apar->bits_per_coded_sample = num_val;
728  } else if (!strcmp(key, "stereo") && apar) {
729  av_channel_layout_default(&apar->ch_layout, num_val + 1);
730  } else if (!strcmp(key, "width") && vpar) {
731  vpar->width = num_val;
732  } else if (!strcmp(key, "height") && vpar) {
733  vpar->height = num_val;
734  } else if (!strcmp(key, "datastream")) {
736  if (!st)
737  return AVERROR(ENOMEM);
739  }
740  }
741  }
742  if (amf_type == AMF_DATA_TYPE_STRING) {
743  if (!strcmp(key, "encoder")) {
744  int version = -1;
745  if (1 == sscanf(str_val, "Open Broadcaster Software v0.%d", &version)) {
746  if (version > 0 && version <= 655)
747  flv->broken_sizes = 1;
748  }
749  } else if (!strcmp(key, "metadatacreator")) {
750  if ( !strcmp (str_val, "MEGA")
751  || !strncmp(str_val, "FlixEngine", 10))
752  flv->broken_sizes = 1;
753  }
754  }
755  }
756 
758  FLVMetaVideoColor *meta_video_color = &flv->meta_color_info;
759  if (!strcmp(key, "colorPrimaries")) {
760  meta_video_color->primaries = num_val;
761  } else if (!strcmp(key, "transferCharacteristics")) {
762  meta_video_color->trc = num_val;
763  } else if (!strcmp(key, "matrixCoefficients")) {
764  meta_video_color->matrix_coefficients = num_val;
765  } else if (!strcmp(key, "maxFall")) {
766  meta_video_color->max_fall = num_val;
767  } else if (!strcmp(key, "maxCLL")) {
768  meta_video_color->max_cll = num_val;
769  } else if (!strcmp(key, "redX")) {
770  meta_video_color->mastering_meta.r_x = num_val;
771  } else if (!strcmp(key, "redY")) {
772  meta_video_color->mastering_meta.r_y = num_val;
773  } else if (!strcmp(key, "greenX")) {
774  meta_video_color->mastering_meta.g_x = num_val;
775  } else if (!strcmp(key, "greenY")) {
776  meta_video_color->mastering_meta.g_y = num_val;
777  } else if (!strcmp(key, "blueX")) {
778  meta_video_color->mastering_meta.b_x = num_val;
779  } else if (!strcmp(key, "blueY")) {
780  meta_video_color->mastering_meta.b_y = num_val;
781  } else if (!strcmp(key, "whitePointX")) {
782  meta_video_color->mastering_meta.white_x = num_val;
783  } else if (!strcmp(key, "whitePointY")) {
784  meta_video_color->mastering_meta.white_y = num_val;
785  } else if (!strcmp(key, "maxLuminance")) {
786  meta_video_color->mastering_meta.max_luminance = num_val;
787  } else if (!strcmp(key, "minLuminance")) {
788  meta_video_color->mastering_meta.min_luminance = num_val;
789  }
790  }
791 
792  if (amf_type == AMF_DATA_TYPE_OBJECT && s->nb_streams == 1 &&
793  ((!apar && !strcmp(key, "audiocodecid")) ||
794  (!vpar && !strcmp(key, "videocodecid"))))
795  s->ctx_flags &= ~AVFMTCTX_NOHEADER; //If there is either audio/video missing, codecid will be an empty object
796 
797  if ((!strcmp(key, "duration") ||
798  !strcmp(key, "filesize") ||
799  !strcmp(key, "width") ||
800  !strcmp(key, "height") ||
801  !strcmp(key, "videodatarate") ||
802  !strcmp(key, "framerate") ||
803  !strcmp(key, "videocodecid") ||
804  !strcmp(key, "audiodatarate") ||
805  !strcmp(key, "audiosamplerate") ||
806  !strcmp(key, "audiosamplesize") ||
807  !strcmp(key, "stereo") ||
808  !strcmp(key, "audiocodecid") ||
809  !strcmp(key, "datastream")) && !flv->dump_full_metadata)
810  return 0;
811 
812  s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
813  if (amf_type == AMF_DATA_TYPE_BOOL) {
814  av_strlcpy(str_val, num_val > 0 ? "true" : "false",
815  sizeof(str_val));
816  av_dict_set(&s->metadata, key, str_val, 0);
817  } else if (amf_type == AMF_DATA_TYPE_NUMBER) {
818  snprintf(str_val, sizeof(str_val), "%.f", num_val);
819  av_dict_set(&s->metadata, key, str_val, 0);
820  } else if (amf_type == AMF_DATA_TYPE_STRING) {
821  av_dict_set(&s->metadata, key, str_val, 0);
822  } else if ( amf_type == AMF_DATA_TYPE_DATE
823  && isfinite(date.milliseconds)
824  && date.milliseconds > INT64_MIN/1000
825  && date.milliseconds < INT64_MAX/1000
826  ) {
827  // timezone is ignored, since there is no easy way to offset the UTC
828  // timestamp into the specified timezone
829  avpriv_dict_set_timestamp(&s->metadata, key, 1000 * (int64_t)date.milliseconds);
830  }
831  }
832 
833  return 0;
834 }
835 
836 #define TYPE_ONTEXTDATA 1
837 #define TYPE_ONCAPTION 2
838 #define TYPE_ONCAPTIONINFO 3
839 #define TYPE_UNKNOWN 9
840 
842 {
843  FLVContext *flv = s->priv_data;
845  AVStream *stream, *astream, *vstream;
846  AVStream av_unused *dstream;
847  AVIOContext *ioc;
848  int i;
849  char buffer[32];
850 
851  astream = NULL;
852  vstream = NULL;
853  dstream = NULL;
854  ioc = s->pb;
855 
856  // first object needs to be "onMetaData" string
857  type = avio_r8(ioc);
858  if (type != AMF_DATA_TYPE_STRING ||
859  amf_get_string(ioc, buffer, sizeof(buffer)) < 0)
860  return TYPE_UNKNOWN;
861 
862  if (!strcmp(buffer, "onTextData"))
863  return TYPE_ONTEXTDATA;
864 
865  if (!strcmp(buffer, "onCaption"))
866  return TYPE_ONCAPTION;
867 
868  if (!strcmp(buffer, "onCaptionInfo"))
869  return TYPE_ONCAPTIONINFO;
870 
871  if (strcmp(buffer, "onMetaData") && strcmp(buffer, "onCuePoint") && strcmp(buffer, "|RtmpSampleAccess")) {
872  av_log(s, AV_LOG_DEBUG, "Unknown type %s\n", buffer);
873  return TYPE_UNKNOWN;
874  }
875 
876  // find the streams now so that amf_parse_object doesn't need to do
877  // the lookup every time it is called.
878  for (i = 0; i < s->nb_streams; i++) {
879  stream = s->streams[i];
880  if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
881  vstream = stream;
883  } else if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
884  astream = stream;
885  if (flv->last_keyframe_stream_index == -1)
887  } else if (stream->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
888  dstream = stream;
889  }
890 
891  // parse the second object (we want a mixed array)
892  if (amf_parse_object(s, astream, vstream, buffer, next_pos, 0) < 0)
893  return -1;
894 
895  return 0;
896 }
897 
899 {
900  FFFormatContext *const si = ffformatcontext(s);
901  int flags;
902  FLVContext *flv = s->priv_data;
903  int offset;
904  int pre_tag_size = 0;
905 
906  /* Actual FLV data at 0xe40000 in KUX file */
907  if(!strcmp(s->iformat->name, "kux"))
908  avio_skip(s->pb, 0xe40000);
909 
910  avio_skip(s->pb, 4);
911  flags = avio_r8(s->pb);
912 
914 
915  s->ctx_flags |= AVFMTCTX_NOHEADER;
916 
917  offset = avio_rb32(s->pb);
918  avio_seek(s->pb, offset, SEEK_SET);
919 
920  /* Annex E. The FLV File Format
921  * E.3 TheFLVFileBody
922  * Field Type Comment
923  * PreviousTagSize0 UI32 Always 0
924  * */
925  pre_tag_size = avio_rb32(s->pb);
926  if (pre_tag_size) {
927  av_log(s, AV_LOG_WARNING, "Read FLV header error, input file is not a standard flv format, first PreviousTagSize0 always is 0\n");
928  }
929 
930  s->start_time = 0;
931  flv->sum_flv_tag_size = 0;
932  flv->last_keyframe_stream_index = -1;
933 
934  return 0;
935 }
936 
938 {
939  int i;
940  FLVContext *flv = s->priv_data;
941  for (i = 0; i < FLV_STREAM_TYPE_NB; i++)
942  av_freep(&flv->new_extradata[i]);
943  for (i = 0; i < flv->mt_extradata_cnt; i++)
944  av_freep(&flv->mt_extradata[i]);
945  av_freep(&flv->mt_extradata);
946  av_freep(&flv->mt_extradata_sz);
947  av_freep(&flv->keyframe_times);
949  return 0;
950 }
951 
953 {
954  int ret;
955  if (!size)
956  return 0;
957 
958  if ((ret = ff_get_extradata(s, st->codecpar, s->pb, size)) < 0)
959  return ret;
960  ffstream(st)->need_context_update = 1;
961  return 0;
962 }
963 
964 static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream,
965  int size, int multitrack)
966 {
967  if (!size)
968  return 0;
969 
970  if (!multitrack) {
971  av_free(flv->new_extradata[stream]);
972  flv->new_extradata[stream] = av_mallocz(size +
974  if (!flv->new_extradata[stream])
975  return AVERROR(ENOMEM);
976  flv->new_extradata_size[stream] = size;
977  avio_read(pb, flv->new_extradata[stream], size);
978  } else {
979  int new_count = stream + 1;
980 
981  if (flv->mt_extradata_cnt < new_count) {
982  void *tmp = av_realloc_array(flv->mt_extradata, new_count,
983  sizeof(*flv->mt_extradata));
984  if (!tmp)
985  return AVERROR(ENOMEM);
986  flv->mt_extradata = tmp;
987 
988  tmp = av_realloc_array(flv->mt_extradata_sz, new_count,
989  sizeof(*flv->mt_extradata_sz));
990  if (!tmp)
991  return AVERROR(ENOMEM);
992  flv->mt_extradata_sz = tmp;
993 
994  // Set newly allocated pointers/sizes to 0
995  for (int i = flv->mt_extradata_cnt; i < new_count; i++) {
996  flv->mt_extradata[i] = NULL;
997  flv->mt_extradata_sz[i] = 0;
998  }
999  flv->mt_extradata_cnt = new_count;
1000  }
1001 
1002  av_free(flv->mt_extradata[stream]);
1004  if (!flv->mt_extradata[stream])
1005  return AVERROR(ENOMEM);
1006  flv->mt_extradata_sz[stream] = size;
1007  avio_read(pb, flv->mt_extradata[stream], size);
1008  }
1009 
1010  return 0;
1011 }
1012 
1014 {
1016  "Found invalid index entries, clearing the index.\n");
1017  for (unsigned i = 0; i < s->nb_streams; i++) {
1018  FFStream *const sti = ffstream(s->streams[i]);
1019  int out = 0;
1020  /* Remove all index entries that point to >= pos */
1021  for (int j = 0; j < sti->nb_index_entries; j++)
1022  if (sti->index_entries[j].pos < pos)
1023  sti->index_entries[out++] = sti->index_entries[j];
1024  sti->nb_index_entries = out;
1025  }
1026 }
1027 
1028 static int amf_skip_tag(AVIOContext *pb, AMFDataType type, int depth)
1029 {
1030  int nb = -1, ret, parse_name = 1;
1031 
1032  if (depth > MAX_DEPTH)
1033  return AVERROR_PATCHWELCOME;
1034 
1035  if (avio_feof(pb))
1036  return AVERROR_EOF;
1037 
1038  switch (type) {
1039  case AMF_DATA_TYPE_NUMBER:
1040  avio_skip(pb, 8);
1041  break;
1042  case AMF_DATA_TYPE_BOOL:
1043  avio_skip(pb, 1);
1044  break;
1045  case AMF_DATA_TYPE_STRING:
1046  avio_skip(pb, avio_rb16(pb));
1047  break;
1048  case AMF_DATA_TYPE_ARRAY:
1049  parse_name = 0;
1051  nb = avio_rb32(pb);
1052  if (nb < 0)
1053  return AVERROR_INVALIDDATA;
1054  case AMF_DATA_TYPE_OBJECT:
1055  while(!pb->eof_reached && (nb-- > 0 || type != AMF_DATA_TYPE_ARRAY)) {
1056  if (parse_name) {
1057  int size = avio_rb16(pb);
1058  if (!size) {
1059  avio_skip(pb, 1);
1060  break;
1061  }
1062  avio_skip(pb, size);
1063  }
1064  if ((ret = amf_skip_tag(pb, avio_r8(pb), depth + 1)) < 0)
1065  return ret;
1066  }
1067  break;
1068  case AMF_DATA_TYPE_NULL:
1070  break;
1071  default:
1072  return AVERROR_INVALIDDATA;
1073  }
1074  return 0;
1075 }
1076 
1078  int64_t dts, int64_t next)
1079 {
1080  AVIOContext *pb = s->pb;
1081  AVStream *st = NULL;
1082  char buf[20];
1083  int ret = AVERROR_INVALIDDATA;
1084  int i, length = -1;
1085  int array = 0;
1086 
1087  switch (avio_r8(pb)) {
1088  case AMF_DATA_TYPE_ARRAY:
1089  array = 1;
1091  avio_seek(pb, 4, SEEK_CUR);
1092  case AMF_DATA_TYPE_OBJECT:
1093  break;
1094  default:
1095  goto skip;
1096  }
1097 
1098  while (array || (ret = amf_get_string(pb, buf, sizeof(buf))) > 0) {
1099  AMFDataType type = avio_r8(pb);
1100  if (type == AMF_DATA_TYPE_STRING && (array || !strcmp(buf, "text"))) {
1101  length = avio_rb16(pb);
1102  ret = av_get_packet(pb, pkt, length);
1103  if (ret < 0)
1104  goto skip;
1105  else
1106  break;
1107  } else {
1108  if ((ret = amf_skip_tag(pb, type, 0)) < 0)
1109  goto skip;
1110  }
1111  }
1112 
1113  if (length < 0) {
1115  goto skip;
1116  }
1117 
1118  for (i = 0; i < s->nb_streams; i++) {
1119  st = s->streams[i];
1121  break;
1122  }
1123 
1124  if (i == s->nb_streams) {
1126  if (!st)
1127  return AVERROR(ENOMEM);
1129  }
1130 
1131  pkt->dts = dts;
1132  pkt->pts = dts;
1133  pkt->size = ret;
1134 
1135  pkt->stream_index = st->index;
1137 
1138 skip:
1139  avio_seek(s->pb, next + 4, SEEK_SET);
1140 
1141  return ret;
1142 }
1143 
1145 {
1146  FLVContext *flv = s->priv_data;
1147  int64_t i;
1148  int64_t pos = avio_tell(s->pb);
1149 
1150  for (i=0; !avio_feof(s->pb); i++) {
1151  int j = i & (RESYNC_BUFFER_SIZE-1);
1152  int j1 = j + RESYNC_BUFFER_SIZE;
1153  flv->resync_buffer[j ] =
1154  flv->resync_buffer[j1] = avio_r8(s->pb);
1155 
1156  if (i >= 8 && pos) {
1157  uint8_t *d = flv->resync_buffer + j1 - 8;
1158  if (d[0] == 'F' &&
1159  d[1] == 'L' &&
1160  d[2] == 'V' &&
1161  d[3] < 5 && d[5] == 0) {
1162  av_log(s, AV_LOG_WARNING, "Concatenated FLV detected, might fail to demux, decode and seek %"PRId64"\n", flv->last_ts);
1163  flv->time_offset = flv->last_ts + 1;
1164  flv->time_pos = avio_tell(s->pb);
1165  }
1166  }
1167 
1168  if (i > 22) {
1169  unsigned lsize2 = AV_RB32(flv->resync_buffer + j1 - 4);
1170  if (lsize2 >= 11 && lsize2 + 8LL < FFMIN(i, RESYNC_BUFFER_SIZE)) {
1171  unsigned size2 = AV_RB24(flv->resync_buffer + j1 - lsize2 + 1 - 4);
1172  unsigned lsize1 = AV_RB32(flv->resync_buffer + j1 - lsize2 - 8);
1173  if (lsize1 >= 11 && lsize1 + 8LL + lsize2 < FFMIN(i, RESYNC_BUFFER_SIZE)) {
1174  unsigned size1 = AV_RB24(flv->resync_buffer + j1 - lsize1 + 1 - lsize2 - 8);
1175  if (size1 == lsize1 - 11 && size2 == lsize2 - 11) {
1176  avio_seek(s->pb, pos + i - lsize1 - lsize2 - 8, SEEK_SET);
1177  return 1;
1178  }
1179  }
1180  }
1181  }
1182  }
1183  return AVERROR_EOF;
1184 }
1185 
1187 {
1188  int ret;
1189  FLVContext *flv = s->priv_data;
1190  AMFDataType type;
1191  AVIOContext *ioc;
1192  char buffer[32];
1193  ioc = s->pb;
1194 
1195  // first object needs to be "colorInfo" string
1196  type = avio_r8(ioc);
1197  if (type != AMF_DATA_TYPE_STRING) {
1198  av_log(s, AV_LOG_WARNING, "Ignore invalid colorInfo\n");
1199  return 0;
1200  }
1201 
1202  ret = amf_get_string(ioc, buffer, sizeof(buffer));
1203  if (ret < 0)
1204  return ret;
1205 
1206  if (strcmp(buffer, "colorInfo") != 0) {
1207  av_log(s, AV_LOG_WARNING, "Ignore invalid colorInfo type %s\n", buffer);
1208  return 0;
1209  }
1210 
1212  ret = amf_parse_object(s, NULL, NULL, buffer, next_pos, 0); // parse metadata
1213  if (ret < 0) {
1215  return ret;
1216  }
1217 
1219 
1220  return 0;
1221 }
1222 
1224 {
1225  FLVContext *flv = s->priv_data;
1226  const FLVMetaVideoColor* meta_video_color = &flv->meta_color_info;
1227  const FLVMasteringMeta *mastering_meta = &meta_video_color->mastering_meta;
1228 
1229  int has_mastering_primaries, has_mastering_luminance;
1230  // Mastering primaries are CIE 1931 coords, and must be > 0.
1231  has_mastering_primaries =
1232  mastering_meta->r_x > 0 && mastering_meta->r_y > 0 &&
1233  mastering_meta->g_x > 0 && mastering_meta->g_y > 0 &&
1234  mastering_meta->b_x > 0 && mastering_meta->b_y > 0 &&
1235  mastering_meta->white_x > 0 && mastering_meta->white_y > 0;
1236  has_mastering_luminance = mastering_meta->max_luminance > 0 && mastering_meta->min_luminance > 0;
1237 
1238  if (meta_video_color->matrix_coefficients != AVCOL_SPC_RESERVED)
1239  st->codecpar->color_space = meta_video_color->matrix_coefficients;
1240  if (meta_video_color->primaries != AVCOL_PRI_RESERVED &&
1241  meta_video_color->primaries != AVCOL_PRI_RESERVED0)
1242  st->codecpar->color_primaries = meta_video_color->primaries;
1243  if (meta_video_color->trc != AVCOL_TRC_RESERVED &&
1244  meta_video_color->trc != AVCOL_TRC_RESERVED0)
1245  st->codecpar->color_trc = meta_video_color->trc;
1246 
1247  if (meta_video_color->max_cll && meta_video_color->max_fall) {
1248  size_t size = 0;
1250  if (!metadata)
1251  return AVERROR(ENOMEM);
1253  AV_PKT_DATA_CONTENT_LIGHT_LEVEL, metadata, size, 0)) {
1254  av_freep(&metadata);
1255  return AVERROR(ENOMEM);
1256  }
1257  metadata->MaxCLL = meta_video_color->max_cll;
1258  metadata->MaxFALL = meta_video_color->max_fall;
1259  }
1260 
1261  if (has_mastering_primaries || has_mastering_luminance) {
1262  size_t size = 0;
1264  AVPacketSideData *sd;
1265 
1266  if (!metadata)
1267  return AVERROR(ENOMEM);
1268 
1272  metadata, size, 0);
1273  if (!sd) {
1274  av_freep(&metadata);
1275  return AVERROR(ENOMEM);
1276  }
1277 
1278  // hdrCll
1279  if (has_mastering_luminance) {
1280  metadata->max_luminance = av_d2q(mastering_meta->max_luminance, INT_MAX);
1281  metadata->min_luminance = av_d2q(mastering_meta->min_luminance, INT_MAX);
1282  metadata->has_luminance = 1;
1283  }
1284  // hdrMdcv
1285  if (has_mastering_primaries) {
1286  metadata->display_primaries[0][0] = av_d2q(mastering_meta->r_x, INT_MAX);
1287  metadata->display_primaries[0][1] = av_d2q(mastering_meta->r_y, INT_MAX);
1288  metadata->display_primaries[1][0] = av_d2q(mastering_meta->g_x, INT_MAX);
1289  metadata->display_primaries[1][1] = av_d2q(mastering_meta->g_y, INT_MAX);
1290  metadata->display_primaries[2][0] = av_d2q(mastering_meta->b_x, INT_MAX);
1291  metadata->display_primaries[2][1] = av_d2q(mastering_meta->b_y, INT_MAX);
1292  metadata->white_point[0] = av_d2q(mastering_meta->white_x, INT_MAX);
1293  metadata->white_point[1] = av_d2q(mastering_meta->white_y, INT_MAX);
1294  metadata->has_primaries = 1;
1295  }
1296  }
1297  return 0;
1298 }
1299 
1300 static int flv_parse_mod_ex_data(AVFormatContext *s, int *pkt_type, int *size, int64_t *dts)
1301 {
1302  int ex_type, ret;
1303  uint8_t *ex_data;
1304 
1305  int ex_size = (uint8_t)avio_r8(s->pb) + 1;
1306  *size -= 1;
1307 
1308  if (ex_size == 256) {
1309  ex_size = (uint16_t)avio_rb16(s->pb) + 1;
1310  *size -= 2;
1311  }
1312 
1313  if (ex_size >= *size) {
1314  av_log(s, AV_LOG_WARNING, "ModEx size larger than remaining data!\n");
1315  return AVERROR(EINVAL);
1316  }
1317 
1318  ex_data = av_malloc(ex_size);
1319  if (!ex_data)
1320  return AVERROR(ENOMEM);
1321 
1322  ret = avio_read(s->pb, ex_data, ex_size);
1323  if (ret < 0) {
1324  av_free(ex_data);
1325  return ret;
1326  }
1327  *size -= ex_size;
1328 
1329  ex_type = (uint8_t)avio_r8(s->pb);
1330  *size -= 1;
1331 
1332  *pkt_type = ex_type & 0x0f;
1333  ex_type &= 0xf0;
1334 
1335  if (ex_type == PacketModExTypeTimestampOffsetNano) {
1336  uint32_t nano_offset;
1337 
1338  if (ex_size != 3) {
1339  av_log(s, AV_LOG_WARNING, "Invalid ModEx size for Type TimestampOffsetNano!\n");
1340  nano_offset = 0;
1341  } else {
1342  nano_offset = (ex_data[0] << 16) | (ex_data[1] << 8) | ex_data[2];
1343  }
1344 
1345  // this is not likely to ever add anything, but right now timestamps are with ms precision
1346  *dts += nano_offset / 1000000;
1347  } else {
1348  av_log(s, AV_LOG_INFO, "Unknown ModEx type: %d", ex_type);
1349  }
1350 
1351  av_free(ex_data);
1352 
1353  return 0;
1354 }
1355 
1357 {
1358  FLVContext *flv = s->priv_data;
1359  int ret = AVERROR_BUG, i, size, flags;
1360  int res = 0;
1361  enum FlvTagType type;
1362  int stream_type = -1;
1363  int64_t next, pos, meta_pos;
1364  int64_t dts, pts = AV_NOPTS_VALUE;
1365  int av_uninit(channels);
1366  int av_uninit(sample_rate);
1367  AVStream *st = NULL;
1368  int last = -1;
1369  int orig_size;
1370  int enhanced_flv = 0;
1371  int multitrack = 0;
1372  int pkt_type = 0;
1373  uint8_t track_idx = 0;
1374  uint32_t codec_id = 0;
1375  int multitrack_type = MultitrackTypeOneTrack;
1376 
1377 retry:
1378  /* pkt size is repeated at end. skip it */
1379  pos = avio_tell(s->pb);
1380  type = (avio_r8(s->pb) & 0x1F);
1381  orig_size =
1382  size = avio_rb24(s->pb);
1383  flv->sum_flv_tag_size += size + 11LL;
1384  dts = avio_rb24(s->pb);
1385  dts |= (unsigned)avio_r8(s->pb) << 24;
1386  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));
1387  if (avio_feof(s->pb))
1388  return AVERROR_EOF;
1389  avio_skip(s->pb, 3); /* stream id, always 0 */
1390  flags = 0;
1391 
1392  if (flv->validate_next < flv->validate_count) {
1393  int64_t validate_pos = flv->validate_index[flv->validate_next].pos;
1394  if (pos == validate_pos) {
1395  if (FFABS(dts - flv->validate_index[flv->validate_next].dts) <=
1397  flv->validate_next++;
1398  } else {
1399  clear_index_entries(s, validate_pos);
1400  flv->validate_count = 0;
1401  }
1402  } else if (pos > validate_pos) {
1403  clear_index_entries(s, validate_pos);
1404  flv->validate_count = 0;
1405  }
1406  }
1407 
1408  if (size == 0) {
1409  ret = FFERROR_REDO;
1410  goto leave;
1411  }
1412 
1413  next = size + avio_tell(s->pb);
1414 
1415  if (type == FLV_TAG_TYPE_AUDIO) {
1416  stream_type = FLV_STREAM_TYPE_AUDIO;
1417  flags = avio_r8(s->pb);
1418  size--;
1419 
1421  enhanced_flv = 1;
1422  pkt_type = flags & ~FLV_AUDIO_CODECID_MASK;
1423 
1424  while (pkt_type == PacketTypeModEx) {
1425  ret = flv_parse_mod_ex_data(s, &pkt_type, &size, &dts);
1426  if (ret < 0)
1427  goto leave;
1428  }
1429 
1430  if (pkt_type == AudioPacketTypeMultitrack) {
1431  uint8_t types = avio_r8(s->pb);
1432  multitrack_type = types & 0xF0;
1433  pkt_type = types & 0xF;
1434 
1435  multitrack = 1;
1436  size--;
1437  }
1438 
1439  codec_id = avio_rb32(s->pb);
1440  size -= 4;
1441 
1442  if (multitrack) {
1443  track_idx = avio_r8(s->pb);
1444  size--;
1445  }
1446  }
1447  } else if (type == FLV_TAG_TYPE_VIDEO) {
1448  stream_type = FLV_STREAM_TYPE_VIDEO;
1449  flags = avio_r8(s->pb);
1451  /*
1452  * Reference Enhancing FLV 2023-03-v1.0.0-B.8
1453  * https://github.com/veovera/enhanced-rtmp/blob/main/enhanced-rtmp-v1.pdf
1454  * */
1455  enhanced_flv = (flags >> 7) & 1;
1456  pkt_type = enhanced_flv ? codec_id : 0;
1457  size--;
1458 
1459  while (pkt_type == PacketTypeModEx) {
1460  ret = flv_parse_mod_ex_data(s, &pkt_type, &size, &dts);
1461  if (ret < 0)
1462  goto leave;
1463  }
1464 
1465  if (enhanced_flv && pkt_type != PacketTypeMetadata &&
1467  goto skip;
1468 
1469  if (pkt_type == PacketTypeMultitrack) {
1470  uint8_t types = avio_r8(s->pb);
1471  multitrack_type = types & 0xF0;
1472  pkt_type = types & 0xF;
1473 
1474  multitrack = 1;
1475  size--;
1476  }
1477 
1478  if (enhanced_flv) {
1479  codec_id = avio_rb32(s->pb);
1480  size -= 4;
1481  }
1482  if (multitrack) {
1483  track_idx = avio_r8(s->pb);
1484  size--;
1485  }
1486 
1487  if (enhanced_flv && (flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_VIDEO_INFO_CMD) {
1488  if (pkt_type == PacketTypeMetadata) {
1489  ret = flv_parse_video_color_info(s, st, next);
1490  if (ret < 0)
1491  goto leave;
1492  }
1493  goto skip;
1495  goto skip;
1496  }
1497  } else if (type == FLV_TAG_TYPE_META) {
1498  stream_type=FLV_STREAM_TYPE_SUBTITLE;
1499  if (size > 13 + 1 + 4) { // Header-type metadata stuff
1500  int type;
1501  meta_pos = avio_tell(s->pb);
1502  type = flv_read_metabody(s, next);
1503  if (type == 0 && dts == 0 || type < 0) {
1504  if (type < 0 && flv->validate_count &&
1505  flv->validate_index[0].pos > next &&
1506  flv->validate_index[0].pos - 4 < next) {
1507  av_log(s, AV_LOG_WARNING, "Adjusting next position due to index mismatch\n");
1508  next = flv->validate_index[0].pos - 4;
1509  }
1510  goto skip;
1511  } else if (type == TYPE_ONTEXTDATA) {
1512  avpriv_request_sample(s, "OnTextData packet");
1513  return flv_data_packet(s, pkt, dts, next);
1514  } else if (type == TYPE_ONCAPTION) {
1515  return flv_data_packet(s, pkt, dts, next);
1516  } else if (type == TYPE_UNKNOWN) {
1517  stream_type = FLV_STREAM_TYPE_DATA;
1518  }
1519  avio_seek(s->pb, meta_pos, SEEK_SET);
1520  }
1521  } else {
1523  "Skipping flv packet: type %d, size %d, flags %d.\n",
1524  type, size, flags);
1525 skip:
1526  if (avio_seek(s->pb, next, SEEK_SET) != next) {
1527  // This can happen if flv_read_metabody above read past
1528  // next, on a non-seekable input, and the preceding data has
1529  // been flushed out from the IO buffer.
1530  av_log(s, AV_LOG_ERROR, "Unable to seek to the next packet\n");
1531  return AVERROR_INVALIDDATA;
1532  }
1533  ret = FFERROR_REDO;
1534  goto leave;
1535  }
1536 
1537  /* skip empty data packets */
1538  if (!size) {
1539  ret = FFERROR_REDO;
1540  goto leave;
1541  }
1542 
1543  for (;;) {
1544  int track_size = size;
1545 
1546  if (multitrack_type != MultitrackTypeOneTrack) {
1547  track_size = avio_rb24(s->pb);
1548  size -= 3;
1549  }
1550 
1551  /* now find stream */
1552  for (i = 0; i < s->nb_streams; i++) {
1553  st = s->streams[i];
1554  if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1555  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
1556  (s->audio_codec_id || flv_same_audio_codec(st->codecpar, flags, codec_id)) &&
1557  st->id == track_idx)
1558  break;
1559  } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1560  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
1561  (s->video_codec_id || flv_same_video_codec(st->codecpar, codec_id)) &&
1562  st->id == track_idx)
1563  break;
1564  } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1566  break;
1567  } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1569  break;
1570  }
1571  }
1572  if (i == s->nb_streams) {
1574  st = create_stream(s, stream_types[stream_type], track_idx);
1575  if (!st)
1576  return AVERROR(ENOMEM);
1577  }
1578  av_log(s, AV_LOG_TRACE, "%d %X %d \n", stream_type, flags, st->discard);
1579 
1580  if (flv->time_pos <= pos) {
1581  dts += flv->time_offset;
1582  }
1583 
1584  if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1586  stream_type == FLV_STREAM_TYPE_AUDIO))
1587  av_add_index_entry(st, pos, dts, track_size, 0, AVINDEX_KEYFRAME);
1588 
1589  if ((st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || stream_type == FLV_STREAM_TYPE_AUDIO)) ||
1591  st->discard >= AVDISCARD_ALL) {
1592  avio_seek(s->pb, next, SEEK_SET);
1593  ret = FFERROR_REDO;
1594  goto leave;
1595  }
1596 
1597  // if not streamed and no duration from metadata then seek to end to find
1598  // the duration from the timestamps
1599  if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1600  (!s->duration || s->duration == AV_NOPTS_VALUE) &&
1601  !flv->searched_for_end) {
1602  int final_size;
1603  const int64_t pos = avio_tell(s->pb);
1604  // Read the last 4 bytes of the file, this should be the size of the
1605  // previous FLV tag. Use the timestamp of its payload as duration.
1606  int64_t fsize = avio_size(s->pb);
1607 retry_duration:
1608  avio_seek(s->pb, fsize - 4, SEEK_SET);
1609  final_size = avio_rb32(s->pb);
1610  if (final_size > 0 && final_size < fsize) {
1611  // Seek to the start of the last FLV tag at position (fsize - 4 - final_size)
1612  // but skip the byte indicating the type.
1613  avio_seek(s->pb, fsize - 3 - final_size, SEEK_SET);
1614  if (final_size == avio_rb24(s->pb) + 11) {
1615  uint32_t ts = avio_rb24(s->pb);
1616  ts |= (unsigned)avio_r8(s->pb) << 24;
1617  if (ts)
1618  s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
1619  else if (fsize >= 8 && fsize - 8 >= final_size) {
1620  fsize -= final_size+4;
1621  goto retry_duration;
1622  }
1623  }
1624  }
1625 
1626  avio_seek(s->pb, pos, SEEK_SET);
1627  flv->searched_for_end = 1;
1628  }
1629 
1630  if (stream_type == FLV_STREAM_TYPE_AUDIO && !enhanced_flv) {
1631  int bits_per_coded_sample;
1633  sample_rate = 44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >>
1635  bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
1637  !st->codecpar->sample_rate ||
1640  st->codecpar->sample_rate = sample_rate;
1641  st->codecpar->bits_per_coded_sample = bits_per_coded_sample;
1642  }
1643  if (!st->codecpar->codec_id) {
1644  flv_set_audio_codec(s, st, st->codecpar,
1646  flv->last_sample_rate =
1647  sample_rate = st->codecpar->sample_rate;
1648  flv->last_channels =
1650  } else {
1652  if (!par) {
1653  ret = AVERROR(ENOMEM);
1654  goto leave;
1655  }
1656  par->sample_rate = sample_rate;
1657  par->bits_per_coded_sample = bits_per_coded_sample;
1659  sample_rate = par->sample_rate;
1661  }
1662  } else if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1663  if (!st->codecpar->codec_id)
1664  flv_set_audio_codec(s, st, st->codecpar,
1666 
1667  // These are not signalled in the flags anymore
1668  channels = 0;
1669  sample_rate = 0;
1670 
1671  if (pkt_type == AudioPacketTypeMultichannelConfig) {
1672  int channel_order = avio_r8(s->pb);
1673  channels = avio_r8(s->pb);
1674  size -= 2;
1675  track_size -= 2;
1676 
1678 
1679  if (channel_order == AudioChannelOrderCustom) {
1681  if (ret < 0)
1682  return ret;
1683 
1684  for (i = 0; i < channels; i++) {
1685  uint8_t id = avio_r8(s->pb);
1686  size--;
1687  track_size--;
1688 
1689  if (id < 18)
1690  st->codecpar->ch_layout.u.map[i].id = id;
1691  else if (id >= 18 && id <= 23)
1692  st->codecpar->ch_layout.u.map[i].id = id - 18 + AV_CHAN_LOW_FREQUENCY_2;
1693  else if (id == 0xFE)
1695  else
1697  }
1698  } else if (channel_order == AudioChannelOrderNative) {
1699  uint64_t mask = avio_rb32(s->pb);
1700  size -= 4;
1701  track_size -= 4;
1702 
1703  // The first 18 entries in the mask match ours, but the remaining 6 entries start at AV_CHAN_LOW_FREQUENCY_2
1704  mask = (mask & 0x3FFFF) | ((mask & 0xFC0000) << (AV_CHAN_LOW_FREQUENCY_2 - 18));
1706  if (ret < 0)
1707  return ret;
1708  } else {
1710  }
1711 
1712  av_log(s, AV_LOG_DEBUG, "Set channel data from MultiChannel info.\n");
1713 
1714  goto next_track;
1715  }
1716  } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1717  int sret = flv_set_video_codec(s, st, codec_id, 1);
1718  if (sret < 0)
1719  return sret;
1720  size -= sret;
1721  track_size -= sret;
1722  } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1724  } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1725  st->codecpar->codec_id = AV_CODEC_ID_NONE; // Opaque AMF data
1726  }
1727 
1728  if (st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1734  st->codecpar->codec_id == AV_CODEC_ID_AV1 ||
1735  st->codecpar->codec_id == AV_CODEC_ID_VP9) {
1736  int type = 0;
1737  if (enhanced_flv) {
1738  type = pkt_type;
1739  } else {
1740  type = avio_r8(s->pb);
1741  size--;
1742  track_size--;
1743  }
1744 
1745  if (size < 0 || track_size < 0) {
1747  goto leave;
1748  }
1749 
1750  if (enhanced_flv && stream_type == FLV_STREAM_TYPE_VIDEO &&
1752  flv_update_video_color_info(s, st); // update av packet side data
1754  }
1755 
1756  if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 ||
1758  (!enhanced_flv || type == PacketTypeCodedFrames))) {
1759  // sign extension
1760  int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000;
1761  pts = av_sat_add64(dts, cts);
1762  if (cts < 0) { // dts might be wrong
1763  if (!flv->wrong_dts)
1765  "Negative cts, previous timestamps might be wrong.\n");
1766  flv->wrong_dts = 1;
1767  } else if (FFABS(dts - pts) > 1000*60*15) {
1769  "invalid timestamps %"PRId64" %"PRId64"\n", dts, pts);
1770  dts = pts = AV_NOPTS_VALUE;
1771  }
1772  size -= 3;
1773  track_size -= 3;
1774  }
1775  if (type == 0 && (!st->codecpar->extradata || st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1779  AVDictionaryEntry *t;
1780 
1781  if (st->codecpar->extradata) {
1782  if ((ret = flv_queue_extradata(flv, s->pb, multitrack ? track_idx : stream_type, track_size, multitrack)) < 0)
1783  return ret;
1784  ret = FFERROR_REDO;
1785  goto leave;
1786  }
1787  if ((ret = flv_get_extradata(s, st, track_size)) < 0)
1788  return ret;
1789 
1790  /* Workaround for buggy Omnia A/XE encoder */
1791  t = av_dict_get(s->metadata, "Encoder", NULL, 0);
1792  if (st->codecpar->codec_id == AV_CODEC_ID_AAC && t && !strcmp(t->value, "Omnia A/XE"))
1793  st->codecpar->extradata_size = 2;
1794 
1795  ret = FFERROR_REDO;
1796  goto leave;
1797  }
1798  }
1799 
1800  /* skip empty or broken data packets */
1801  if (size <= 0 || track_size < 0) {
1802  ret = FFERROR_REDO;
1803  goto leave;
1804  }
1805 
1806  /* skip empty data track */
1807  if (!track_size)
1808  goto next_track;
1809 
1810  ret = av_get_packet(s->pb, pkt, track_size);
1811  if (ret < 0)
1812  return ret;
1813 
1814  track_size -= ret;
1815  size -= ret;
1816 
1817  pkt->dts = dts;
1818  pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts;
1819  pkt->stream_index = st->index;
1820  pkt->pos = pos;
1821  if (!multitrack && flv->new_extradata[stream_type]) {
1823  flv->new_extradata[stream_type],
1824  flv->new_extradata_size[stream_type]);
1825  if (ret < 0)
1826  return ret;
1827 
1828  flv->new_extradata[stream_type] = NULL;
1829  flv->new_extradata_size[stream_type] = 0;
1830  } else if (multitrack &&
1831  flv->mt_extradata_cnt > track_idx &&
1832  flv->mt_extradata[track_idx]) {
1834  flv->mt_extradata[track_idx],
1835  flv->mt_extradata_sz[track_idx]);
1836  if (ret < 0)
1837  return ret;
1838 
1839  flv->mt_extradata[track_idx] = NULL;
1840  flv->mt_extradata_sz[track_idx] = 0;
1841  }
1842  if (stream_type == FLV_STREAM_TYPE_AUDIO && !enhanced_flv &&
1843  (sample_rate != flv->last_sample_rate ||
1844  channels != flv->last_channels)) {
1845  flv->last_sample_rate = sample_rate;
1846  flv->last_channels = channels;
1847  ff_add_param_change(pkt, channels, 0, sample_rate, 0, 0);
1848  }
1849 
1850  if (stream_type == FLV_STREAM_TYPE_AUDIO ||
1852  stream_type == FLV_STREAM_TYPE_SUBTITLE ||
1853  stream_type == FLV_STREAM_TYPE_DATA)
1855 
1856  ret = ff_buffer_packet(s, pkt);
1857  if (ret < 0)
1858  return ret;
1859  res = FFERROR_REDO;
1860 
1861 next_track:
1862  if (track_size) {
1863  av_log(s, AV_LOG_WARNING, "Track size mismatch: %d!\n", track_size);
1864  avio_skip(s->pb, track_size);
1865  size -= track_size;
1866  }
1867 
1868  if (!size)
1869  break;
1870 
1871  if (multitrack_type == MultitrackTypeOneTrack) {
1872  av_log(s, AV_LOG_ERROR, "Attempted to read next track in single-track mode.\n");
1873  ret = FFERROR_REDO;
1874  goto leave;
1875  }
1876 
1877  if (multitrack_type == MultitrackTypeManyTracksManyCodecs) {
1878  codec_id = avio_rb32(s->pb);
1879  size -= 4;
1880  }
1881 
1882  track_idx = avio_r8(s->pb);
1883  size--;
1884 
1885  if (avio_feof(s->pb)) {
1886  av_log(s, AV_LOG_WARNING, "Premature EOF\n");
1887  /* return REDO so that any potentially queued up packages can be drained first */
1888  return FFERROR_REDO;
1889  }
1890  }
1891 
1892  ret = 0;
1893 leave:
1894  last = avio_rb32(s->pb);
1895  if (!flv->trust_datasize) {
1896  if (last != orig_size + 11 && last != orig_size + 10 &&
1897  !avio_feof(s->pb) &&
1898  (last != orig_size || !last) && last != flv->sum_flv_tag_size &&
1899  !flv->broken_sizes) {
1900  av_log(s, AV_LOG_ERROR, "Packet mismatch %d %d %"PRId64"\n", last, orig_size + 11, flv->sum_flv_tag_size);
1901  avio_seek(s->pb, pos + 1, SEEK_SET);
1902  ret = resync(s);
1904  if (ret >= 0) {
1905  goto retry;
1906  }
1907  }
1908  }
1909 
1910  if (ret >= 0)
1911  flv->last_ts = pkt->dts;
1912 
1913  return ret ? ret : res;
1914 }
1915 
1916 static int flv_read_seek(AVFormatContext *s, int stream_index,
1917  int64_t ts, int flags)
1918 {
1919  FLVContext *flv = s->priv_data;
1920  flv->validate_count = 0;
1921  return avio_seek_time(s->pb, stream_index, ts, flags);
1922 }
1923 
1924 #define OFFSET(x) offsetof(FLVContext, x)
1925 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1926 static const AVOption options[] = {
1927  { "flv_metadata", "Allocate streams according to the onMetaData array", OFFSET(trust_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1928  { "flv_full_metadata", "Dump full metadata of the onMetadata", OFFSET(dump_full_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1929  { "flv_ignore_prevtag", "Ignore the Size of previous tag", OFFSET(trust_datasize), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1930  { NULL }
1931 };
1932 
1933 static const AVClass flv_kux_class = {
1934  .class_name = "(live) flv/kux demuxer",
1935  .item_name = av_default_item_name,
1936  .option = options,
1937  .version = LIBAVUTIL_VERSION_INT,
1938 };
1939 
1941  .p.name = "flv",
1942  .p.long_name = NULL_IF_CONFIG_SMALL("FLV (Flash Video)"),
1943  .p.extensions = "flv",
1944  .p.priv_class = &flv_kux_class,
1945  .priv_data_size = sizeof(FLVContext),
1946  .read_probe = flv_probe,
1951 };
1952 
1954  .p.name = "live_flv",
1955  .p.long_name = NULL_IF_CONFIG_SMALL("live RTMP FLV (Flash Video)"),
1956  .p.extensions = "flv",
1957  .p.priv_class = &flv_kux_class,
1958  .p.flags = AVFMT_TS_DISCONT,
1959  .priv_data_size = sizeof(FLVContext),
1965 };
1966 
1968  .p.name = "kux",
1969  .p.long_name = NULL_IF_CONFIG_SMALL("KUX (YouKu)"),
1970  .p.extensions = "kux",
1971  .p.priv_class = &flv_kux_class,
1972  .priv_data_size = sizeof(FLVContext),
1973  .read_probe = kux_probe,
1978 };
AVCOL_PRI_RESERVED
@ AVCOL_PRI_RESERVED
Definition: pixfmt.h:619
AV_CODEC_ID_PCM_S16LE
@ AV_CODEC_ID_PCM_S16LE
Definition: codec_id.h:335
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:103
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:430
AMF_DATA_TYPE_OBJECT_END
@ AMF_DATA_TYPE_OBJECT_END
Definition: flv.h:176
FLV_CODECID_H264
@ FLV_CODECID_H264
Definition: flv.h:117
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
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_STREAM_TYPE_SUBTITLE
@ FLV_STREAM_TYPE_SUBTITLE
Definition: flv.h:74
FLV_TAG_TYPE_VIDEO
@ FLV_TAG_TYPE_VIDEO
Definition: flv.h:67
AV_CODEC_ID_AC3
@ AV_CODEC_ID_AC3
Definition: codec_id.h:451
FLVContext::pos
int64_t pos
Definition: flvdec.c:89
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
FLV_CODECID_VP6A
@ FLV_CODECID_VP6A
Definition: flv.h:115
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:640
clear_index_entries
static void clear_index_entries(AVFormatContext *s, int64_t pos)
Definition: flvdec.c:1013
FLVContext::validate_next
int validate_next
Definition: flvdec.c:91
out
FILE * out
Definition: movenc.c:55
FLV_CODECID_NELLYMOSER_8KHZ_MONO
@ FLV_CODECID_NELLYMOSER_8KHZ_MONO
Definition: flv.h:102
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
AudioChannelOrderNative
@ AudioChannelOrderNative
Definition: flv.h:149
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:838
flv_data_packet
static int flv_data_packet(AVFormatContext *s, AVPacket *pkt, int64_t dts, int64_t next)
Definition: flvdec.c:1077
int64_t
long long int64_t
Definition: coverity.c:34
FLVContext::meta_color_info
FLVMetaVideoColor meta_color_info
Definition: flvdec.c:111
AVChannelLayout::map
AVChannelCustom * map
This member must be used when the channel order is AV_CHANNEL_ORDER_CUSTOM.
Definition: channel_layout.h:370
ff_buffer_packet
int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt)
Definition: demux.c:613
dict_internal.h
av_unused
#define av_unused
Definition: attributes.h:131
mask
int mask
Definition: mediacodecdec_common.c:154
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:108
FLV_HEADER_FLAG_HASVIDEO
@ FLV_HEADER_FLAG_HASVIDEO
Definition: flv.h:61
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
FLVContext::trust_metadata
int trust_metadata
configure streams according onMetaData
Definition: flvdec.c:79
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:1356
FLV_CODECID_VP6
@ FLV_CODECID_VP6
Definition: flv.h:114
TYPE_ONCAPTION
#define TYPE_ONCAPTION
Definition: flvdec.c:837
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:95
amf_date
Definition: flvdec.c:120
AMF_DATA_TYPE_UNDEFINED
@ AMF_DATA_TYPE_UNDEFINED
Definition: flv.h:173
AMF_DATA_TYPE_DATE
@ AMF_DATA_TYPE_DATE
Definition: flv.h:178
flv_set_audio_codec
static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, AVCodecParameters *apar, int flv_codecid)
Definition: flvdec.c:305
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:59
FLVMasteringMeta::b_x
float b_x
Definition: flvdec.c:54
AV_CODEC_ID_FLAC
@ AV_CODEC_ID_FLAC
Definition: codec_id.h:460
AVProbeData::buf_size
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:454
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:615
FLV_CODECID_NELLYMOSER_16KHZ_MONO
@ FLV_CODECID_NELLYMOSER_16KHZ_MONO
Definition: flv.h:101
FLVContext::trust_datasize
int trust_datasize
trust data size of FLVTag
Definition: flvdec.c:80
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:329
intfloat.h
codec_type
enum AVMediaType codec_type
Definition: rtp.c:37
AMF_DATA_TYPE_OBJECT
@ AMF_DATA_TYPE_OBJECT
Definition: flv.h:171
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:1953
PacketTypeMultitrack
@ PacketTypeMultitrack
Definition: flv.h:132
FLV_CODECID_X_HEVC
@ FLV_CODECID_X_HEVC
Definition: flv.h:122
FLV_CODECID_PCM_ALAW
@ FLV_CODECID_PCM_ALAW
Definition: flv.h:104
options
static const AVOption options[]
Definition: flvdec.c:1926
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
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
FLV_CODECID_H263
@ FLV_CODECID_H263
Definition: flv.h:112
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:463
FLV_FRAME_DISP_INTER
@ FLV_FRAME_DISP_INTER
disposable inter frame (H.263 only)
Definition: flv.h:162
FLVContext::video_bit_rate
int64_t video_bit_rate
Definition: flvdec.c:102
FLVContext::searched_for_end
int searched_for_end
Definition: flvdec.c:93
FLVMasteringMeta::r_y
float r_y
Definition: flvdec.c:51
AVCOL_SPC_RESERVED
@ AVCOL_SPC_RESERVED
reserved for future use by ITU-T and ISO/IEC just like 15-255 are
Definition: pixfmt.h:673
FLVContext::keyframe_times
int64_t * keyframe_times
Definition: flvdec.c:104
FLVContext::keyframe_filepositions
int64_t * keyframe_filepositions
Definition: flvdec.c:105
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:868
finish
static void finish(void)
Definition: movenc.c:374
OFFSET
#define OFFSET(x)
Definition: flvdec.c:1924
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:198
AV_CODEC_ID_SPEEX
@ AV_CODEC_ID_SPEEX
Definition: codec_id.h:483
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:358
FLVContext::last_ts
int64_t last_ts
Definition: flvdec.c:107
AV_CODEC_ID_PCM_S16BE
@ AV_CODEC_ID_PCM_S16BE
Definition: codec_id.h:336
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:836
flv_read_seek
static int flv_read_seek(AVFormatContext *s, int stream_index, int64_t ts, int flags)
Definition: flvdec.c:1916
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
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
FLV_CODECID_SPEEX
@ FLV_CODECID_SPEEX
Definition: flv.h:108
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:449
FLV_AUDIO_CODECID_OFFSET
#define FLV_AUDIO_CODECID_OFFSET
Definition: flv.h:34
FLVMasteringMeta::white_y
float white_y
Definition: flvdec.c:57
AVCodecParameters::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: codec_par.h:168
VD
#define VD
Definition: flvdec.c:1925
avassert.h
AMFDataType
AMFDataType
Definition: flv.h:167
parse_keyframes_index
static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, int64_t max_pos)
Definition: flvdec.c:506
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
PacketTypeMetadata
@ PacketTypeMetadata
Definition: flv.h:130
VALIDATE_INDEX_TS_THRESH
#define VALIDATE_INDEX_TS_THRESH
Definition: flvdec.c:43
AVCOL_PRI_RESERVED0
@ AVCOL_PRI_RESERVED0
Definition: pixfmt.h:616
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
flv_parse_mod_ex_data
static int flv_parse_mod_ex_data(AVFormatContext *s, int *pkt_type, int *size, int64_t *dts)
Definition: flvdec.c:1300
AudioPacketTypeMultitrack
@ AudioPacketTypeMultitrack
Definition: flv.h:140
FLVContext::new_extradata_size
int new_extradata_size[FLV_STREAM_TYPE_NB]
Definition: flvdec.c:84
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:180
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:553
AV_CHAN_UNKNOWN
@ AV_CHAN_UNKNOWN
Channel contains data, but its position is unknown.
Definition: channel_layout.h:94
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
av_channel_layout_from_mask
int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
Definition: channel_layout.c:252
FLV_COLOR_INFO_FLAG_NONE
@ FLV_COLOR_INFO_FLAG_NONE
Definition: flvdec.c:72
FLVContext::dts
int64_t dts
Definition: flvdec.c:88
amf_skip_tag
static int amf_skip_tag(AVIOContext *pb, AMFDataType type, int depth)
Definition: flvdec.c:1028
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
channels
channels
Definition: aptx.h:31
FLV_CODECID_MP3
@ FLV_CODECID_MP3
Definition: flv.h:99
FLVContext::time_pos
int64_t time_pos
Definition: flvdec.c:109
isfinite
#define isfinite(x)
Definition: libm.h:359
PacketTypeModEx
@ PacketTypeModEx
Definition: flv.h:133
AV_CODEC_ID_PCM_MULAW
@ AV_CODEC_ID_PCM_MULAW
Definition: codec_id.h:341
flv_queue_extradata
static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream, int size, int multitrack)
Definition: flvdec.c:964
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:149
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
FLV_FRAME_VIDEO_INFO_CMD
@ FLV_FRAME_VIDEO_INFO_CMD
video info/command frame
Definition: flv.h:164
FLVContext::sum_flv_tag_size
int64_t sum_flv_tag_size
Definition: flvdec.c:98
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
FLVMetaVideoColor::max_cll
uint16_t max_cll
Definition: flvdec.c:66
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:839
create_stream
static AVStream * create_stream(AVFormatContext *s, int codec_type, int track_idx)
Definition: flvdec.c:199
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
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:342
FLV_CODECID_EX_HEADER
@ FLV_CODECID_EX_HEADER
Definition: flv.h:106
flv_read_close
static int flv_read_close(AVFormatContext *s)
Definition: flvdec.c:937
AV_CODEC_ID_FLASHSV2
@ AV_CODEC_ID_FLASHSV2
Definition: codec_id.h:183
internal.h
AVCOL_TRC_RESERVED0
@ AVCOL_TRC_RESERVED0
Definition: pixfmt.h:641
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
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:168
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
FLV_CODECID_SCREEN
@ FLV_CODECID_SCREEN
Definition: flv.h:113
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
FLVMasteringMeta::g_y
float g_y
Definition: flvdec.c:53
AVFMTCTX_NOHEADER
#define AVFMTCTX_NOHEADER
signal that no header is present (streams are added dynamically)
Definition: avformat.h:1251
FLV_STEREO
@ FLV_STEREO
Definition: flv.h:81
AMF_DATA_TYPE_BOOL
@ AMF_DATA_TYPE_BOOL
Definition: flv.h:169
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:898
isnan
#define isnan(x)
Definition: libm.h:340
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:239
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:86
AMF_DATA_TYPE_ARRAY
@ AMF_DATA_TYPE_ARRAY
Definition: flv.h:177
FLVMasteringMeta::b_y
float b_y
Definition: flvdec.c:55
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:1186
FLVContext::keyframe_count
int keyframe_count
Definition: flvdec.c:101
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
FLV_STREAM_TYPE_AUDIO
@ FLV_STREAM_TYPE_AUDIO
Definition: flv.h:73
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
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
AV_CODEC_ID_EAC3
@ AV_CODEC_ID_EAC3
Definition: codec_id.h:488
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:450
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
FLVMasteringMeta::g_x
float g_x
Definition: flvdec.c:52
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
AVIOContext::seekable
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:261
FLVMasteringMeta::min_luminance
float min_luminance
Definition: flvdec.c:59
FFStream
Definition: internal.h:132
flv_update_video_color_info
static int flv_update_video_color_info(AVFormatContext *s, AVStream *st)
Definition: flvdec.c:1223
FLVMasteringMeta::white_x
float white_x
Definition: flvdec.c:56
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:387
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:77
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:1940
FLVContext::mt_extradata
uint8_t ** mt_extradata
Definition: flvdec.c:114
AV_CODEC_ID_OPUS
@ AV_CODEC_ID_OPUS
Definition: codec_id.h:508
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:122
KEYFRAMES_TAG
#define KEYFRAMES_TAG
Definition: flv.h:55
FLVMetaVideoColor::matrix_coefficients
enum AVColorSpace matrix_coefficients
Definition: flvdec.c:63
FFInputFormat::p
AVInputFormat p
The public AVInputFormat.
Definition: demux.h:46
AudioPacketTypeMultichannelConfig
@ AudioPacketTypeMultichannelConfig
Definition: flv.h:139
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
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:700
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
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:545
read_header
static int read_header(FFV1Context *f, RangeCoder *c)
Definition: ffv1dec.c:394
version
version
Definition: libkvazaar.c:321
AV_CHAN_UNUSED
@ AV_CHAN_UNUSED
Channel is empty can be safely skipped.
Definition: channel_layout.h:91
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:220
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
FLV_COLOR_INFO_FLAG_PARSING
@ FLV_COLOR_INFO_FLAG_PARSING
Definition: flvdec.c:74
av_channel_layout_custom_init
int av_channel_layout_custom_init(AVChannelLayout *channel_layout, int nb_channels)
Initialize a custom channel layout with the specified number of channels.
Definition: channel_layout.c:232
kux_probe
static int kux_probe(const AVProbeData *p)
Definition: flvdec.c:154
av_mastering_display_metadata_alloc_size
AVMasteringDisplayMetadata * av_mastering_display_metadata_alloc_size(size_t *size)
Allocate an AVMasteringDisplayMetadata structure and set its fields to default values.
Definition: mastering_display_metadata.c:44
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:839
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
FLVMetaVideoColor::primaries
enum AVColorPrimaries primaries
Definition: flvdec.c:65
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
FLVContext::last_keyframe_stream_index
int last_keyframe_stream_index
Definition: flvdec.c:100
flv_read_metabody
static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
Definition: flvdec.c:841
FLV_HEADER_FLAG_HASAUDIO
@ FLV_HEADER_FLAG_HASAUDIO
Definition: flv.h:62
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:1144
FLVContext::framerate
AVRational framerate
Definition: flvdec.c:106
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:669
flv_probe
static int flv_probe(const AVProbeData *p)
Definition: flvdec.c:144
FLVContext::meta_color_info_flag
enum FLVMetaColorInfoFlag meta_color_info_flag
Definition: flvdec.c:112
MultitrackTypeOneTrack
@ MultitrackTypeOneTrack
Definition: flv.h:154
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
FLV_STREAM_TYPE_DATA
@ FLV_STREAM_TYPE_DATA
Definition: flv.h:75
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:82
AVCodecParameters::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
Definition: codec_par.h:81
AMF_DATA_TYPE_MIXEDARRAY
@ AMF_DATA_TYPE_MIXEDARRAY
Definition: flv.h:175
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:170
FLVContext::new_extradata
uint8_t * new_extradata[FLV_STREAM_TYPE_NB]
Definition: flvdec.c:83
FFFormatContext::missing_streams
int missing_streams
Definition: internal.h:124
av_uninit
#define av_uninit(x)
Definition: attributes.h:154
FLV_CODECID_PCM
@ FLV_CODECID_PCM
Definition: flv.h:97
array
static int array[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:116
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:760
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:125
flv_kux_class
static const AVClass flv_kux_class
Definition: flvdec.c:1933
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
FLVMetaVideoColor::max_fall
uint16_t max_fall
Definition: flvdec.c:67
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:783
AVSTREAM_PARSE_HEADERS
@ AVSTREAM_PARSE_HEADERS
Only parse headers, do not repack.
Definition: avformat.h:594
pos
unsigned int pos
Definition: spdifenc.c:414
avformat.h
dict.h
AV_CODEC_ID_TEXT
@ AV_CODEC_ID_TEXT
raw UTF-8 text
Definition: codec_id.h:560
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
id
enum AVCodecID id
Definition: dts2pts.c:367
amf_get_string
static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize)
Definition: flvdec.c:486
av_sat_add64
#define av_sat_add64
Definition: common.h:139
AudioChannelOrderCustom
@ AudioChannelOrderCustom
Definition: flv.h:150
FLV_CODECID_SCREEN2
@ FLV_CODECID_SCREEN2
Definition: flv.h:116
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:754
channel_layout.h
AV_CHAN_LOW_FREQUENCY_2
@ AV_CHAN_LOW_FREQUENCY_2
Definition: channel_layout.h:76
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
FLVMetaColorInfoFlag
FLVMetaColorInfoFlag
Definition: flvdec.c:71
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:442
FLV_TAG_TYPE_META
@ FLV_TAG_TYPE_META
Definition: flv.h:68
flv_set_video_codec
static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, uint32_t flv_codecid, int read)
Definition: flvdec.c:415
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:601
FLV_CODECID_MPEG4
@ FLV_CODECID_MPEG4
Definition: flv.h:119
FLV_STREAM_TYPE_VIDEO
@ FLV_STREAM_TYPE_VIDEO
Definition: flv.h:72
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
FLVContext::validate_index
struct FLVContext::@392 validate_index[2]
flv_same_video_codec
static int flv_same_video_codec(AVCodecParameters *vpar, uint32_t flv_codecid)
Definition: flvdec.c:384
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
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
FLVMetaVideoColor::trc
enum AVColorTransferCharacteristic trc
Definition: flvdec.c:64
FFStream::index_entries
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: internal.h:188
FLV_STREAM_TYPE_NB
@ FLV_STREAM_TYPE_NB
Definition: flv.h:76
ff_kux_demuxer
const FFInputFormat ff_kux_demuxer
Definition: flvdec.c:1967
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
MultitrackTypeManyTracksManyCodecs
@ MultitrackTypeManyTracksManyCodecs
Definition: flv.h:156
AV_CODEC_ID_PCM_U8
@ AV_CODEC_ID_PCM_U8
Definition: codec_id.h:340
mastering_display_metadata.h
FLVContext::mt_extradata_sz
int * mt_extradata_sz
Definition: flvdec.c:115
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
AVCOL_TRC_RESERVED
@ AVCOL_TRC_RESERVED
Definition: pixfmt.h:644
flv_get_extradata
static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size)
Definition: flvdec.c:952
AMF_DATA_TYPE_NUMBER
@ AMF_DATA_TYPE_NUMBER
Definition: flv.h:168
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
FLVMasteringMeta::r_x
float r_x
Definition: flvdec.c:50
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
AVChannelLayout::u
union AVChannelLayout::@434 u
Details about which channels are present in this layout.
FLVContext::mt_extradata_cnt
int mt_extradata_cnt
Definition: flvdec.c:116
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
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
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
FLVContext::validate_count
int validate_count
Definition: flvdec.c:92
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
FLV_CODECID_AAC
@ FLV_CODECID_AAC
Definition: flv.h:107
FLV_CODECID_REALH263
@ FLV_CODECID_REALH263
Definition: flv.h:118
FLV_AUDIO_SAMPLESIZE_MASK
#define FLV_AUDIO_SAMPLESIZE_MASK
Definition: flv.h:46
AVDictionaryEntry::value
char * value
Definition: dict.h:91
avstring.h
FLV_CODECID_PCM_MULAW
@ FLV_CODECID_PCM_MULAW
Definition: flv.h:105
PacketTypeCodedFrames
@ PacketTypeCodedFrames
Definition: flv.h:127
FLV_COLOR_INFO_FLAG_GOT
@ FLV_COLOR_INFO_FLAG_GOT
Definition: flvdec.c:73
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:121
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
flv_same_audio_codec
static int flv_same_audio_codec(AVCodecParameters *apar, int flags, uint32_t codec_fourcc)
Definition: flvdec.c:233
PacketModExTypeTimestampOffsetNano
@ PacketModExTypeTimestampOffsetNano
Definition: flv.h:144
FLVMasteringMeta::max_luminance
float max_luminance
Definition: flvdec.c:58
FLV_CODECID_NELLYMOSER
@ FLV_CODECID_NELLYMOSER
Definition: flv.h:103
FLV_CODECID_ADPCM
@ FLV_CODECID_ADPCM
Definition: flv.h:98
FLV_CODECID_PCM_LE
@ FLV_CODECID_PCM_LE
Definition: flv.h:100
snprintf
#define snprintf
Definition: snprintf.h:34
FLVContext::dump_full_metadata
int dump_full_metadata
Dump full metadata of the onMetadata.
Definition: flvdec.c:81
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
AVChannelCustom::id
enum AVChannel id
Definition: channel_layout.h:284
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:375
FLV_FRAME_KEY
@ FLV_FRAME_KEY
key frame (for AVC, a seekable frame)
Definition: flv.h:160
FLVContext::last_sample_rate
int last_sample_rate
Definition: flvdec.c:85
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:172
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:481
FLVContext::broken_sizes
int broken_sizes
Definition: flvdec.c:97
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