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