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