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