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