3 * Copyright (c) 2003 The FFmpeg Project
5 * This demuxer will generate a 1 byte extradata for VP6F content.
7 * - upper 4 bits: difference between encoded width and visible width
8 * - lower 4 bits: difference between encoded height and visible height
10 * This file is part of FFmpeg.
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.
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.
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
27 #include "libavutil/avstring.h"
28 #include "libavutil/channel_layout.h"
29 #include "libavutil/dict.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/intfloat.h"
32 #include "libavutil/mathematics.h"
33 #include "libavutil/time_internal.h"
34 #include "libavcodec/bytestream.h"
35 #include "libavcodec/mpeg4audio.h"
38 #include "avio_internal.h"
41 #define VALIDATE_INDEX_TS_THRESH 2500
43 #define RESYNC_BUFFER_SIZE (1<<20)
45 typedef struct FLVContext {
46 const AVClass *class; ///< Class for private options.
47 int trust_metadata; ///< configure streams according onMetaData
48 int trust_datasize; ///< trust data size of FLVTag
49 int dump_full_metadata; ///< Dump full metadata of the onMetadata
50 int wrong_dts; ///< wrong dts due to negative cts
51 uint8_t *new_extradata[FLV_STREAM_TYPE_NB];
52 int new_extradata_size[FLV_STREAM_TYPE_NB];
63 uint8_t resync_buffer[2*RESYNC_BUFFER_SIZE];
68 int last_keyframe_stream_index;
70 int64_t video_bit_rate;
71 int64_t audio_bit_rate;
72 int64_t *keyframe_times;
73 int64_t *keyframe_filepositions;
82 typedef struct amf_date {
87 static int probe(const AVProbeData *p, int live)
89 const uint8_t *d = p->buf;
90 unsigned offset = AV_RB32(d + 5);
95 d[3] < 5 && d[5] == 0 &&
96 offset + 100 < p->buf_size &&
98 int is_live = !memcmp(d + offset + 40, "NGINX RTMP", 10);
101 return AVPROBE_SCORE_MAX;
106 static int flv_probe(const AVProbeData *p)
111 static int live_flv_probe(const AVProbeData *p)
116 static int kux_probe(const AVProbeData *p)
118 const uint8_t *d = p->buf;
125 return AVPROBE_SCORE_EXTENSION + 1;
130 static void add_keyframes_index(AVFormatContext *s)
132 FLVContext *flv = s->priv_data;
133 AVStream *stream = NULL;
136 if (flv->last_keyframe_stream_index < 0) {
137 av_log(s, AV_LOG_DEBUG, "keyframe stream hasn't been created\n");
141 av_assert0(flv->last_keyframe_stream_index <= s->nb_streams);
142 stream = s->streams[flv->last_keyframe_stream_index];
144 if (stream->nb_index_entries == 0) {
145 for (i = 0; i < flv->keyframe_count; i++) {
146 av_log(s, AV_LOG_TRACE, "keyframe filepositions = %"PRId64" times = %"PRId64"\n",
147 flv->keyframe_filepositions[i], flv->keyframe_times[i] * 1000);
148 av_add_index_entry(stream, flv->keyframe_filepositions[i],
149 flv->keyframe_times[i] * 1000, 0, 0, AVINDEX_KEYFRAME);
152 av_log(s, AV_LOG_WARNING, "Skipping duplicate index\n");
154 if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
155 av_freep(&flv->keyframe_times);
156 av_freep(&flv->keyframe_filepositions);
157 flv->keyframe_count = 0;
161 static AVStream *create_stream(AVFormatContext *s, int codec_type)
163 FLVContext *flv = s->priv_data;
164 AVStream *st = avformat_new_stream(s, NULL);
167 st->codecpar->codec_type = codec_type;
168 if (s->nb_streams>=3 ||( s->nb_streams==2
169 && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE
170 && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE
171 && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_DATA
172 && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_DATA))
173 s->ctx_flags &= ~AVFMTCTX_NOHEADER;
174 if (codec_type == AVMEDIA_TYPE_AUDIO) {
175 st->codecpar->bit_rate = flv->audio_bit_rate;
176 flv->missing_streams &= ~FLV_HEADER_FLAG_HASAUDIO;
178 if (codec_type == AVMEDIA_TYPE_VIDEO) {
179 st->codecpar->bit_rate = flv->video_bit_rate;
180 flv->missing_streams &= ~FLV_HEADER_FLAG_HASVIDEO;
181 st->avg_frame_rate = flv->framerate;
185 avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
186 flv->last_keyframe_stream_index = s->nb_streams - 1;
187 add_keyframes_index(s);
191 static int flv_same_audio_codec(AVCodecParameters *apar, int flags)
193 int bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
194 int flv_codecid = flags & FLV_AUDIO_CODECID_MASK;
197 if (!apar->codec_id && !apar->codec_tag)
200 if (apar->bits_per_coded_sample != bits_per_coded_sample)
203 switch (flv_codecid) {
204 // no distinction between S16 and S8 PCM codec flags
205 case FLV_CODECID_PCM:
206 codec_id = bits_per_coded_sample == 8
209 : AV_CODEC_ID_PCM_S16BE;
211 : AV_CODEC_ID_PCM_S16LE;
213 return codec_id == apar->codec_id;
214 case FLV_CODECID_PCM_LE:
215 codec_id = bits_per_coded_sample == 8
217 : AV_CODEC_ID_PCM_S16LE;
218 return codec_id == apar->codec_id;
219 case FLV_CODECID_AAC:
220 return apar->codec_id == AV_CODEC_ID_AAC;
221 case FLV_CODECID_ADPCM:
222 return apar->codec_id == AV_CODEC_ID_ADPCM_SWF;
223 case FLV_CODECID_SPEEX:
224 return apar->codec_id == AV_CODEC_ID_SPEEX;
225 case FLV_CODECID_MP3:
226 return apar->codec_id == AV_CODEC_ID_MP3;
227 case FLV_CODECID_NELLYMOSER_8KHZ_MONO:
228 case FLV_CODECID_NELLYMOSER_16KHZ_MONO:
229 case FLV_CODECID_NELLYMOSER:
230 return apar->codec_id == AV_CODEC_ID_NELLYMOSER;
231 case FLV_CODECID_PCM_MULAW:
232 return apar->sample_rate == 8000 &&
233 apar->codec_id == AV_CODEC_ID_PCM_MULAW;
234 case FLV_CODECID_PCM_ALAW:
235 return apar->sample_rate == 8000 &&
236 apar->codec_id == AV_CODEC_ID_PCM_ALAW;
238 return apar->codec_tag == (flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
242 static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream,
243 AVCodecParameters *apar, int flv_codecid)
245 switch (flv_codecid) {
246 // no distinction between S16 and S8 PCM codec flags
247 case FLV_CODECID_PCM:
248 apar->codec_id = apar->bits_per_coded_sample == 8
251 : AV_CODEC_ID_PCM_S16BE;
253 : AV_CODEC_ID_PCM_S16LE;
256 case FLV_CODECID_PCM_LE:
257 apar->codec_id = apar->bits_per_coded_sample == 8
259 : AV_CODEC_ID_PCM_S16LE;
261 case FLV_CODECID_AAC:
262 apar->codec_id = AV_CODEC_ID_AAC;
264 case FLV_CODECID_ADPCM:
265 apar->codec_id = AV_CODEC_ID_ADPCM_SWF;
267 case FLV_CODECID_SPEEX:
268 apar->codec_id = AV_CODEC_ID_SPEEX;
269 apar->sample_rate = 16000;
271 case FLV_CODECID_MP3:
272 apar->codec_id = AV_CODEC_ID_MP3;
273 astream->need_parsing = AVSTREAM_PARSE_FULL;
275 case FLV_CODECID_NELLYMOSER_8KHZ_MONO:
276 // in case metadata does not otherwise declare samplerate
277 apar->sample_rate = 8000;
278 apar->codec_id = AV_CODEC_ID_NELLYMOSER;
280 case FLV_CODECID_NELLYMOSER_16KHZ_MONO:
281 apar->sample_rate = 16000;
282 apar->codec_id = AV_CODEC_ID_NELLYMOSER;
284 case FLV_CODECID_NELLYMOSER:
285 apar->codec_id = AV_CODEC_ID_NELLYMOSER;
287 case FLV_CODECID_PCM_MULAW:
288 apar->sample_rate = 8000;
289 apar->codec_id = AV_CODEC_ID_PCM_MULAW;
291 case FLV_CODECID_PCM_ALAW:
292 apar->sample_rate = 8000;
293 apar->codec_id = AV_CODEC_ID_PCM_ALAW;
296 avpriv_request_sample(s, "Audio codec (%x)",
297 flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
298 apar->codec_tag = flv_codecid >> FLV_AUDIO_CODECID_OFFSET;
302 static int flv_same_video_codec(AVCodecParameters *vpar, int flags)
304 int flv_codecid = flags & FLV_VIDEO_CODECID_MASK;
306 if (!vpar->codec_id && !vpar->codec_tag)
309 switch (flv_codecid) {
310 case FLV_CODECID_H263:
311 return vpar->codec_id == AV_CODEC_ID_FLV1;
312 case FLV_CODECID_SCREEN:
313 return vpar->codec_id == AV_CODEC_ID_FLASHSV;
314 case FLV_CODECID_SCREEN2:
315 return vpar->codec_id == AV_CODEC_ID_FLASHSV2;
316 case FLV_CODECID_VP6:
317 return vpar->codec_id == AV_CODEC_ID_VP6F;
318 case FLV_CODECID_VP6A:
319 return vpar->codec_id == AV_CODEC_ID_VP6A;
320 case FLV_CODECID_H264:
321 return vpar->codec_id == AV_CODEC_ID_H264;
323 return vpar->codec_tag == flv_codecid;
327 static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream,
328 int flv_codecid, int read)
331 AVCodecParameters *par = vstream->codecpar;
332 enum AVCodecID old_codec_id = vstream->codecpar->codec_id;
333 switch (flv_codecid) {
334 case FLV_CODECID_H263:
335 par->codec_id = AV_CODEC_ID_FLV1;
337 case FLV_CODECID_REALH263:
338 par->codec_id = AV_CODEC_ID_H263;
339 break; // Really mean it this time
340 case FLV_CODECID_SCREEN:
341 par->codec_id = AV_CODEC_ID_FLASHSV;
343 case FLV_CODECID_SCREEN2:
344 par->codec_id = AV_CODEC_ID_FLASHSV2;
346 case FLV_CODECID_VP6:
347 par->codec_id = AV_CODEC_ID_VP6F;
348 case FLV_CODECID_VP6A:
349 if (flv_codecid == FLV_CODECID_VP6A)
350 par->codec_id = AV_CODEC_ID_VP6A;
352 if (par->extradata_size != 1) {
353 ff_alloc_extradata(par, 1);
356 par->extradata[0] = avio_r8(s->pb);
360 ret = 1; // 1 byte body size adjustment for flv_read_packet()
362 case FLV_CODECID_H264:
363 par->codec_id = AV_CODEC_ID_H264;
364 vstream->need_parsing = AVSTREAM_PARSE_HEADERS;
365 ret = 3; // not 4, reading packet type will consume one byte
367 case FLV_CODECID_MPEG4:
368 par->codec_id = AV_CODEC_ID_MPEG4;
372 avpriv_request_sample(s, "Video codec (%x)", flv_codecid);
373 par->codec_tag = flv_codecid;
376 if (!vstream->internal->need_context_update && par->codec_id != old_codec_id) {
377 avpriv_request_sample(s, "Changing the codec id midstream");
378 return AVERROR_PATCHWELCOME;
384 static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize)
386 int length = avio_rb16(ioc);
387 if (length >= buffsize) {
388 avio_skip(ioc, length);
392 avio_read(ioc, buffer, length);
394 buffer[length] = '\0';
399 static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, int64_t max_pos)
401 FLVContext *flv = s->priv_data;
402 unsigned int timeslen = 0, fileposlen = 0, i;
404 int64_t *times = NULL;
405 int64_t *filepositions = NULL;
406 int ret = AVERROR(ENOSYS);
407 int64_t initial_pos = avio_tell(ioc);
409 if (flv->keyframe_count > 0) {
410 av_log(s, AV_LOG_DEBUG, "keyframes have been parsed\n");
413 av_assert0(!flv->keyframe_times);
414 av_assert0(!flv->keyframe_filepositions);
416 if (s->flags & AVFMT_FLAG_IGNIDX)
419 while (avio_tell(ioc) < max_pos - 2 &&
420 amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
421 int64_t **current_array;
422 unsigned int arraylen;
424 // Expect array object in context
425 if (avio_r8(ioc) != AMF_DATA_TYPE_ARRAY)
428 arraylen = avio_rb32(ioc);
432 if (!strcmp(KEYFRAMES_TIMESTAMP_TAG , str_val) && !times) {
433 current_array = ×
435 } else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) &&
437 current_array = &filepositions;
438 fileposlen = arraylen;
440 // unexpected metatag inside keyframes, will not use such
441 // metadata for indexing
444 if (!(*current_array = av_mallocz(sizeof(**current_array) * arraylen))) {
445 ret = AVERROR(ENOMEM);
449 for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) {
450 if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER)
452 current_array[0][i] = av_int2double(avio_rb64(ioc));
454 if (times && filepositions) {
455 // All done, exiting at a position allowing amf_parse_object
456 // to finish parsing the object
462 if (timeslen == fileposlen && fileposlen>1 && max_pos <= filepositions[0]) {
463 for (i = 0; i < FFMIN(2,fileposlen); i++) {
464 flv->validate_index[i].pos = filepositions[i];
465 flv->validate_index[i].dts = times[i] * 1000;
466 flv->validate_count = i + 1;
468 flv->keyframe_times = times;
469 flv->keyframe_filepositions = filepositions;
470 flv->keyframe_count = timeslen;
472 filepositions = NULL;
475 av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n");
480 av_freep(&filepositions);
481 avio_seek(ioc, initial_pos, SEEK_SET);
485 static int amf_parse_object(AVFormatContext *s, AVStream *astream,
486 AVStream *vstream, const char *key,
487 int64_t max_pos, int depth)
489 AVCodecParameters *apar, *vpar;
490 FLVContext *flv = s->priv_data;
492 AMFDataType amf_type;
499 amf_type = avio_r8(ioc);
502 case AMF_DATA_TYPE_NUMBER:
503 num_val = av_int2double(avio_rb64(ioc));
505 case AMF_DATA_TYPE_BOOL:
506 num_val = avio_r8(ioc);
508 case AMF_DATA_TYPE_STRING:
509 if (amf_get_string(ioc, str_val, sizeof(str_val)) < 0) {
510 av_log(s, AV_LOG_ERROR, "AMF_DATA_TYPE_STRING parsing failed\n");
514 case AMF_DATA_TYPE_OBJECT:
516 (ioc->seekable & AVIO_SEEKABLE_NORMAL) &&
517 !strcmp(KEYFRAMES_TAG, key) && depth == 1)
518 if (parse_keyframes_index(s, ioc,
520 av_log(s, AV_LOG_ERROR, "Keyframe index parsing failed\n");
522 add_keyframes_index(s);
523 while (avio_tell(ioc) < max_pos - 2 &&
524 amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
525 if (amf_parse_object(s, astream, vstream, str_val, max_pos,
527 return -1; // if we couldn't skip, bomb out.
528 if (avio_r8(ioc) != AMF_END_OF_OBJECT) {
529 av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_OBJECT\n");
533 case AMF_DATA_TYPE_NULL:
534 case AMF_DATA_TYPE_UNDEFINED:
535 case AMF_DATA_TYPE_UNSUPPORTED:
536 break; // these take up no additional space
537 case AMF_DATA_TYPE_MIXEDARRAY:
540 avio_skip(ioc, 4); // skip 32-bit max array index
541 while (avio_tell(ioc) < max_pos - 2 &&
542 amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
543 // this is the only case in which we would want a nested
544 // parse to not skip over the object
545 if (amf_parse_object(s, astream, vstream, str_val, max_pos,
549 if (v != AMF_END_OF_OBJECT) {
550 av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_MIXEDARRAY, found %d\n", v);
555 case AMF_DATA_TYPE_ARRAY:
557 unsigned int arraylen, i;
559 arraylen = avio_rb32(ioc);
560 for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++)
561 if (amf_parse_object(s, NULL, NULL, NULL, max_pos,
563 return -1; // if we couldn't skip, bomb out.
566 case AMF_DATA_TYPE_DATE:
567 // timestamp (double) and UTC offset (int16)
568 date.milliseconds = av_int2double(avio_rb64(ioc));
569 date.timezone = avio_rb16(ioc);
571 default: // unsupported type, we couldn't skip
572 av_log(s, AV_LOG_ERROR, "unsupported amf type %d\n", amf_type);
577 apar = astream ? astream->codecpar : NULL;
578 vpar = vstream ? vstream->codecpar : NULL;
580 // stream info doesn't live any deeper than the first object
582 if (amf_type == AMF_DATA_TYPE_NUMBER ||
583 amf_type == AMF_DATA_TYPE_BOOL) {
584 if (!strcmp(key, "duration"))
585 s->duration = num_val * AV_TIME_BASE;
586 else if (!strcmp(key, "videodatarate") &&
587 0 <= (int)(num_val * 1024.0))
588 flv->video_bit_rate = num_val * 1024.0;
589 else if (!strcmp(key, "audiodatarate") &&
590 0 <= (int)(num_val * 1024.0))
591 flv->audio_bit_rate = num_val * 1024.0;
592 else if (!strcmp(key, "datastream")) {
593 AVStream *st = create_stream(s, AVMEDIA_TYPE_SUBTITLE);
595 return AVERROR(ENOMEM);
596 st->codecpar->codec_id = AV_CODEC_ID_TEXT;
597 } else if (!strcmp(key, "framerate")) {
598 flv->framerate = av_d2q(num_val, 1000);
600 vstream->avg_frame_rate = flv->framerate;
601 } else if (flv->trust_metadata) {
602 if (!strcmp(key, "videocodecid") && vpar) {
603 int ret = flv_set_video_codec(s, vstream, num_val, 0);
606 } else if (!strcmp(key, "audiocodecid") && apar) {
607 int id = ((int)num_val) << FLV_AUDIO_CODECID_OFFSET;
608 flv_set_audio_codec(s, astream, apar, id);
609 } else if (!strcmp(key, "audiosamplerate") && apar) {
610 apar->sample_rate = num_val;
611 } else if (!strcmp(key, "audiosamplesize") && apar) {
612 apar->bits_per_coded_sample = num_val;
613 } else if (!strcmp(key, "stereo") && apar) {
614 apar->channels = num_val + 1;
615 apar->channel_layout = apar->channels == 2 ?
616 AV_CH_LAYOUT_STEREO :
618 } else if (!strcmp(key, "width") && vpar) {
619 vpar->width = num_val;
620 } else if (!strcmp(key, "height") && vpar) {
621 vpar->height = num_val;
625 if (amf_type == AMF_DATA_TYPE_STRING) {
626 if (!strcmp(key, "encoder")) {
628 if (1 == sscanf(str_val, "Open Broadcaster Software v0.%d", &version)) {
629 if (version > 0 && version <= 655)
630 flv->broken_sizes = 1;
632 } else if (!strcmp(key, "metadatacreator")) {
633 if ( !strcmp (str_val, "MEGA")
634 || !strncmp(str_val, "FlixEngine", 10))
635 flv->broken_sizes = 1;
640 if (amf_type == AMF_DATA_TYPE_OBJECT && s->nb_streams == 1 &&
641 ((!apar && !strcmp(key, "audiocodecid")) ||
642 (!vpar && !strcmp(key, "videocodecid"))))
643 s->ctx_flags &= ~AVFMTCTX_NOHEADER; //If there is either audio/video missing, codecid will be an empty object
645 if ((!strcmp(key, "duration") ||
646 !strcmp(key, "filesize") ||
647 !strcmp(key, "width") ||
648 !strcmp(key, "height") ||
649 !strcmp(key, "videodatarate") ||
650 !strcmp(key, "framerate") ||
651 !strcmp(key, "videocodecid") ||
652 !strcmp(key, "audiodatarate") ||
653 !strcmp(key, "audiosamplerate") ||
654 !strcmp(key, "audiosamplesize") ||
655 !strcmp(key, "stereo") ||
656 !strcmp(key, "audiocodecid") ||
657 !strcmp(key, "datastream")) && !flv->dump_full_metadata)
660 s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
661 if (amf_type == AMF_DATA_TYPE_BOOL) {
662 av_strlcpy(str_val, num_val > 0 ? "true" : "false",
664 av_dict_set(&s->metadata, key, str_val, 0);
665 } else if (amf_type == AMF_DATA_TYPE_NUMBER) {
666 snprintf(str_val, sizeof(str_val), "%.f", num_val);
667 av_dict_set(&s->metadata, key, str_val, 0);
668 } else if (amf_type == AMF_DATA_TYPE_STRING) {
669 av_dict_set(&s->metadata, key, str_val, 0);
670 } else if (amf_type == AMF_DATA_TYPE_DATE) {
674 time = date.milliseconds / 1000; // to seconds
675 localtime_r(&time, &t);
676 strftime(datestr, sizeof(datestr), "%a, %d %b %Y %H:%M:%S %z", &t);
678 av_dict_set(&s->metadata, key, datestr, 0);
685 #define TYPE_ONTEXTDATA 1
686 #define TYPE_ONCAPTION 2
687 #define TYPE_ONCAPTIONINFO 3
688 #define TYPE_UNKNOWN 9
690 static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
692 FLVContext *flv = s->priv_data;
694 AVStream *stream, *astream, *vstream;
695 AVStream av_unused *dstream;
705 // first object needs to be "onMetaData" string
707 if (type != AMF_DATA_TYPE_STRING ||
708 amf_get_string(ioc, buffer, sizeof(buffer)) < 0)
711 if (!strcmp(buffer, "onTextData"))
712 return TYPE_ONTEXTDATA;
714 if (!strcmp(buffer, "onCaption"))
715 return TYPE_ONCAPTION;
717 if (!strcmp(buffer, "onCaptionInfo"))
718 return TYPE_ONCAPTIONINFO;
720 if (strcmp(buffer, "onMetaData") && strcmp(buffer, "onCuePoint")) {
721 av_log(s, AV_LOG_DEBUG, "Unknown type %s\n", buffer);
725 // find the streams now so that amf_parse_object doesn't need to do
726 // the lookup every time it is called.
727 for (i = 0; i < s->nb_streams; i++) {
728 stream = s->streams[i];
729 if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
731 flv->last_keyframe_stream_index = i;
732 } else if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
734 if (flv->last_keyframe_stream_index == -1)
735 flv->last_keyframe_stream_index = i;
737 else if (stream->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
741 // parse the second object (we want a mixed array)
742 if (amf_parse_object(s, astream, vstream, buffer, next_pos, 0) < 0)
748 static int flv_read_header(AVFormatContext *s)
751 FLVContext *flv = s->priv_data;
753 int pre_tag_size = 0;
755 /* Actual FLV data at 0xe40000 in KUX file */
756 if(!strcmp(s->iformat->name, "kux"))
757 avio_skip(s->pb, 0xe40000);
760 flags = avio_r8(s->pb);
762 flv->missing_streams = flags & (FLV_HEADER_FLAG_HASVIDEO | FLV_HEADER_FLAG_HASAUDIO);
764 s->ctx_flags |= AVFMTCTX_NOHEADER;
766 offset = avio_rb32(s->pb);
767 avio_seek(s->pb, offset, SEEK_SET);
769 /* Annex E. The FLV File Format
772 * PreviousTagSize0 UI32 Always 0
774 pre_tag_size = avio_rb32(s->pb);
776 av_log(s, AV_LOG_WARNING, "Read FLV header error, input file is not a standard flv format, first PreviousTagSize0 always is 0\n");
780 flv->sum_flv_tag_size = 0;
781 flv->last_keyframe_stream_index = -1;
786 static int flv_read_close(AVFormatContext *s)
789 FLVContext *flv = s->priv_data;
790 for (i=0; i<FLV_STREAM_TYPE_NB; i++)
791 av_freep(&flv->new_extradata[i]);
792 av_freep(&flv->keyframe_times);
793 av_freep(&flv->keyframe_filepositions);
797 static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size)
802 av_freep(&st->codecpar->extradata);
803 if (ff_get_extradata(s, st->codecpar, s->pb, size) < 0)
804 return AVERROR(ENOMEM);
805 st->internal->need_context_update = 1;
809 static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream,
815 av_free(flv->new_extradata[stream]);
816 flv->new_extradata[stream] = av_mallocz(size +
817 AV_INPUT_BUFFER_PADDING_SIZE);
818 if (!flv->new_extradata[stream])
819 return AVERROR(ENOMEM);
820 flv->new_extradata_size[stream] = size;
821 avio_read(pb, flv->new_extradata[stream], size);
825 static void clear_index_entries(AVFormatContext *s, int64_t pos)
828 av_log(s, AV_LOG_WARNING,
829 "Found invalid index entries, clearing the index.\n");
830 for (i = 0; i < s->nb_streams; i++) {
831 AVStream *st = s->streams[i];
832 /* Remove all index entries that point to >= pos */
834 for (j = 0; j < st->nb_index_entries; j++)
835 if (st->index_entries[j].pos < pos)
836 st->index_entries[out++] = st->index_entries[j];
837 st->nb_index_entries = out;
841 static int amf_skip_tag(AVIOContext *pb, AMFDataType type)
843 int nb = -1, ret, parse_name = 1;
846 case AMF_DATA_TYPE_NUMBER:
849 case AMF_DATA_TYPE_BOOL:
852 case AMF_DATA_TYPE_STRING:
853 avio_skip(pb, avio_rb16(pb));
855 case AMF_DATA_TYPE_ARRAY:
857 case AMF_DATA_TYPE_MIXEDARRAY:
859 case AMF_DATA_TYPE_OBJECT:
860 while(!pb->eof_reached && (nb-- > 0 || type != AMF_DATA_TYPE_ARRAY)) {
862 int size = avio_rb16(pb);
869 if ((ret = amf_skip_tag(pb, avio_r8(pb))) < 0)
873 case AMF_DATA_TYPE_NULL:
874 case AMF_DATA_TYPE_OBJECT_END:
877 return AVERROR_INVALIDDATA;
882 static int flv_data_packet(AVFormatContext *s, AVPacket *pkt,
883 int64_t dts, int64_t next)
885 AVIOContext *pb = s->pb;
888 int ret = AVERROR_INVALIDDATA;
892 switch (avio_r8(pb)) {
893 case AMF_DATA_TYPE_ARRAY:
895 case AMF_DATA_TYPE_MIXEDARRAY:
896 avio_seek(pb, 4, SEEK_CUR);
897 case AMF_DATA_TYPE_OBJECT:
903 while (array || (ret = amf_get_string(pb, buf, sizeof(buf))) > 0) {
904 AMFDataType type = avio_r8(pb);
905 if (type == AMF_DATA_TYPE_STRING && (array || !strcmp(buf, "text"))) {
906 length = avio_rb16(pb);
907 ret = av_get_packet(pb, pkt, length);
913 if ((ret = amf_skip_tag(pb, type)) < 0)
919 ret = AVERROR_INVALIDDATA;
923 for (i = 0; i < s->nb_streams; i++) {
925 if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
929 if (i == s->nb_streams) {
930 st = create_stream(s, AVMEDIA_TYPE_SUBTITLE);
932 return AVERROR(ENOMEM);
933 st->codecpar->codec_id = AV_CODEC_ID_TEXT;
940 pkt->stream_index = st->index;
941 pkt->flags |= AV_PKT_FLAG_KEY;
944 avio_seek(s->pb, next + 4, SEEK_SET);
949 static int resync(AVFormatContext *s)
951 FLVContext *flv = s->priv_data;
953 int64_t pos = avio_tell(s->pb);
955 for (i=0; !avio_feof(s->pb); i++) {
956 int j = i & (RESYNC_BUFFER_SIZE-1);
957 int j1 = j + RESYNC_BUFFER_SIZE;
958 flv->resync_buffer[j ] =
959 flv->resync_buffer[j1] = avio_r8(s->pb);
962 uint8_t *d = flv->resync_buffer + j1 - 8;
966 d[3] < 5 && d[5] == 0) {
967 av_log(s, AV_LOG_WARNING, "Concatenated FLV detected, might fail to demux, decode and seek %"PRId64"\n", flv->last_ts);
968 flv->time_offset = flv->last_ts + 1;
969 flv->time_pos = avio_tell(s->pb);
974 unsigned lsize2 = AV_RB32(flv->resync_buffer + j1 - 4);
975 if (lsize2 >= 11 && lsize2 + 8LL < FFMIN(i, RESYNC_BUFFER_SIZE)) {
976 unsigned size2 = AV_RB24(flv->resync_buffer + j1 - lsize2 + 1 - 4);
977 unsigned lsize1 = AV_RB32(flv->resync_buffer + j1 - lsize2 - 8);
978 if (lsize1 >= 11 && lsize1 + 8LL + lsize2 < FFMIN(i, RESYNC_BUFFER_SIZE)) {
979 unsigned size1 = AV_RB24(flv->resync_buffer + j1 - lsize1 + 1 - lsize2 - 8);
980 if (size1 == lsize1 - 11 && size2 == lsize2 - 11) {
981 avio_seek(s->pb, pos + i - lsize1 - lsize2 - 8, SEEK_SET);
991 static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
993 FLVContext *flv = s->priv_data;
994 int ret, i, size, flags;
995 enum FlvTagType type;
997 int64_t next, pos, meta_pos;
998 int64_t dts, pts = AV_NOPTS_VALUE;
999 int av_uninit(channels);
1000 int av_uninit(sample_rate);
1001 AVStream *st = NULL;
1006 /* pkt size is repeated at end. skip it */
1007 pos = avio_tell(s->pb);
1008 type = (avio_r8(s->pb) & 0x1F);
1010 size = avio_rb24(s->pb);
1011 flv->sum_flv_tag_size += size + 11;
1012 dts = avio_rb24(s->pb);
1013 dts |= (unsigned)avio_r8(s->pb) << 24;
1014 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));
1015 if (avio_feof(s->pb))
1017 avio_skip(s->pb, 3); /* stream id, always 0 */
1020 if (flv->validate_next < flv->validate_count) {
1021 int64_t validate_pos = flv->validate_index[flv->validate_next].pos;
1022 if (pos == validate_pos) {
1023 if (FFABS(dts - flv->validate_index[flv->validate_next].dts) <=
1024 VALIDATE_INDEX_TS_THRESH) {
1025 flv->validate_next++;
1027 clear_index_entries(s, validate_pos);
1028 flv->validate_count = 0;
1030 } else if (pos > validate_pos) {
1031 clear_index_entries(s, validate_pos);
1032 flv->validate_count = 0;
1041 next = size + avio_tell(s->pb);
1043 if (type == FLV_TAG_TYPE_AUDIO) {
1044 stream_type = FLV_STREAM_TYPE_AUDIO;
1045 flags = avio_r8(s->pb);
1047 } else if (type == FLV_TAG_TYPE_VIDEO) {
1048 stream_type = FLV_STREAM_TYPE_VIDEO;
1049 flags = avio_r8(s->pb);
1051 if ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_VIDEO_INFO_CMD)
1053 } else if (type == FLV_TAG_TYPE_META) {
1054 stream_type=FLV_STREAM_TYPE_SUBTITLE;
1055 if (size > 13 + 1 + 4) { // Header-type metadata stuff
1057 meta_pos = avio_tell(s->pb);
1058 type = flv_read_metabody(s, next);
1059 if (type == 0 && dts == 0 || type < 0) {
1060 if (type < 0 && flv->validate_count &&
1061 flv->validate_index[0].pos > next &&
1062 flv->validate_index[0].pos - 4 < next
1064 av_log(s, AV_LOG_WARNING, "Adjusting next position due to index mismatch\n");
1065 next = flv->validate_index[0].pos - 4;
1068 } else if (type == TYPE_ONTEXTDATA) {
1069 avpriv_request_sample(s, "OnTextData packet");
1070 return flv_data_packet(s, pkt, dts, next);
1071 } else if (type == TYPE_ONCAPTION) {
1072 return flv_data_packet(s, pkt, dts, next);
1073 } else if (type == TYPE_UNKNOWN) {
1074 stream_type = FLV_STREAM_TYPE_DATA;
1076 avio_seek(s->pb, meta_pos, SEEK_SET);
1079 av_log(s, AV_LOG_DEBUG,
1080 "Skipping flv packet: type %d, size %d, flags %d.\n",
1083 if (avio_seek(s->pb, next, SEEK_SET) != next) {
1084 // This can happen if flv_read_metabody above read past
1085 // next, on a non-seekable input, and the preceding data has
1086 // been flushed out from the IO buffer.
1087 av_log(s, AV_LOG_ERROR, "Unable to seek to the next packet\n");
1088 return AVERROR_INVALIDDATA;
1094 /* skip empty data packets */
1100 /* now find stream */
1101 for (i = 0; i < s->nb_streams; i++) {
1103 if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1104 if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
1105 (s->audio_codec_id || flv_same_audio_codec(st->codecpar, flags)))
1107 } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1108 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
1109 (s->video_codec_id || flv_same_video_codec(st->codecpar, flags)))
1111 } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1112 if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
1114 } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1115 if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
1119 if (i == s->nb_streams) {
1120 static const enum AVMediaType stream_types[] = {AVMEDIA_TYPE_VIDEO, AVMEDIA_TYPE_AUDIO, AVMEDIA_TYPE_SUBTITLE, AVMEDIA_TYPE_DATA};
1121 st = create_stream(s, stream_types[stream_type]);
1123 return AVERROR(ENOMEM);
1126 av_log(s, AV_LOG_TRACE, "%d %X %d \n", stream_type, flags, st->discard);
1128 if (flv->time_pos <= pos) {
1129 dts += flv->time_offset;
1132 if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1133 ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY ||
1134 stream_type == FLV_STREAM_TYPE_AUDIO))
1135 av_add_index_entry(st, pos, dts, size, 0, AVINDEX_KEYFRAME);
1137 if ( (st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || (stream_type == FLV_STREAM_TYPE_AUDIO)))
1138 ||(st->discard >= AVDISCARD_BIDIR && ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_DISP_INTER && (stream_type == FLV_STREAM_TYPE_VIDEO)))
1139 || st->discard >= AVDISCARD_ALL
1141 avio_seek(s->pb, next, SEEK_SET);
1146 // if not streamed and no duration from metadata then seek to end to find
1147 // the duration from the timestamps
1148 if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1149 (!s->duration || s->duration == AV_NOPTS_VALUE) &&
1150 !flv->searched_for_end) {
1152 const int64_t pos = avio_tell(s->pb);
1153 // Read the last 4 bytes of the file, this should be the size of the
1154 // previous FLV tag. Use the timestamp of its payload as duration.
1155 int64_t fsize = avio_size(s->pb);
1157 avio_seek(s->pb, fsize - 4, SEEK_SET);
1158 size = avio_rb32(s->pb);
1159 if (size > 0 && size < fsize) {
1160 // Seek to the start of the last FLV tag at position (fsize - 4 - size)
1161 // but skip the byte indicating the type.
1162 avio_seek(s->pb, fsize - 3 - size, SEEK_SET);
1163 if (size == avio_rb24(s->pb) + 11) {
1164 uint32_t ts = avio_rb24(s->pb);
1165 ts |= avio_r8(s->pb) << 24;
1167 s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
1168 else if (fsize >= 8 && fsize - 8 >= size) {
1170 goto retry_duration;
1175 avio_seek(s->pb, pos, SEEK_SET);
1176 flv->searched_for_end = 1;
1179 if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1180 int bits_per_coded_sample;
1181 channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1;
1182 sample_rate = 44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >>
1183 FLV_AUDIO_SAMPLERATE_OFFSET) >> 3;
1184 bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
1185 if (!st->codecpar->channels || !st->codecpar->sample_rate ||
1186 !st->codecpar->bits_per_coded_sample) {
1187 st->codecpar->channels = channels;
1188 st->codecpar->channel_layout = channels == 1
1190 : AV_CH_LAYOUT_STEREO;
1191 st->codecpar->sample_rate = sample_rate;
1192 st->codecpar->bits_per_coded_sample = bits_per_coded_sample;
1194 if (!st->codecpar->codec_id) {
1195 flv_set_audio_codec(s, st, st->codecpar,
1196 flags & FLV_AUDIO_CODECID_MASK);
1197 flv->last_sample_rate =
1198 sample_rate = st->codecpar->sample_rate;
1199 flv->last_channels =
1200 channels = st->codecpar->channels;
1202 AVCodecParameters *par = avcodec_parameters_alloc();
1204 ret = AVERROR(ENOMEM);
1207 par->sample_rate = sample_rate;
1208 par->bits_per_coded_sample = bits_per_coded_sample;
1209 flv_set_audio_codec(s, st, par, flags & FLV_AUDIO_CODECID_MASK);
1210 sample_rate = par->sample_rate;
1211 avcodec_parameters_free(&par);
1213 } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1214 int ret = flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK, 1);
1218 } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1219 st->codecpar->codec_id = AV_CODEC_ID_TEXT;
1220 } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1221 st->codecpar->codec_id = AV_CODEC_ID_NONE; // Opaque AMF data
1224 if (st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1225 st->codecpar->codec_id == AV_CODEC_ID_H264 ||
1226 st->codecpar->codec_id == AV_CODEC_ID_MPEG4) {
1227 int type = avio_r8(s->pb);
1231 ret = AVERROR_INVALIDDATA;
1235 if (st->codecpar->codec_id == AV_CODEC_ID_H264 || st->codecpar->codec_id == AV_CODEC_ID_MPEG4) {
1237 int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000;
1239 if (cts < 0) { // dts might be wrong
1240 if (!flv->wrong_dts)
1241 av_log(s, AV_LOG_WARNING,
1242 "Negative cts, previous timestamps might be wrong.\n");
1244 } else if (FFABS(dts - pts) > 1000*60*15) {
1245 av_log(s, AV_LOG_WARNING,
1246 "invalid timestamps %"PRId64" %"PRId64"\n", dts, pts);
1247 dts = pts = AV_NOPTS_VALUE;
1250 if (type == 0 && (!st->codecpar->extradata || st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1251 st->codecpar->codec_id == AV_CODEC_ID_H264)) {
1252 AVDictionaryEntry *t;
1254 if (st->codecpar->extradata) {
1255 if ((ret = flv_queue_extradata(flv, s->pb, stream_type, size)) < 0)
1260 if ((ret = flv_get_extradata(s, st, size)) < 0)
1263 /* Workaround for buggy Omnia A/XE encoder */
1264 t = av_dict_get(s->metadata, "Encoder", NULL, 0);
1265 if (st->codecpar->codec_id == AV_CODEC_ID_AAC && t && !strcmp(t->value, "Omnia A/XE"))
1266 st->codecpar->extradata_size = 2;
1268 if (st->codecpar->codec_id == AV_CODEC_ID_AAC && 0) {
1269 MPEG4AudioConfig cfg;
1271 if (avpriv_mpeg4audio_get_config(&cfg, st->codecpar->extradata,
1272 st->codecpar->extradata_size * 8, 1) >= 0) {
1273 st->codecpar->channels = cfg.channels;
1274 st->codecpar->channel_layout = 0;
1275 if (cfg.ext_sample_rate)
1276 st->codecpar->sample_rate = cfg.ext_sample_rate;
1278 st->codecpar->sample_rate = cfg.sample_rate;
1279 av_log(s, AV_LOG_TRACE, "mp4a config channels %d sample rate %d\n",
1280 st->codecpar->channels, st->codecpar->sample_rate);
1289 /* skip empty data packets */
1295 ret = av_get_packet(s->pb, pkt, size);
1299 pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts;
1300 pkt->stream_index = st->index;
1302 if (flv->new_extradata[stream_type]) {
1303 uint8_t *side = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
1304 flv->new_extradata_size[stream_type]);
1306 memcpy(side, flv->new_extradata[stream_type],
1307 flv->new_extradata_size[stream_type]);
1308 av_freep(&flv->new_extradata[stream_type]);
1309 flv->new_extradata_size[stream_type] = 0;
1312 if (stream_type == FLV_STREAM_TYPE_AUDIO &&
1313 (sample_rate != flv->last_sample_rate ||
1314 channels != flv->last_channels)) {
1315 flv->last_sample_rate = sample_rate;
1316 flv->last_channels = channels;
1317 ff_add_param_change(pkt, channels, 0, sample_rate, 0, 0);
1320 if ( stream_type == FLV_STREAM_TYPE_AUDIO ||
1321 ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY) ||
1322 stream_type == FLV_STREAM_TYPE_SUBTITLE ||
1323 stream_type == FLV_STREAM_TYPE_DATA)
1324 pkt->flags |= AV_PKT_FLAG_KEY;
1327 last = avio_rb32(s->pb);
1328 if (!flv->trust_datasize) {
1329 if (last != orig_size + 11 && last != orig_size + 10 &&
1330 !avio_feof(s->pb) &&
1331 (last != orig_size || !last) && last != flv->sum_flv_tag_size &&
1332 !flv->broken_sizes) {
1333 av_log(s, AV_LOG_ERROR, "Packet mismatch %d %d %d\n", last, orig_size + 11, flv->sum_flv_tag_size);
1334 avio_seek(s->pb, pos + 1, SEEK_SET);
1336 av_packet_unref(pkt);
1344 flv->last_ts = pkt->dts;
1349 static int flv_read_seek(AVFormatContext *s, int stream_index,
1350 int64_t ts, int flags)
1352 FLVContext *flv = s->priv_data;
1353 flv->validate_count = 0;
1354 return avio_seek_time(s->pb, stream_index, ts, flags);
1357 #define OFFSET(x) offsetof(FLVContext, x)
1358 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1359 static const AVOption options[] = {
1360 { "flv_metadata", "Allocate streams according to the onMetaData array", OFFSET(trust_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1361 { "flv_full_metadata", "Dump full metadata of the onMetadata", OFFSET(dump_full_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1362 { "flv_ignore_prevtag", "Ignore the Size of previous tag", OFFSET(trust_datasize), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1363 { "missing_streams", "", OFFSET(missing_streams), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0xFF, VD | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
1367 static const AVClass flv_class = {
1368 .class_name = "flvdec",
1369 .item_name = av_default_item_name,
1371 .version = LIBAVUTIL_VERSION_INT,
1374 AVInputFormat ff_flv_demuxer = {
1376 .long_name = NULL_IF_CONFIG_SMALL("FLV (Flash Video)"),
1377 .priv_data_size = sizeof(FLVContext),
1378 .read_probe = flv_probe,
1379 .read_header = flv_read_header,
1380 .read_packet = flv_read_packet,
1381 .read_seek = flv_read_seek,
1382 .read_close = flv_read_close,
1383 .extensions = "flv",
1384 .priv_class = &flv_class,
1387 static const AVClass live_flv_class = {
1388 .class_name = "live_flvdec",
1389 .item_name = av_default_item_name,
1391 .version = LIBAVUTIL_VERSION_INT,
1394 AVInputFormat ff_live_flv_demuxer = {
1396 .long_name = NULL_IF_CONFIG_SMALL("live RTMP FLV (Flash Video)"),
1397 .priv_data_size = sizeof(FLVContext),
1398 .read_probe = live_flv_probe,
1399 .read_header = flv_read_header,
1400 .read_packet = flv_read_packet,
1401 .read_seek = flv_read_seek,
1402 .read_close = flv_read_close,
1403 .extensions = "flv",
1404 .priv_class = &live_flv_class,
1405 .flags = AVFMT_TS_DISCONT
1408 static const AVClass kux_class = {
1409 .class_name = "kuxdec",
1410 .item_name = av_default_item_name,
1412 .version = LIBAVUTIL_VERSION_INT,
1415 AVInputFormat ff_kux_demuxer = {
1417 .long_name = NULL_IF_CONFIG_SMALL("KUX (YouKu)"),
1418 .priv_data_size = sizeof(FLVContext),
1419 .read_probe = kux_probe,
1420 .read_header = flv_read_header,
1421 .read_packet = flv_read_packet,
1422 .read_seek = flv_read_seek,
1423 .read_close = flv_read_close,
1424 .extensions = "kux",
1425 .priv_class = &kux_class,