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