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/avstring.h"
29 #include "libavutil/dict.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/intfloat.h"
32 #include "libavutil/mathematics.h"
34 #include "libavcodec/bytestream.h"
35 #include "libavcodec/mpeg4audio.h"
36 #include "avformat.h"
37 #include "internal.h"
38 #include "avio_internal.h"
39 #include "flv.h"
40 
41 #define VALIDATE_INDEX_TS_THRESH 2500
42 
43 #define RESYNC_BUFFER_SIZE (1<<20)
44 
45 #define MAX_DEPTH 16 ///< arbitrary limit to prevent unbounded recursion
46 
47 typedef struct FLVContext {
48  const AVClass *class; ///< Class for private options.
49  int trust_metadata; ///< configure streams according onMetaData
50  int trust_datasize; ///< trust data size of FLVTag
51  int dump_full_metadata; ///< Dump full metadata of the onMetadata
52  int wrong_dts; ///< wrong dts due to negative cts
57  struct {
58  int64_t dts;
59  int64_t pos;
60  } validate_index[2];
64 
66 
69 
72  int64_t video_bit_rate;
73  int64_t audio_bit_rate;
74  int64_t *keyframe_times;
78  int64_t last_ts;
79  int64_t time_offset;
80  int64_t time_pos;
81 } FLVContext;
82 
83 /* AMF date type */
84 typedef struct amf_date {
85  double milliseconds;
86  int16_t timezone;
87 } amf_date;
88 
89 static int probe(const AVProbeData *p, int live)
90 {
91  const uint8_t *d = p->buf;
92  unsigned offset = AV_RB32(d + 5);
93 
94  if (d[0] == 'F' &&
95  d[1] == 'L' &&
96  d[2] == 'V' &&
97  d[3] < 5 && d[5] == 0 &&
98  offset + 100 < p->buf_size &&
99  offset > 8) {
100  int is_live = !memcmp(d + offset + 40, "NGINX RTMP", 10);
101 
102  if (live == is_live)
103  return AVPROBE_SCORE_MAX;
104  }
105  return 0;
106 }
107 
108 static int flv_probe(const AVProbeData *p)
109 {
110  return probe(p, 0);
111 }
112 
113 static int live_flv_probe(const AVProbeData *p)
114 {
115  return probe(p, 1);
116 }
117 
118 static int kux_probe(const AVProbeData *p)
119 {
120  const uint8_t *d = p->buf;
121 
122  if (d[0] == 'K' &&
123  d[1] == 'D' &&
124  d[2] == 'K' &&
125  d[3] == 0 &&
126  d[4] == 0) {
127  return AVPROBE_SCORE_EXTENSION + 1;
128  }
129  return 0;
130 }
131 
133 {
134  FLVContext *flv = s->priv_data;
135  AVStream *stream = NULL;
136  unsigned int i = 0;
137 
138  if (flv->last_keyframe_stream_index < 0) {
139  av_log(s, AV_LOG_DEBUG, "keyframe stream hasn't been created\n");
140  return;
141  }
142 
143  av_assert0(flv->last_keyframe_stream_index <= s->nb_streams);
144  stream = s->streams[flv->last_keyframe_stream_index];
145 
146  if (stream->nb_index_entries == 0) {
147  for (i = 0; i < flv->keyframe_count; i++) {
148  av_log(s, AV_LOG_TRACE, "keyframe filepositions = %"PRId64" times = %"PRId64"\n",
149  flv->keyframe_filepositions[i], flv->keyframe_times[i] * 1000);
151  flv->keyframe_times[i] * 1000, 0, 0, AVINDEX_KEYFRAME);
152  }
153  } else
154  av_log(s, AV_LOG_WARNING, "Skipping duplicate index\n");
155 
156  if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
157  av_freep(&flv->keyframe_times);
159  flv->keyframe_count = 0;
160  }
161 }
162 
164 {
165  FLVContext *flv = s->priv_data;
167  if (!st)
168  return NULL;
170  if (s->nb_streams>=3 ||( s->nb_streams==2
171  && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE
172  && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE
173  && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_DATA
174  && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_DATA))
175  s->ctx_flags &= ~AVFMTCTX_NOHEADER;
177  st->codecpar->bit_rate = flv->audio_bit_rate;
179  }
181  st->codecpar->bit_rate = flv->video_bit_rate;
183  st->avg_frame_rate = flv->framerate;
184  }
185 
186 
187  avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
188  flv->last_keyframe_stream_index = s->nb_streams - 1;
190  return st;
191 }
192 
194 {
195  int bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
196  int flv_codecid = flags & FLV_AUDIO_CODECID_MASK;
197  int codec_id;
198 
199  if (!apar->codec_id && !apar->codec_tag)
200  return 1;
201 
202  if (apar->bits_per_coded_sample != bits_per_coded_sample)
203  return 0;
204 
205  switch (flv_codecid) {
206  // no distinction between S16 and S8 PCM codec flags
207  case FLV_CODECID_PCM:
208  codec_id = bits_per_coded_sample == 8
210 #if HAVE_BIGENDIAN
212 #else
214 #endif
215  return codec_id == apar->codec_id;
216  case FLV_CODECID_PCM_LE:
217  codec_id = bits_per_coded_sample == 8
220  return codec_id == apar->codec_id;
221  case FLV_CODECID_AAC:
222  return apar->codec_id == AV_CODEC_ID_AAC;
223  case FLV_CODECID_ADPCM:
224  return apar->codec_id == AV_CODEC_ID_ADPCM_SWF;
225  case FLV_CODECID_SPEEX:
226  return apar->codec_id == AV_CODEC_ID_SPEEX;
227  case FLV_CODECID_MP3:
228  return apar->codec_id == AV_CODEC_ID_MP3;
232  return apar->codec_id == AV_CODEC_ID_NELLYMOSER;
234  return apar->sample_rate == 8000 &&
237  return apar->sample_rate == 8000 &&
239  default:
240  return apar->codec_tag == (flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
241  }
242 }
243 
245  AVCodecParameters *apar, int flv_codecid)
246 {
247  switch (flv_codecid) {
248  // no distinction between S16 and S8 PCM codec flags
249  case FLV_CODECID_PCM:
250  apar->codec_id = apar->bits_per_coded_sample == 8
252 #if HAVE_BIGENDIAN
254 #else
256 #endif
257  break;
258  case FLV_CODECID_PCM_LE:
259  apar->codec_id = apar->bits_per_coded_sample == 8
262  break;
263  case FLV_CODECID_AAC:
264  apar->codec_id = AV_CODEC_ID_AAC;
265  break;
266  case FLV_CODECID_ADPCM:
268  break;
269  case FLV_CODECID_SPEEX:
270  apar->codec_id = AV_CODEC_ID_SPEEX;
271  apar->sample_rate = 16000;
272  break;
273  case FLV_CODECID_MP3:
274  apar->codec_id = AV_CODEC_ID_MP3;
276  break;
278  // in case metadata does not otherwise declare samplerate
279  apar->sample_rate = 8000;
281  break;
283  apar->sample_rate = 16000;
285  break;
288  break;
290  apar->sample_rate = 8000;
292  break;
294  apar->sample_rate = 8000;
296  break;
297  default:
298  avpriv_request_sample(s, "Audio codec (%x)",
299  flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
300  apar->codec_tag = flv_codecid >> FLV_AUDIO_CODECID_OFFSET;
301  }
302 }
303 
305 {
306  int flv_codecid = flags & FLV_VIDEO_CODECID_MASK;
307 
308  if (!vpar->codec_id && !vpar->codec_tag)
309  return 1;
310 
311  switch (flv_codecid) {
312  case FLV_CODECID_H263:
313  return vpar->codec_id == AV_CODEC_ID_FLV1;
314  case FLV_CODECID_SCREEN:
315  return vpar->codec_id == AV_CODEC_ID_FLASHSV;
316  case FLV_CODECID_SCREEN2:
317  return vpar->codec_id == AV_CODEC_ID_FLASHSV2;
318  case FLV_CODECID_VP6:
319  return vpar->codec_id == AV_CODEC_ID_VP6F;
320  case FLV_CODECID_VP6A:
321  return vpar->codec_id == AV_CODEC_ID_VP6A;
322  case FLV_CODECID_H264:
323  return vpar->codec_id == AV_CODEC_ID_H264;
324  default:
325  return vpar->codec_tag == flv_codecid;
326  }
327 }
328 
330  int flv_codecid, int read)
331 {
332  int ret = 0;
333  AVCodecParameters *par = vstream->codecpar;
334  enum AVCodecID old_codec_id = vstream->codecpar->codec_id;
335  switch (flv_codecid) {
336  case FLV_CODECID_H263:
337  par->codec_id = AV_CODEC_ID_FLV1;
338  break;
340  par->codec_id = AV_CODEC_ID_H263;
341  break; // Really mean it this time
342  case FLV_CODECID_SCREEN:
344  break;
345  case FLV_CODECID_SCREEN2:
347  break;
348  case FLV_CODECID_VP6:
349  par->codec_id = AV_CODEC_ID_VP6F;
350  case FLV_CODECID_VP6A:
351  if (flv_codecid == FLV_CODECID_VP6A)
352  par->codec_id = AV_CODEC_ID_VP6A;
353  if (read) {
354  if (par->extradata_size != 1) {
355  ff_alloc_extradata(par, 1);
356  }
357  if (par->extradata)
358  par->extradata[0] = avio_r8(s->pb);
359  else
360  avio_skip(s->pb, 1);
361  }
362  ret = 1; // 1 byte body size adjustment for flv_read_packet()
363  break;
364  case FLV_CODECID_H264:
365  par->codec_id = AV_CODEC_ID_H264;
367  ret = 3; // not 4, reading packet type will consume one byte
368  break;
369  case FLV_CODECID_MPEG4:
371  ret = 3;
372  break;
373  default:
374  avpriv_request_sample(s, "Video codec (%x)", flv_codecid);
375  par->codec_tag = flv_codecid;
376  }
377 
378  if (!vstream->internal->need_context_update && par->codec_id != old_codec_id) {
379  avpriv_request_sample(s, "Changing the codec id midstream");
380  return AVERROR_PATCHWELCOME;
381  }
382 
383  return ret;
384 }
385 
386 static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize)
387 {
388  int ret;
389  int length = avio_rb16(ioc);
390  if (length >= buffsize) {
391  avio_skip(ioc, length);
392  return -1;
393  }
394 
395  ret = avio_read(ioc, buffer, length);
396  if (ret < 0)
397  return ret;
398  if (ret < length)
399  return AVERROR_INVALIDDATA;
400 
401  buffer[length] = '\0';
402 
403  return length;
404 }
405 
407 {
408  FLVContext *flv = s->priv_data;
409  unsigned int timeslen = 0, fileposlen = 0, i;
410  char str_val[256];
411  int64_t *times = NULL;
412  int64_t *filepositions = NULL;
413  int ret = AVERROR(ENOSYS);
414  int64_t initial_pos = avio_tell(ioc);
415 
416  if (flv->keyframe_count > 0) {
417  av_log(s, AV_LOG_DEBUG, "keyframes have been parsed\n");
418  return 0;
419  }
420  av_assert0(!flv->keyframe_times);
422 
423  if (s->flags & AVFMT_FLAG_IGNIDX)
424  return 0;
425 
426  while (avio_tell(ioc) < max_pos - 2 &&
427  amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
428  int64_t **current_array;
429  unsigned int arraylen;
430 
431  // Expect array object in context
432  if (avio_r8(ioc) != AMF_DATA_TYPE_ARRAY)
433  break;
434 
435  arraylen = avio_rb32(ioc);
436  if (arraylen>>28)
437  break;
438 
439  if (!strcmp(KEYFRAMES_TIMESTAMP_TAG , str_val) && !times) {
440  current_array = &times;
441  timeslen = arraylen;
442  } else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) &&
443  !filepositions) {
444  current_array = &filepositions;
445  fileposlen = arraylen;
446  } else
447  // unexpected metatag inside keyframes, will not use such
448  // metadata for indexing
449  break;
450 
451  if (!(*current_array = av_mallocz(sizeof(**current_array) * arraylen))) {
452  ret = AVERROR(ENOMEM);
453  goto finish;
454  }
455 
456  for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) {
457  double d;
458  if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER)
459  goto invalid;
460  d = av_int2double(avio_rb64(ioc));
461  if (isnan(d) || d < INT64_MIN || d > INT64_MAX)
462  goto invalid;
463  if (current_array == &times && (d <= INT64_MIN / 1000 || d >= INT64_MAX / 1000))
464  goto invalid;
465  current_array[0][i] = d;
466  }
467  if (times && filepositions) {
468  // All done, exiting at a position allowing amf_parse_object
469  // to finish parsing the object
470  ret = 0;
471  break;
472  }
473  }
474 
475  if (timeslen == fileposlen && fileposlen>1 && max_pos <= filepositions[0]) {
476  for (i = 0; i < FFMIN(2,fileposlen); i++) {
477  flv->validate_index[i].pos = filepositions[i];
478  flv->validate_index[i].dts = times[i] * 1000;
479  flv->validate_count = i + 1;
480  }
481  flv->keyframe_times = times;
482  flv->keyframe_filepositions = filepositions;
483  flv->keyframe_count = timeslen;
484  times = NULL;
485  filepositions = NULL;
486  } else {
487 invalid:
488  av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n");
489  }
490 
491 finish:
492  av_freep(&times);
493  av_freep(&filepositions);
494  avio_seek(ioc, initial_pos, SEEK_SET);
495  return ret;
496 }
497 
499  AVStream *vstream, const char *key,
500  int64_t max_pos, int depth)
501 {
502  AVCodecParameters *apar, *vpar;
503  FLVContext *flv = s->priv_data;
504  AVIOContext *ioc;
505  AMFDataType amf_type;
506  char str_val[1024];
507  double num_val;
508  amf_date date;
509 
510  if (depth > MAX_DEPTH)
511  return AVERROR_PATCHWELCOME;
512 
513  num_val = 0;
514  ioc = s->pb;
515  if (avio_feof(ioc))
516  return AVERROR_EOF;
517  amf_type = avio_r8(ioc);
518 
519  switch (amf_type) {
521  num_val = av_int2double(avio_rb64(ioc));
522  break;
523  case AMF_DATA_TYPE_BOOL:
524  num_val = avio_r8(ioc);
525  break;
527  if (amf_get_string(ioc, str_val, sizeof(str_val)) < 0) {
528  av_log(s, AV_LOG_ERROR, "AMF_DATA_TYPE_STRING parsing failed\n");
529  return -1;
530  }
531  break;
533  if (key &&
534  (ioc->seekable & AVIO_SEEKABLE_NORMAL) &&
535  !strcmp(KEYFRAMES_TAG, key) && depth == 1)
536  if (parse_keyframes_index(s, ioc,
537  max_pos) < 0)
538  av_log(s, AV_LOG_ERROR, "Keyframe index parsing failed\n");
539  else
541  while (avio_tell(ioc) < max_pos - 2 &&
542  amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
543  if (amf_parse_object(s, astream, vstream, str_val, max_pos,
544  depth + 1) < 0)
545  return -1; // if we couldn't skip, bomb out.
546  if (avio_r8(ioc) != AMF_END_OF_OBJECT) {
547  av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_OBJECT\n");
548  return -1;
549  }
550  break;
551  case AMF_DATA_TYPE_NULL:
554  break; // these take up no additional space
556  {
557  unsigned v;
558  avio_skip(ioc, 4); // skip 32-bit max array index
559  while (avio_tell(ioc) < max_pos - 2 &&
560  amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
561  // this is the only case in which we would want a nested
562  // parse to not skip over the object
563  if (amf_parse_object(s, astream, vstream, str_val, max_pos,
564  depth + 1) < 0)
565  return -1;
566  v = avio_r8(ioc);
567  if (v != AMF_END_OF_OBJECT) {
568  av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_MIXEDARRAY, found %d\n", v);
569  return -1;
570  }
571  break;
572  }
573  case AMF_DATA_TYPE_ARRAY:
574  {
575  unsigned int arraylen, i;
576 
577  arraylen = avio_rb32(ioc);
578  for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++)
580  depth + 1) < 0)
581  return -1; // if we couldn't skip, bomb out.
582  }
583  break;
584  case AMF_DATA_TYPE_DATE:
585  // timestamp (double) and UTC offset (int16)
586  date.milliseconds = av_int2double(avio_rb64(ioc));
587  date.timezone = avio_rb16(ioc);
588  break;
589  default: // unsupported type, we couldn't skip
590  av_log(s, AV_LOG_ERROR, "unsupported amf type %d\n", amf_type);
591  return -1;
592  }
593 
594  if (key) {
595  apar = astream ? astream->codecpar : NULL;
596  vpar = vstream ? vstream->codecpar : NULL;
597 
598  // stream info doesn't live any deeper than the first object
599  if (depth == 1) {
600  if (amf_type == AMF_DATA_TYPE_NUMBER ||
601  amf_type == AMF_DATA_TYPE_BOOL) {
602  if (!strcmp(key, "duration"))
603  s->duration = num_val * AV_TIME_BASE;
604  else if (!strcmp(key, "videodatarate") &&
605  0 <= (int)(num_val * 1024.0))
606  flv->video_bit_rate = num_val * 1024.0;
607  else if (!strcmp(key, "audiodatarate") &&
608  0 <= (int)(num_val * 1024.0))
609  flv->audio_bit_rate = num_val * 1024.0;
610  else if (!strcmp(key, "datastream")) {
612  if (!st)
613  return AVERROR(ENOMEM);
615  } else if (!strcmp(key, "framerate")) {
616  flv->framerate = av_d2q(num_val, 1000);
617  if (vstream)
618  vstream->avg_frame_rate = flv->framerate;
619  } else if (flv->trust_metadata) {
620  if (!strcmp(key, "videocodecid") && vpar) {
621  int ret = flv_set_video_codec(s, vstream, num_val, 0);
622  if (ret < 0)
623  return ret;
624  } else if (!strcmp(key, "audiocodecid") && apar) {
625  int id = ((int)num_val) << FLV_AUDIO_CODECID_OFFSET;
626  flv_set_audio_codec(s, astream, apar, id);
627  } else if (!strcmp(key, "audiosamplerate") && apar) {
628  apar->sample_rate = num_val;
629  } else if (!strcmp(key, "audiosamplesize") && apar) {
630  apar->bits_per_coded_sample = num_val;
631  } else if (!strcmp(key, "stereo") && apar) {
632  apar->channels = num_val + 1;
633  apar->channel_layout = apar->channels == 2 ?
636  } else if (!strcmp(key, "width") && vpar) {
637  vpar->width = num_val;
638  } else if (!strcmp(key, "height") && vpar) {
639  vpar->height = num_val;
640  }
641  }
642  }
643  if (amf_type == AMF_DATA_TYPE_STRING) {
644  if (!strcmp(key, "encoder")) {
645  int version = -1;
646  if (1 == sscanf(str_val, "Open Broadcaster Software v0.%d", &version)) {
647  if (version > 0 && version <= 655)
648  flv->broken_sizes = 1;
649  }
650  } else if (!strcmp(key, "metadatacreator")) {
651  if ( !strcmp (str_val, "MEGA")
652  || !strncmp(str_val, "FlixEngine", 10))
653  flv->broken_sizes = 1;
654  }
655  }
656  }
657 
658  if (amf_type == AMF_DATA_TYPE_OBJECT && s->nb_streams == 1 &&
659  ((!apar && !strcmp(key, "audiocodecid")) ||
660  (!vpar && !strcmp(key, "videocodecid"))))
661  s->ctx_flags &= ~AVFMTCTX_NOHEADER; //If there is either audio/video missing, codecid will be an empty object
662 
663  if ((!strcmp(key, "duration") ||
664  !strcmp(key, "filesize") ||
665  !strcmp(key, "width") ||
666  !strcmp(key, "height") ||
667  !strcmp(key, "videodatarate") ||
668  !strcmp(key, "framerate") ||
669  !strcmp(key, "videocodecid") ||
670  !strcmp(key, "audiodatarate") ||
671  !strcmp(key, "audiosamplerate") ||
672  !strcmp(key, "audiosamplesize") ||
673  !strcmp(key, "stereo") ||
674  !strcmp(key, "audiocodecid") ||
675  !strcmp(key, "datastream")) && !flv->dump_full_metadata)
676  return 0;
677 
678  s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
679  if (amf_type == AMF_DATA_TYPE_BOOL) {
680  av_strlcpy(str_val, num_val > 0 ? "true" : "false",
681  sizeof(str_val));
682  av_dict_set(&s->metadata, key, str_val, 0);
683  } else if (amf_type == AMF_DATA_TYPE_NUMBER) {
684  snprintf(str_val, sizeof(str_val), "%.f", num_val);
685  av_dict_set(&s->metadata, key, str_val, 0);
686  } else if (amf_type == AMF_DATA_TYPE_STRING) {
687  av_dict_set(&s->metadata, key, str_val, 0);
688  } else if (amf_type == AMF_DATA_TYPE_DATE) {
689  time_t time;
690  struct tm t;
691  char datestr[128];
692  time = date.milliseconds / 1000; // to seconds
693  localtime_r(&time, &t);
694  strftime(datestr, sizeof(datestr), "%a, %d %b %Y %H:%M:%S %z", &t);
695 
696  av_dict_set(&s->metadata, key, datestr, 0);
697  }
698  }
699 
700  return 0;
701 }
702 
703 #define TYPE_ONTEXTDATA 1
704 #define TYPE_ONCAPTION 2
705 #define TYPE_ONCAPTIONINFO 3
706 #define TYPE_UNKNOWN 9
707 
708 static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
709 {
710  FLVContext *flv = s->priv_data;
712  AVStream *stream, *astream, *vstream;
713  AVStream av_unused *dstream;
714  AVIOContext *ioc;
715  int i;
716  char buffer[32];
717 
718  astream = NULL;
719  vstream = NULL;
720  dstream = NULL;
721  ioc = s->pb;
722 
723  // first object needs to be "onMetaData" string
724  type = avio_r8(ioc);
725  if (type != AMF_DATA_TYPE_STRING ||
726  amf_get_string(ioc, buffer, sizeof(buffer)) < 0)
727  return TYPE_UNKNOWN;
728 
729  if (!strcmp(buffer, "onTextData"))
730  return TYPE_ONTEXTDATA;
731 
732  if (!strcmp(buffer, "onCaption"))
733  return TYPE_ONCAPTION;
734 
735  if (!strcmp(buffer, "onCaptionInfo"))
736  return TYPE_ONCAPTIONINFO;
737 
738  if (strcmp(buffer, "onMetaData") && strcmp(buffer, "onCuePoint")) {
739  av_log(s, AV_LOG_DEBUG, "Unknown type %s\n", buffer);
740  return TYPE_UNKNOWN;
741  }
742 
743  // find the streams now so that amf_parse_object doesn't need to do
744  // the lookup every time it is called.
745  for (i = 0; i < s->nb_streams; i++) {
746  stream = s->streams[i];
747  if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
748  vstream = stream;
750  } else if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
751  astream = stream;
752  if (flv->last_keyframe_stream_index == -1)
754  }
755  else if (stream->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
756  dstream = stream;
757  }
758 
759  // parse the second object (we want a mixed array)
760  if (amf_parse_object(s, astream, vstream, buffer, next_pos, 0) < 0)
761  return -1;
762 
763  return 0;
764 }
765 
767 {
768  int flags;
769  FLVContext *flv = s->priv_data;
770  int offset;
771  int pre_tag_size = 0;
772 
773  /* Actual FLV data at 0xe40000 in KUX file */
774  if(!strcmp(s->iformat->name, "kux"))
775  avio_skip(s->pb, 0xe40000);
776 
777  avio_skip(s->pb, 4);
778  flags = avio_r8(s->pb);
779 
781 
782  s->ctx_flags |= AVFMTCTX_NOHEADER;
783 
784  offset = avio_rb32(s->pb);
785  avio_seek(s->pb, offset, SEEK_SET);
786 
787  /* Annex E. The FLV File Format
788  * E.3 TheFLVFileBody
789  * Field Type Comment
790  * PreviousTagSize0 UI32 Always 0
791  * */
792  pre_tag_size = avio_rb32(s->pb);
793  if (pre_tag_size) {
794  av_log(s, AV_LOG_WARNING, "Read FLV header error, input file is not a standard flv format, first PreviousTagSize0 always is 0\n");
795  }
796 
797  s->start_time = 0;
798  flv->sum_flv_tag_size = 0;
799  flv->last_keyframe_stream_index = -1;
800 
801  return 0;
802 }
803 
805 {
806  int i;
807  FLVContext *flv = s->priv_data;
808  for (i=0; i<FLV_STREAM_TYPE_NB; i++)
809  av_freep(&flv->new_extradata[i]);
810  av_freep(&flv->keyframe_times);
812  return 0;
813 }
814 
816 {
817  if (!size)
818  return 0;
819 
820  av_freep(&st->codecpar->extradata);
821  if (ff_get_extradata(s, st->codecpar, s->pb, size) < 0)
822  return AVERROR(ENOMEM);
823  st->internal->need_context_update = 1;
824  return 0;
825 }
826 
827 static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream,
828  int size)
829 {
830  if (!size)
831  return 0;
832 
833  av_free(flv->new_extradata[stream]);
834  flv->new_extradata[stream] = av_mallocz(size +
836  if (!flv->new_extradata[stream])
837  return AVERROR(ENOMEM);
838  flv->new_extradata_size[stream] = size;
839  avio_read(pb, flv->new_extradata[stream], size);
840  return 0;
841 }
842 
843 static void clear_index_entries(AVFormatContext *s, int64_t pos)
844 {
845  int i, j, out;
847  "Found invalid index entries, clearing the index.\n");
848  for (i = 0; i < s->nb_streams; i++) {
849  AVStream *st = s->streams[i];
850  /* Remove all index entries that point to >= pos */
851  out = 0;
852  for (j = 0; j < st->nb_index_entries; j++)
853  if (st->index_entries[j].pos < pos)
854  st->index_entries[out++] = st->index_entries[j];
855  st->nb_index_entries = out;
856  }
857 }
858 
859 static int amf_skip_tag(AVIOContext *pb, AMFDataType type, int depth)
860 {
861  int nb = -1, ret, parse_name = 1;
862 
863  if (depth > MAX_DEPTH)
864  return AVERROR_PATCHWELCOME;
865 
866  if (avio_feof(pb))
867  return AVERROR_EOF;
868 
869  switch (type) {
871  avio_skip(pb, 8);
872  break;
873  case AMF_DATA_TYPE_BOOL:
874  avio_skip(pb, 1);
875  break;
877  avio_skip(pb, avio_rb16(pb));
878  break;
879  case AMF_DATA_TYPE_ARRAY:
880  parse_name = 0;
882  nb = avio_rb32(pb);
883  if (nb < 0)
884  return AVERROR_INVALIDDATA;
886  while(!pb->eof_reached && (nb-- > 0 || type != AMF_DATA_TYPE_ARRAY)) {
887  if (parse_name) {
888  int size = avio_rb16(pb);
889  if (!size) {
890  avio_skip(pb, 1);
891  break;
892  }
893  avio_skip(pb, size);
894  }
895  if ((ret = amf_skip_tag(pb, avio_r8(pb), depth + 1)) < 0)
896  return ret;
897  }
898  break;
899  case AMF_DATA_TYPE_NULL:
901  break;
902  default:
903  return AVERROR_INVALIDDATA;
904  }
905  return 0;
906 }
907 
909  int64_t dts, int64_t next)
910 {
911  AVIOContext *pb = s->pb;
912  AVStream *st = NULL;
913  char buf[20];
914  int ret = AVERROR_INVALIDDATA;
915  int i, length = -1;
916  int array = 0;
917 
918  switch (avio_r8(pb)) {
919  case AMF_DATA_TYPE_ARRAY:
920  array = 1;
922  avio_seek(pb, 4, SEEK_CUR);
924  break;
925  default:
926  goto skip;
927  }
928 
929  while (array || (ret = amf_get_string(pb, buf, sizeof(buf))) > 0) {
930  AMFDataType type = avio_r8(pb);
931  if (type == AMF_DATA_TYPE_STRING && (array || !strcmp(buf, "text"))) {
932  length = avio_rb16(pb);
933  ret = av_get_packet(pb, pkt, length);
934  if (ret < 0)
935  goto skip;
936  else
937  break;
938  } else {
939  if ((ret = amf_skip_tag(pb, type, 0)) < 0)
940  goto skip;
941  }
942  }
943 
944  if (length < 0) {
946  goto skip;
947  }
948 
949  for (i = 0; i < s->nb_streams; i++) {
950  st = s->streams[i];
952  break;
953  }
954 
955  if (i == s->nb_streams) {
957  if (!st)
958  return AVERROR(ENOMEM);
960  }
961 
962  pkt->dts = dts;
963  pkt->pts = dts;
964  pkt->size = ret;
965 
966  pkt->stream_index = st->index;
968 
969 skip:
970  avio_seek(s->pb, next + 4, SEEK_SET);
971 
972  return ret;
973 }
974 
976 {
977  FLVContext *flv = s->priv_data;
978  int64_t i;
979  int64_t pos = avio_tell(s->pb);
980 
981  for (i=0; !avio_feof(s->pb); i++) {
982  int j = i & (RESYNC_BUFFER_SIZE-1);
983  int j1 = j + RESYNC_BUFFER_SIZE;
984  flv->resync_buffer[j ] =
985  flv->resync_buffer[j1] = avio_r8(s->pb);
986 
987  if (i >= 8 && pos) {
988  uint8_t *d = flv->resync_buffer + j1 - 8;
989  if (d[0] == 'F' &&
990  d[1] == 'L' &&
991  d[2] == 'V' &&
992  d[3] < 5 && d[5] == 0) {
993  av_log(s, AV_LOG_WARNING, "Concatenated FLV detected, might fail to demux, decode and seek %"PRId64"\n", flv->last_ts);
994  flv->time_offset = flv->last_ts + 1;
995  flv->time_pos = avio_tell(s->pb);
996  }
997  }
998 
999  if (i > 22) {
1000  unsigned lsize2 = AV_RB32(flv->resync_buffer + j1 - 4);
1001  if (lsize2 >= 11 && lsize2 + 8LL < FFMIN(i, RESYNC_BUFFER_SIZE)) {
1002  unsigned size2 = AV_RB24(flv->resync_buffer + j1 - lsize2 + 1 - 4);
1003  unsigned lsize1 = AV_RB32(flv->resync_buffer + j1 - lsize2 - 8);
1004  if (lsize1 >= 11 && lsize1 + 8LL + lsize2 < FFMIN(i, RESYNC_BUFFER_SIZE)) {
1005  unsigned size1 = AV_RB24(flv->resync_buffer + j1 - lsize1 + 1 - lsize2 - 8);
1006  if (size1 == lsize1 - 11 && size2 == lsize2 - 11) {
1007  avio_seek(s->pb, pos + i - lsize1 - lsize2 - 8, SEEK_SET);
1008  return 1;
1009  }
1010  }
1011  }
1012  }
1013  }
1014  return AVERROR_EOF;
1015 }
1016 
1018 {
1019  FLVContext *flv = s->priv_data;
1020  int ret, i, size, flags;
1021  enum FlvTagType type;
1022  int stream_type=-1;
1023  int64_t next, pos, meta_pos;
1024  int64_t dts, pts = AV_NOPTS_VALUE;
1025  int av_uninit(channels);
1026  int av_uninit(sample_rate);
1027  AVStream *st = NULL;
1028  int last = -1;
1029  int orig_size;
1030 
1031 retry:
1032  /* pkt size is repeated at end. skip it */
1033  pos = avio_tell(s->pb);
1034  type = (avio_r8(s->pb) & 0x1F);
1035  orig_size =
1036  size = avio_rb24(s->pb);
1037  flv->sum_flv_tag_size += size + 11;
1038  dts = avio_rb24(s->pb);
1039  dts |= (unsigned)avio_r8(s->pb) << 24;
1040  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));
1041  if (avio_feof(s->pb))
1042  return AVERROR_EOF;
1043  avio_skip(s->pb, 3); /* stream id, always 0 */
1044  flags = 0;
1045 
1046  if (flv->validate_next < flv->validate_count) {
1047  int64_t validate_pos = flv->validate_index[flv->validate_next].pos;
1048  if (pos == validate_pos) {
1049  if (FFABS(dts - flv->validate_index[flv->validate_next].dts) <=
1051  flv->validate_next++;
1052  } else {
1053  clear_index_entries(s, validate_pos);
1054  flv->validate_count = 0;
1055  }
1056  } else if (pos > validate_pos) {
1057  clear_index_entries(s, validate_pos);
1058  flv->validate_count = 0;
1059  }
1060  }
1061 
1062  if (size == 0) {
1063  ret = FFERROR_REDO;
1064  goto leave;
1065  }
1066 
1067  next = size + avio_tell(s->pb);
1068 
1069  if (type == FLV_TAG_TYPE_AUDIO) {
1070  stream_type = FLV_STREAM_TYPE_AUDIO;
1071  flags = avio_r8(s->pb);
1072  size--;
1073  } else if (type == FLV_TAG_TYPE_VIDEO) {
1074  stream_type = FLV_STREAM_TYPE_VIDEO;
1075  flags = avio_r8(s->pb);
1076  size--;
1078  goto skip;
1079  } else if (type == FLV_TAG_TYPE_META) {
1080  stream_type=FLV_STREAM_TYPE_SUBTITLE;
1081  if (size > 13 + 1 + 4) { // Header-type metadata stuff
1082  int type;
1083  meta_pos = avio_tell(s->pb);
1084  type = flv_read_metabody(s, next);
1085  if (type == 0 && dts == 0 || type < 0) {
1086  if (type < 0 && flv->validate_count &&
1087  flv->validate_index[0].pos > next &&
1088  flv->validate_index[0].pos - 4 < next
1089  ) {
1090  av_log(s, AV_LOG_WARNING, "Adjusting next position due to index mismatch\n");
1091  next = flv->validate_index[0].pos - 4;
1092  }
1093  goto skip;
1094  } else if (type == TYPE_ONTEXTDATA) {
1095  avpriv_request_sample(s, "OnTextData packet");
1096  return flv_data_packet(s, pkt, dts, next);
1097  } else if (type == TYPE_ONCAPTION) {
1098  return flv_data_packet(s, pkt, dts, next);
1099  } else if (type == TYPE_UNKNOWN) {
1100  stream_type = FLV_STREAM_TYPE_DATA;
1101  }
1102  avio_seek(s->pb, meta_pos, SEEK_SET);
1103  }
1104  } else {
1106  "Skipping flv packet: type %d, size %d, flags %d.\n",
1107  type, size, flags);
1108 skip:
1109  if (avio_seek(s->pb, next, SEEK_SET) != next) {
1110  // This can happen if flv_read_metabody above read past
1111  // next, on a non-seekable input, and the preceding data has
1112  // been flushed out from the IO buffer.
1113  av_log(s, AV_LOG_ERROR, "Unable to seek to the next packet\n");
1114  return AVERROR_INVALIDDATA;
1115  }
1116  ret = FFERROR_REDO;
1117  goto leave;
1118  }
1119 
1120  /* skip empty data packets */
1121  if (!size) {
1122  ret = FFERROR_REDO;
1123  goto leave;
1124  }
1125 
1126  /* now find stream */
1127  for (i = 0; i < s->nb_streams; i++) {
1128  st = s->streams[i];
1129  if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1130  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
1131  (s->audio_codec_id || flv_same_audio_codec(st->codecpar, flags)))
1132  break;
1133  } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1134  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
1135  (s->video_codec_id || flv_same_video_codec(st->codecpar, flags)))
1136  break;
1137  } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1139  break;
1140  } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1142  break;
1143  }
1144  }
1145  if (i == s->nb_streams) {
1147  st = create_stream(s, stream_types[stream_type]);
1148  if (!st)
1149  return AVERROR(ENOMEM);
1150 
1151  }
1152  av_log(s, AV_LOG_TRACE, "%d %X %d \n", stream_type, flags, st->discard);
1153 
1154  if (flv->time_pos <= pos) {
1155  dts += flv->time_offset;
1156  }
1157 
1158  if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1160  stream_type == FLV_STREAM_TYPE_AUDIO))
1161  av_add_index_entry(st, pos, dts, size, 0, AVINDEX_KEYFRAME);
1162 
1163  if ( (st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || (stream_type == FLV_STREAM_TYPE_AUDIO)))
1165  || st->discard >= AVDISCARD_ALL
1166  ) {
1167  avio_seek(s->pb, next, SEEK_SET);
1168  ret = FFERROR_REDO;
1169  goto leave;
1170  }
1171 
1172  // if not streamed and no duration from metadata then seek to end to find
1173  // the duration from the timestamps
1174  if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1175  (!s->duration || s->duration == AV_NOPTS_VALUE) &&
1176  !flv->searched_for_end) {
1177  int size;
1178  const int64_t pos = avio_tell(s->pb);
1179  // Read the last 4 bytes of the file, this should be the size of the
1180  // previous FLV tag. Use the timestamp of its payload as duration.
1181  int64_t fsize = avio_size(s->pb);
1182 retry_duration:
1183  avio_seek(s->pb, fsize - 4, SEEK_SET);
1184  size = avio_rb32(s->pb);
1185  if (size > 0 && size < fsize) {
1186  // Seek to the start of the last FLV tag at position (fsize - 4 - size)
1187  // but skip the byte indicating the type.
1188  avio_seek(s->pb, fsize - 3 - size, SEEK_SET);
1189  if (size == avio_rb24(s->pb) + 11) {
1190  uint32_t ts = avio_rb24(s->pb);
1191  ts |= (unsigned)avio_r8(s->pb) << 24;
1192  if (ts)
1193  s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
1194  else if (fsize >= 8 && fsize - 8 >= size) {
1195  fsize -= size+4;
1196  goto retry_duration;
1197  }
1198  }
1199  }
1200 
1201  avio_seek(s->pb, pos, SEEK_SET);
1202  flv->searched_for_end = 1;
1203  }
1204 
1205  if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1206  int bits_per_coded_sample;
1208  sample_rate = 44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >>
1210  bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
1211  if (!st->codecpar->channels || !st->codecpar->sample_rate ||
1213  st->codecpar->channels = channels;
1214  st->codecpar->channel_layout = channels == 1
1218  st->codecpar->bits_per_coded_sample = bits_per_coded_sample;
1219  }
1220  if (!st->codecpar->codec_id) {
1221  flv_set_audio_codec(s, st, st->codecpar,
1223  flv->last_sample_rate =
1225  flv->last_channels =
1226  channels = st->codecpar->channels;
1227  } else {
1229  if (!par) {
1230  ret = AVERROR(ENOMEM);
1231  goto leave;
1232  }
1233  par->sample_rate = sample_rate;
1234  par->bits_per_coded_sample = bits_per_coded_sample;
1236  sample_rate = par->sample_rate;
1238  }
1239  } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1241  if (ret < 0)
1242  return ret;
1243  size -= ret;
1244  } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1246  } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1247  st->codecpar->codec_id = AV_CODEC_ID_NONE; // Opaque AMF data
1248  }
1249 
1250  if (st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1253  int type = avio_r8(s->pb);
1254  size--;
1255 
1256  if (size < 0) {
1258  goto leave;
1259  }
1260 
1262  // sign extension
1263  int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000;
1264  pts = dts + cts;
1265  if (cts < 0) { // dts might be wrong
1266  if (!flv->wrong_dts)
1268  "Negative cts, previous timestamps might be wrong.\n");
1269  flv->wrong_dts = 1;
1270  } else if (FFABS(dts - pts) > 1000*60*15) {
1272  "invalid timestamps %"PRId64" %"PRId64"\n", dts, pts);
1273  dts = pts = AV_NOPTS_VALUE;
1274  }
1275  }
1276  if (type == 0 && (!st->codecpar->extradata || st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1277  st->codecpar->codec_id == AV_CODEC_ID_H264)) {
1278  AVDictionaryEntry *t;
1279 
1280  if (st->codecpar->extradata) {
1281  if ((ret = flv_queue_extradata(flv, s->pb, stream_type, size)) < 0)
1282  return ret;
1283  ret = FFERROR_REDO;
1284  goto leave;
1285  }
1286  if ((ret = flv_get_extradata(s, st, size)) < 0)
1287  return ret;
1288 
1289  /* Workaround for buggy Omnia A/XE encoder */
1290  t = av_dict_get(s->metadata, "Encoder", NULL, 0);
1291  if (st->codecpar->codec_id == AV_CODEC_ID_AAC && t && !strcmp(t->value, "Omnia A/XE"))
1292  st->codecpar->extradata_size = 2;
1293 
1294  if (st->codecpar->codec_id == AV_CODEC_ID_AAC && 0) {
1295  MPEG4AudioConfig cfg;
1296 
1298  st->codecpar->extradata_size * 8, 1) >= 0) {
1299  st->codecpar->channels = cfg.channels;
1300  st->codecpar->channel_layout = 0;
1301  if (cfg.ext_sample_rate)
1303  else
1304  st->codecpar->sample_rate = cfg.sample_rate;
1305  av_log(s, AV_LOG_TRACE, "mp4a config channels %d sample rate %d\n",
1306  st->codecpar->channels, st->codecpar->sample_rate);
1307  }
1308  }
1309 
1310  ret = FFERROR_REDO;
1311  goto leave;
1312  }
1313  }
1314 
1315  /* skip empty data packets */
1316  if (!size) {
1317  ret = FFERROR_REDO;
1318  goto leave;
1319  }
1320 
1321  ret = av_get_packet(s->pb, pkt, size);
1322  if (ret < 0)
1323  return ret;
1324  pkt->dts = dts;
1325  pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts;
1326  pkt->stream_index = st->index;
1327  pkt->pos = pos;
1328  if (flv->new_extradata[stream_type]) {
1330  flv->new_extradata_size[stream_type]);
1331  if (side) {
1332  memcpy(side, flv->new_extradata[stream_type],
1333  flv->new_extradata_size[stream_type]);
1334  av_freep(&flv->new_extradata[stream_type]);
1335  flv->new_extradata_size[stream_type] = 0;
1336  }
1337  }
1338  if (stream_type == FLV_STREAM_TYPE_AUDIO &&
1339  (sample_rate != flv->last_sample_rate ||
1340  channels != flv->last_channels)) {
1342  flv->last_channels = channels;
1344  }
1345 
1346  if ( stream_type == FLV_STREAM_TYPE_AUDIO ||
1348  stream_type == FLV_STREAM_TYPE_SUBTITLE ||
1349  stream_type == FLV_STREAM_TYPE_DATA)
1351 
1352 leave:
1353  last = avio_rb32(s->pb);
1354  if (!flv->trust_datasize) {
1355  if (last != orig_size + 11 && last != orig_size + 10 &&
1356  !avio_feof(s->pb) &&
1357  (last != orig_size || !last) && last != flv->sum_flv_tag_size &&
1358  !flv->broken_sizes) {
1359  av_log(s, AV_LOG_ERROR, "Packet mismatch %d %d %d\n", last, orig_size + 11, flv->sum_flv_tag_size);
1360  avio_seek(s->pb, pos + 1, SEEK_SET);
1361  ret = resync(s);
1363  if (ret >= 0) {
1364  goto retry;
1365  }
1366  }
1367  }
1368 
1369  if (ret >= 0)
1370  flv->last_ts = pkt->dts;
1371 
1372  return ret;
1373 }
1374 
1375 static int flv_read_seek(AVFormatContext *s, int stream_index,
1376  int64_t ts, int flags)
1377 {
1378  FLVContext *flv = s->priv_data;
1379  flv->validate_count = 0;
1380  return avio_seek_time(s->pb, stream_index, ts, flags);
1381 }
1382 
1383 #define OFFSET(x) offsetof(FLVContext, x)
1384 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1385 static const AVOption options[] = {
1386  { "flv_metadata", "Allocate streams according to the onMetaData array", OFFSET(trust_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1387  { "flv_full_metadata", "Dump full metadata of the onMetadata", OFFSET(dump_full_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1388  { "flv_ignore_prevtag", "Ignore the Size of previous tag", OFFSET(trust_datasize), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1389  { "missing_streams", "", OFFSET(missing_streams), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0xFF, VD | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
1390  { NULL }
1391 };
1392 
1393 static const AVClass flv_class = {
1394  .class_name = "flvdec",
1395  .item_name = av_default_item_name,
1396  .option = options,
1397  .version = LIBAVUTIL_VERSION_INT,
1398 };
1399 
1401  .name = "flv",
1402  .long_name = NULL_IF_CONFIG_SMALL("FLV (Flash Video)"),
1403  .priv_data_size = sizeof(FLVContext),
1404  .read_probe = flv_probe,
1409  .extensions = "flv",
1410  .priv_class = &flv_class,
1411 };
1412 
1413 static const AVClass live_flv_class = {
1414  .class_name = "live_flvdec",
1415  .item_name = av_default_item_name,
1416  .option = options,
1417  .version = LIBAVUTIL_VERSION_INT,
1418 };
1419 
1421  .name = "live_flv",
1422  .long_name = NULL_IF_CONFIG_SMALL("live RTMP FLV (Flash Video)"),
1423  .priv_data_size = sizeof(FLVContext),
1429  .extensions = "flv",
1430  .priv_class = &live_flv_class,
1432 };
1433 
1434 static const AVClass kux_class = {
1435  .class_name = "kuxdec",
1436  .item_name = av_default_item_name,
1437  .option = options,
1438  .version = LIBAVUTIL_VERSION_INT,
1439 };
1440 
1442  .name = "kux",
1443  .long_name = NULL_IF_CONFIG_SMALL("KUX (YouKu)"),
1444  .priv_data_size = sizeof(FLVContext),
1445  .read_probe = kux_probe,
1450  .extensions = "kux",
1451  .priv_class = &kux_class,
1452 };
AVStream::index_entries
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: avformat.h:1099
AV_CODEC_ID_PCM_S16LE
@ AV_CODEC_ID_PCM_S16LE
Definition: avcodec.h:463
FLV_CODECID_H263
@ FLV_CODECID_H263
Definition: flv.h:105
FLVContext::audio_bit_rate
int64_t audio_bit_rate
Definition: flvdec.c:73
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:599
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_CODEC_ID_VP6F
@ AV_CODEC_ID_VP6F
Definition: avcodec.h:310
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3971
flv_same_video_codec
static int flv_same_video_codec(AVCodecParameters *vpar, int flags)
Definition: flvdec.c:304
FLV_STREAM_TYPE_VIDEO
@ FLV_STREAM_TYPE_VIDEO
Definition: flv.h:66
FLVContext::pos
int64_t pos
Definition: flvdec.c:59
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
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4480
FLV_STREAM_TYPE_DATA
@ FLV_STREAM_TYPE_DATA
Definition: flv.h:69
AV_OPT_FLAG_READONLY
#define AV_OPT_FLAG_READONLY
The option may not be set through the AVOptions API, only read.
Definition: opt.h:289
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3953
FLV_CODECID_NELLYMOSER
@ FLV_CODECID_NELLYMOSER
Definition: flv.h:97
codec_id
enum AVCodecID codec_id
Definition: qsv.c:72
ff_get_extradata
int ff_get_extradata(AVFormatContext *s, 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: utils.c:3327
clear_index_entries
static void clear_index_entries(AVFormatContext *s, int64_t pos)
Definition: flvdec.c:843
FLVContext::validate_next
int validate_next
Definition: flvdec.c:61
FFERROR_REDO
#define FFERROR_REDO
Returned by demuxers to indicate that data was consumed but discarded (ignored streams or junk data).
Definition: internal.h:657
out
FILE * out
Definition: movenc.c:54
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3949
AVFMT_FLAG_IGNIDX
#define AVFMT_FLAG_IGNIDX
Ignore index.
Definition: avformat.h:1475
FLV_CODECID_MP3
@ FLV_CODECID_MP3
Definition: flv.h:93
AMF_END_OF_OBJECT
#define AMF_END_OF_OBJECT
Definition: flv.h:47
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:925
FLV_CODECID_H264
@ FLV_CODECID_H264
Definition: flv.h:110
av_int2double
static av_always_inline double av_int2double(uint64_t i)
Reinterpret a 64-bit integer as a double.
Definition: intfloat.h:60
AMF_DATA_TYPE_UNSUPPORTED
@ AMF_DATA_TYPE_UNSUPPORTED
Definition: flv.h:136
AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_MONO
Definition: channel_layout.h:85
TYPE_ONCAPTIONINFO
#define TYPE_ONCAPTIONINFO
Definition: flvdec.c:705
flv_data_packet
static int flv_data_packet(AVFormatContext *s, AVPacket *pkt, int64_t dts, int64_t next)
Definition: flvdec.c:908
av_unused
#define av_unused
Definition: attributes.h:125
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: avcodec.h:230
FLVContext::time_offset
int64_t time_offset
Definition: flvdec.c:79
FLVContext::trust_metadata
int trust_metadata
configure streams according onMetaData
Definition: flvdec.c:49
FLV_CODECID_PCM
@ FLV_CODECID_PCM
Definition: flv.h:91
flv_read_packet
static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: flvdec.c:1017
FLV_CODECID_SCREEN
@ FLV_CODECID_SCREEN
Definition: flv.h:106
max_pos
static const int32_t max_pos[4]
Size of the MP-MLQ fixed excitation codebooks.
Definition: g723_1.h:728
AVStream::internal
AVStreamInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1227
TYPE_ONCAPTION
#define TYPE_ONCAPTION
Definition: flvdec.c:704
AVOption
AVOption.
Definition: opt.h:246
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:943
FLVContext::resync_buffer
uint8_t resync_buffer[2 *RESYNC_BUFFER_SIZE]
Definition: flvdec.c:65
amf_date
Definition: flvdec.c:84
FLV_FRAME_VIDEO_INFO_CMD
@ FLV_FRAME_VIDEO_INFO_CMD
video info/command frame
Definition: flv.h:120
channels
channels
Definition: aptx.c:30
flv_set_audio_codec
static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, AVCodecParameters *apar, int flv_codecid)
Definition: flvdec.c:244
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:3961
mathematics.h
AVProbeData::buf_size
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:449
FLVContext::trust_datasize
int trust_datasize
trust data size of FLVTag
Definition: flvdec.c:50
intfloat.h
codec_type
enum AVMediaType codec_type
Definition: rtp.c:37
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:336
FLV_STREAM_TYPE_NB
@ FLV_STREAM_TYPE_NB
Definition: flv.h:70
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1509
sample_rate
sample_rate
Definition: ffmpeg_filter.c:191
options
static const AVOption options[]
Definition: flvdec.c:1385
AVINDEX_KEYFRAME
#define AVINDEX_KEYFRAME
Definition: avformat.h:808
FLV_AUDIO_SAMPLERATE_OFFSET
#define FLV_AUDIO_SAMPLERATE_OFFSET
Definition: flv.h:33
MPEG4AudioConfig
Definition: mpeg4audio.h:33
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:458
FLVContext::video_bit_rate
int64_t video_bit_rate
Definition: flvdec.c:72
FLVContext::searched_for_end
int searched_for_end
Definition: flvdec.c:63
FLVContext::keyframe_times
int64_t * keyframe_times
Definition: flvdec.c:74
AVCodecParameters::channels
int channels
Audio only.
Definition: avcodec.h:4063
FLVContext::keyframe_filepositions
int64_t * keyframe_filepositions
Definition: flvdec.c:75
finish
static void finish(void)
Definition: movenc.c:345
mpeg4audio.h
OFFSET
#define OFFSET(x)
Definition: flvdec.c:1383
AV_CODEC_ID_SPEEX
@ AV_CODEC_ID_SPEEX
Definition: avcodec.h:599
FLVContext::last_ts
int64_t last_ts
Definition: flvdec.c:78
AMF_DATA_TYPE_STRING
@ AMF_DATA_TYPE_STRING
Definition: flv.h:126
AV_CODEC_ID_PCM_S16BE
@ AV_CODEC_ID_PCM_S16BE
Definition: avcodec.h:464
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:1237
read_seek
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
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: utils.c:2056
TYPE_ONTEXTDATA
#define TYPE_ONTEXTDATA
Definition: flvdec.c:703
flv_read_seek
static int flv_read_seek(AVFormatContext *s, int stream_index, int64_t ts, int flags)
Definition: flvdec.c:1375
read_close
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:557
ff_kux_demuxer
AVInputFormat ff_kux_demuxer
Definition: flvdec.c:1441
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:647
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: avcodec.h:565
AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_STEREO
Definition: channel_layout.h:86
FLV_TAG_TYPE_META
@ FLV_TAG_TYPE_META
Definition: flv.h:62
FLV_AUDIO_CODECID_MASK
#define FLV_AUDIO_CODECID_MASK
Definition: flv.h:42
VD
#define VD
Definition: flvdec.c:1384
AMF_DATA_TYPE_BOOL
@ AMF_DATA_TYPE_BOOL
Definition: flv.h:125
parse_keyframes_index
static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, int64_t max_pos)
Definition: flvdec.c:406
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:800
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:202
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
buf
void * buf
Definition: avisynth_c.h:766
AVInputFormat
Definition: avformat.h:640
VALIDATE_INDEX_TS_THRESH
#define VALIDATE_INDEX_TS_THRESH
Definition: flvdec.c:41
FLV_FRAME_DISP_INTER
@ FLV_FRAME_DISP_INTER
disposable inter frame (H.263 only)
Definition: flv.h:118
FLVContext::sum_flv_tag_size
int sum_flv_tag_size
Definition: flvdec.c:68
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:40
FLVContext::new_extradata_size
int new_extradata_size[FLV_STREAM_TYPE_NB]
Definition: flvdec.c:54
s
#define s(width, name)
Definition: cbs_vp9.c:257
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:645
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:448
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: avcodec.h:4023
FLV_CODECID_MPEG4
@ FLV_CODECID_MPEG4
Definition: flv.h:112
create_stream
static AVStream * create_stream(AVFormatContext *s, int codec_type)
Definition: flvdec.c:163
FLVContext::dts
int64_t dts
Definition: flvdec.c:58
FLV_VIDEO_FRAMETYPE_MASK
#define FLV_VIDEO_FRAMETYPE_MASK
Definition: flv.h:45
amf_skip_tag
static int amf_skip_tag(AVIOContext *pb, AMFDataType type, int depth)
Definition: flvdec.c:859
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
kux_class
static const AVClass kux_class
Definition: flvdec.c:1434
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
AVStream::need_parsing
enum AVStreamParseType need_parsing
Definition: avformat.h:1088
FLVContext::time_pos
int64_t time_pos
Definition: flvdec.c:80
AV_CODEC_ID_PCM_MULAW
@ AV_CODEC_ID_PCM_MULAW
Definition: avcodec.h:469
live_flv_probe
static int live_flv_probe(const AVProbeData *p)
Definition: flvdec.c:113
key
const char * key
Definition: hwcontext_opencl.c:168
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
fsize
static int64_t fsize(FILE *f)
Definition: audiomatch.c:28
AVDISCARD_BIDIR
@ AVDISCARD_BIDIR
discard all bidirectional frames
Definition: avcodec.h:808
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: avcodec.h:245
av_packet_new_side_data
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
Definition: avpacket.c:329
TYPE_UNKNOWN
#define TYPE_UNKNOWN
Definition: flvdec.c:706
flv_set_video_codec
static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_codecid, int read)
Definition: flvdec.c:329
version
int version
Definition: avisynth_c.h:858
int32_t
int32_t
Definition: audio_convert.c:194
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
time_internal.h
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: avcodec.h:811
AVFormatContext
Format I/O context.
Definition: avformat.h:1342
AV_CODEC_ID_PCM_ALAW
@ AV_CODEC_ID_PCM_ALAW
Definition: avcodec.h:470
flv_read_close
static int flv_read_close(AVFormatContext *s)
Definition: flvdec.c:804
AV_CODEC_ID_FLASHSV2
@ AV_CODEC_ID_FLASHSV2
Definition: avcodec.h:349
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1017
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:530
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
add_keyframes_index
static void add_keyframes_index(AVFormatContext *s)
Definition: flvdec.c:132
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
read_probe
static int read_probe(const AVProbeData *pd)
Definition: jvdec.c:55
avcodec_parameters_free
void avcodec_parameters_free(AVCodecParameters **par)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
Definition: utils.c:2069
AMF_DATA_TYPE_DATE
@ AMF_DATA_TYPE_DATE
Definition: flv.h:134
AVFMTCTX_NOHEADER
#define AVFMTCTX_NOHEADER
signal that no header is present (streams are added dynamically)
Definition: avformat.h:1291
FLV_CODECID_NELLYMOSER_8KHZ_MONO
@ FLV_CODECID_NELLYMOSER_8KHZ_MONO
Definition: flv.h:96
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:766
FLV_AUDIO_SAMPLERATE_MASK
#define FLV_AUDIO_SAMPLERATE_MASK
Definition: flv.h:41
isnan
#define isnan(x)
Definition: libm.h:340
FLVContext::validate_index
struct FLVContext::@258 validate_index[2]
flv_same_audio_codec
static int flv_same_audio_codec(AVCodecParameters *apar, int flags)
Definition: flvdec.c:193
FLV_STREAM_TYPE_SUBTITLE
@ FLV_STREAM_TYPE_SUBTITLE
Definition: flv.h:68
KEYFRAMES_TAG
#define KEYFRAMES_TAG
Definition: flv.h:49
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
avio_rb64
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:921
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:446
FLVContext::last_channels
int last_channels
Definition: flvdec.c:56
AV_CODEC_ID_FLASHSV
@ AV_CODEC_ID_FLASHSV
Definition: avcodec.h:304
FLVContext::keyframe_count
int keyframe_count
Definition: flvdec.c:71
AMF_DATA_TYPE_OBJECT_END
@ AMF_DATA_TYPE_OBJECT_END
Definition: flv.h:132
AV_CODEC_ID_VP6A
@ AV_CODEC_ID_VP6A
Definition: avcodec.h:324
FLV_VIDEO_CODECID_MASK
#define FLV_VIDEO_CODECID_MASK
Definition: flv.h:44
KEYFRAMES_BYTEOFFSET_TAG
#define KEYFRAMES_BYTEOFFSET_TAG
Definition: flv.h:51
AVPROBE_SCORE_EXTENSION
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition: avformat.h:456
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: avcodec.h:4067
FLVContext::missing_streams
int missing_streams
Definition: flvdec.c:76
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:215
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3975
AMFDataType
AMFDataType
Definition: flv.h:123
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: avcodec.h:566
FLV_TAG_TYPE_VIDEO
@ FLV_TAG_TYPE_VIDEO
Definition: flv.h:61
AMF_DATA_TYPE_MIXEDARRAY
@ AMF_DATA_TYPE_MIXEDARRAY
Definition: flv.h:131
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: avcodec.h:810
flv.h
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
live_flv_class
static const AVClass live_flv_class
Definition: flvdec.c:1413
avio_rb24
unsigned int avio_rb24(AVIOContext *s)
Definition: aviobuf.c:793
AVMediaType
AVMediaType
Definition: avutil.h:199
AVPacket::size
int size
Definition: avcodec.h:1478
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:188
AVIOContext::seekable
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:260
AVStream::nb_index_entries
int nb_index_entries
Definition: avformat.h:1101
FLV_STREAM_TYPE_AUDIO
@ FLV_STREAM_TYPE_AUDIO
Definition: flv.h:67
AMF_DATA_TYPE_OBJECT
@ AMF_DATA_TYPE_OBJECT
Definition: flv.h:127
localtime_r
#define localtime_r
Definition: time_internal.h:46
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4910
AV_CODEC_ID_H263
@ AV_CODEC_ID_H263
Definition: avcodec.h:222
AV_CODEC_ID_ADPCM_SWF
@ AV_CODEC_ID_ADPCM_SWF
Definition: avcodec.h:515
size
int size
Definition: twinvq_data.h:11134
FLVContext
Definition: flvdec.c:47
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
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:92
MAX_DEPTH
#define MAX_DEPTH
arbitrary limit to prevent unbounded recursion
Definition: flvdec.c:45
amf_date::timezone
int16_t timezone
Definition: flvdec.c:86
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: avcodec.h:1476
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:638
FLV_AUDIO_CODECID_OFFSET
#define FLV_AUDIO_CODECID_OFFSET
Definition: flv.h:34
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
flv_class
static const AVClass flv_class
Definition: flvdec.c:1393
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
FLV_AUDIO_SAMPLESIZE_MASK
#define FLV_AUDIO_SAMPLESIZE_MASK
Definition: flv.h:40
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1483
MPEG4AudioConfig::channels
int channels
Definition: mpeg4audio.h:43
AMF_DATA_TYPE_UNDEFINED
@ AMF_DATA_TYPE_UNDEFINED
Definition: flv.h:129
KEYFRAMES_TIMESTAMP_TAG
#define KEYFRAMES_TIMESTAMP_TAG
Definition: flv.h:50
kux_probe
static int kux_probe(const AVProbeData *p)
Definition: flvdec.c:118
avcodec_parameters_alloc
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: utils.c:2059
FLV_CODECID_PCM_LE
@ FLV_CODECID_PCM_LE
Definition: flv.h:94
FLV_CODECID_NELLYMOSER_16KHZ_MONO
@ FLV_CODECID_NELLYMOSER_16KHZ_MONO
Definition: flv.h:95
AMF_DATA_TYPE_ARRAY
@ AMF_DATA_TYPE_ARRAY
Definition: flv.h:133
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: avcodec.h:216
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1470
FLV_CODECID_PCM_MULAW
@ FLV_CODECID_PCM_MULAW
Definition: flv.h:99
avio_internal.h
FLVContext::last_keyframe_stream_index
int last_keyframe_stream_index
Definition: flvdec.c:70
flv_read_metabody
static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
Definition: flvdec.c:708
AVCodecParameters::height
int height
Definition: avcodec.h:4024
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
resync
static int resync(AVFormatContext *s)
Definition: flvdec.c:975
FLVContext::framerate
AVRational framerate
Definition: flvdec.c:77
flv_probe
static int flv_probe(const AVProbeData *p)
Definition: flvdec.c:108
av_d2q
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
Definition: rational.c:106
uint8_t
uint8_t
Definition: audio_convert.c:194
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
FLV_CODECID_REALH263
@ FLV_CODECID_REALH263
Definition: flv.h:111
FLV_STEREO
@ FLV_STEREO
Definition: flv.h:75
FLVContext::wrong_dts
int wrong_dts
wrong dts due to negative cts
Definition: flvdec.c:52
FLV_CODECID_VP6
@ FLV_CODECID_VP6
Definition: flv.h:107
MPEG4AudioConfig::ext_sample_rate
int ext_sample_rate
Definition: mpeg4audio.h:41
FLV_AUDIO_CHANNEL_MASK
#define FLV_AUDIO_CHANNEL_MASK
Definition: flv.h:39
FLV_HEADER_FLAG_HASAUDIO
@ FLV_HEADER_FLAG_HASAUDIO
Definition: flv.h:56
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: utils.c:5042
flv_queue_extradata
static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream, int size)
Definition: flvdec.c:827
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:313
FLVContext::new_extradata
uint8_t * new_extradata[FLV_STREAM_TYPE_NB]
Definition: flvdec.c:53
av_uninit
#define av_uninit(x)
Definition: attributes.h:148
array
static int array[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:106
ret
ret
Definition: filter_design.txt:187
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVStream
Stream structure.
Definition: avformat.h:870
probe
static int probe(const AVProbeData *p, int live)
Definition: flvdec.c:89
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:246
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:72
ff_live_flv_demuxer
AVInputFormat ff_live_flv_demuxer
Definition: flvdec.c:1420
avio_rb16
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:785
FLV_CODECID_PCM_ALAW
@ FLV_CODECID_PCM_ALAW
Definition: flv.h:98
AVSTREAM_PARSE_HEADERS
@ AVSTREAM_PARSE_HEADERS
Only parse headers, do not repack.
Definition: avformat.h:792
avformat.h
dict.h
AV_CODEC_ID_TEXT
@ AV_CODEC_ID_TEXT
raw UTF-8 text
Definition: avcodec.h:660
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: avcodec.h:790
amf_get_string
static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize)
Definition: flvdec.c:386
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:871
FLV_CODECID_VP6A
@ FLV_CODECID_VP6A
Definition: flv.h:108
FLV_TAG_TYPE_AUDIO
@ FLV_TAG_TYPE_AUDIO
Definition: flv.h:60
channel_layout.h
ff_flv_demuxer
AVInputFormat ff_flv_demuxer
Definition: flvdec.c:1400
FLV_CODECID_AAC
@ FLV_CODECID_AAC
Definition: flv.h:100
AV_OPT_FLAG_EXPORT
#define AV_OPT_FLAG_EXPORT
The option is intended for exporting values to the caller.
Definition: opt.h:284
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
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
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: avcodec.h:1199
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
FLV_HEADER_FLAG_HASVIDEO
@ FLV_HEADER_FLAG_HASVIDEO
Definition: flv.h:55
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:647
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:498
AMF_DATA_TYPE_NUMBER
@ AMF_DATA_TYPE_NUMBER
Definition: flv.h:124
AVIndexEntry::pos
int64_t pos
Definition: avformat.h:801
AVIOContext::eof_reached
int eof_reached
true if was unable to read due to error or eof
Definition: avio.h:239
AVPacket::stream_index
int stream_index
Definition: avcodec.h:1479
FLV_CODECID_SCREEN2
@ FLV_CODECID_SCREEN2
Definition: flv.h:109
FLV_FRAME_KEY
@ FLV_FRAME_KEY
key frame (for AVC, a seekable frame)
Definition: flv.h:116
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:331
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: avcodec.h:3999
AVFMT_TS_DISCONT
#define AVFMT_TS_DISCONT
Format allows timestamp discontinuities.
Definition: avformat.h:469
AVStreamInternal::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:192
AV_CODEC_ID_PCM_U8
@ AV_CODEC_ID_PCM_U8
Definition: avcodec.h:468
FLV_CODECID_SPEEX
@ FLV_CODECID_SPEEX
Definition: flv.h:101
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:39
flv_get_extradata
static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size)
Definition: flvdec.c:815
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:81
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3957
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1454
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:240
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:70
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1497
FlvTagType
FlvTagType
Definition: flv.h:59
AVCodecParameters::channel_layout
uint64_t channel_layout
Audio only.
Definition: avcodec.h:4059
bytestream.h
AVSTREAM_PARSE_FULL
@ AVSTREAM_PARSE_FULL
full parsing and repack
Definition: avformat.h:791
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
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:83
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:3986
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AMF_DATA_TYPE_NULL
@ AMF_DATA_TYPE_NULL
Definition: flv.h:128
FLVContext::validate_count
int validate_count
Definition: flvdec.c:62
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
length
const char int length
Definition: avisynth_c.h:860
AVDictionaryEntry::value
char * value
Definition: dict.h:83
avstring.h
avpriv_mpeg4audio_get_config
int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int bit_size, int sync_extension)
Parse MPEG-4 systems extradata from a raw buffer to retrieve audio configuration.
Definition: mpeg4audio.c:159
AV_CODEC_ID_FLV1
@ AV_CODEC_ID_FLV1
Definition: avcodec.h:239
amf_date::milliseconds
double milliseconds
Definition: flvdec.c:85
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:93
int
int
Definition: ffmpeg_filter.c:191
snprintf
#define snprintf
Definition: snprintf.h:34
FLVContext::dump_full_metadata
int dump_full_metadata
Dump full metadata of the onMetadata.
Definition: flvdec.c:51
FLVContext::last_sample_rate
int last_sample_rate
Definition: flvdec.c:55
AVFMT_EVENT_FLAG_METADATA_UPDATED
#define AVFMT_EVENT_FLAG_METADATA_UPDATED
The call resulted in updated metadata.
Definition: avformat.h:1658
FLV_CODECID_ADPCM
@ FLV_CODECID_ADPCM
Definition: flv.h:92
RESYNC_BUFFER_SIZE
#define RESYNC_BUFFER_SIZE
Definition: flvdec.c:43
AV_CODEC_ID_NELLYMOSER
@ AV_CODEC_ID_NELLYMOSER
Definition: avcodec.h:597
FLVContext::broken_sizes
int broken_sizes
Definition: flvdec.c:67
MPEG4AudioConfig::sample_rate
int sample_rate
Definition: mpeg4audio.h:36
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:3309
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:358