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