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"
37 #include "avio_internal.h"
40 #define VALIDATE_INDEX_TS_THRESH 2500
42 #define RESYNC_BUFFER_SIZE (1<<20)
44 #define MAX_DEPTH 16 ///< arbitrary limit to prevent unbounded recursion
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
52 uint8_t *new_extradata[FLV_STREAM_TYPE_NB];
53 int new_extradata_size[FLV_STREAM_TYPE_NB];
64 uint8_t resync_buffer[2*RESYNC_BUFFER_SIZE];
69 int last_keyframe_stream_index;
71 int64_t video_bit_rate;
72 int64_t audio_bit_rate;
73 int64_t *keyframe_times;
74 int64_t *keyframe_filepositions;
83 typedef struct amf_date {
88 static int probe(const AVProbeData *p, int live)
90 const uint8_t *d = p->buf;
91 unsigned offset = AV_RB32(d + 5);
96 d[3] < 5 && d[5] == 0 &&
97 offset + 100 < p->buf_size &&
99 int is_live = !memcmp(d + offset + 40, "NGINX RTMP", 10);
102 return AVPROBE_SCORE_MAX;
107 static int flv_probe(const AVProbeData *p)
112 static int live_flv_probe(const AVProbeData *p)
117 static int kux_probe(const AVProbeData *p)
119 const uint8_t *d = p->buf;
126 return AVPROBE_SCORE_EXTENSION + 1;
131 static void add_keyframes_index(AVFormatContext *s)
133 FLVContext *flv = s->priv_data;
134 AVStream *stream = NULL;
137 if (flv->last_keyframe_stream_index < 0) {
138 av_log(s, AV_LOG_DEBUG, "keyframe stream hasn't been created\n");
142 av_assert0(flv->last_keyframe_stream_index <= s->nb_streams);
143 stream = s->streams[flv->last_keyframe_stream_index];
145 if (stream->internal->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);
149 av_add_index_entry(stream, flv->keyframe_filepositions[i],
150 flv->keyframe_times[i] * 1000, 0, 0, AVINDEX_KEYFRAME);
153 av_log(s, AV_LOG_WARNING, "Skipping duplicate index\n");
155 if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
156 av_freep(&flv->keyframe_times);
157 av_freep(&flv->keyframe_filepositions);
158 flv->keyframe_count = 0;
162 static AVStream *create_stream(AVFormatContext *s, int codec_type)
164 FLVContext *flv = s->priv_data;
165 AVStream *st = avformat_new_stream(s, NULL);
168 st->codecpar->codec_type = codec_type;
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;
175 if (codec_type == AVMEDIA_TYPE_AUDIO) {
176 st->codecpar->bit_rate = flv->audio_bit_rate;
177 flv->missing_streams &= ~FLV_HEADER_FLAG_HASAUDIO;
179 if (codec_type == AVMEDIA_TYPE_VIDEO) {
180 st->codecpar->bit_rate = flv->video_bit_rate;
181 flv->missing_streams &= ~FLV_HEADER_FLAG_HASVIDEO;
182 st->avg_frame_rate = flv->framerate;
186 avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
187 flv->last_keyframe_stream_index = s->nb_streams - 1;
188 add_keyframes_index(s);
192 static int flv_same_audio_codec(AVCodecParameters *apar, int flags)
194 int bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
195 int flv_codecid = flags & FLV_AUDIO_CODECID_MASK;
198 if (!apar->codec_id && !apar->codec_tag)
201 if (apar->bits_per_coded_sample != bits_per_coded_sample)
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
210 : AV_CODEC_ID_PCM_S16BE;
212 : AV_CODEC_ID_PCM_S16LE;
214 return codec_id == apar->codec_id;
215 case FLV_CODECID_PCM_LE:
216 codec_id = bits_per_coded_sample == 8
218 : AV_CODEC_ID_PCM_S16LE;
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;
228 case FLV_CODECID_NELLYMOSER_8KHZ_MONO:
229 case FLV_CODECID_NELLYMOSER_16KHZ_MONO:
230 case FLV_CODECID_NELLYMOSER:
231 return apar->codec_id == AV_CODEC_ID_NELLYMOSER;
232 case FLV_CODECID_PCM_MULAW:
233 return apar->sample_rate == 8000 &&
234 apar->codec_id == AV_CODEC_ID_PCM_MULAW;
235 case FLV_CODECID_PCM_ALAW:
236 return apar->sample_rate == 8000 &&
237 apar->codec_id == AV_CODEC_ID_PCM_ALAW;
239 return apar->codec_tag == (flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
243 static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream,
244 AVCodecParameters *apar, int flv_codecid)
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
252 : AV_CODEC_ID_PCM_S16BE;
254 : AV_CODEC_ID_PCM_S16LE;
257 case FLV_CODECID_PCM_LE:
258 apar->codec_id = apar->bits_per_coded_sample == 8
260 : AV_CODEC_ID_PCM_S16LE;
262 case FLV_CODECID_AAC:
263 apar->codec_id = AV_CODEC_ID_AAC;
265 case FLV_CODECID_ADPCM:
266 apar->codec_id = AV_CODEC_ID_ADPCM_SWF;
268 case FLV_CODECID_SPEEX:
269 apar->codec_id = AV_CODEC_ID_SPEEX;
270 apar->sample_rate = 16000;
272 case FLV_CODECID_MP3:
273 apar->codec_id = AV_CODEC_ID_MP3;
274 astream->need_parsing = AVSTREAM_PARSE_FULL;
276 case FLV_CODECID_NELLYMOSER_8KHZ_MONO:
277 // in case metadata does not otherwise declare samplerate
278 apar->sample_rate = 8000;
279 apar->codec_id = AV_CODEC_ID_NELLYMOSER;
281 case FLV_CODECID_NELLYMOSER_16KHZ_MONO:
282 apar->sample_rate = 16000;
283 apar->codec_id = AV_CODEC_ID_NELLYMOSER;
285 case FLV_CODECID_NELLYMOSER:
286 apar->codec_id = AV_CODEC_ID_NELLYMOSER;
288 case FLV_CODECID_PCM_MULAW:
289 apar->sample_rate = 8000;
290 apar->codec_id = AV_CODEC_ID_PCM_MULAW;
292 case FLV_CODECID_PCM_ALAW:
293 apar->sample_rate = 8000;
294 apar->codec_id = AV_CODEC_ID_PCM_ALAW;
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;
303 static int flv_same_video_codec(AVCodecParameters *vpar, int flags)
305 int flv_codecid = flags & FLV_VIDEO_CODECID_MASK;
307 if (!vpar->codec_id && !vpar->codec_tag)
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;
324 return vpar->codec_tag == flv_codecid;
328 static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream,
329 int flv_codecid, int read)
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;
338 case FLV_CODECID_REALH263:
339 par->codec_id = AV_CODEC_ID_H263;
340 break; // Really mean it this time
341 case FLV_CODECID_SCREEN:
342 par->codec_id = AV_CODEC_ID_FLASHSV;
344 case FLV_CODECID_SCREEN2:
345 par->codec_id = AV_CODEC_ID_FLASHSV2;
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;
353 if (par->extradata_size != 1) {
354 ff_alloc_extradata(par, 1);
357 par->extradata[0] = avio_r8(s->pb);
361 ret = 1; // 1 byte body size adjustment for flv_read_packet()
363 case FLV_CODECID_H264:
364 par->codec_id = AV_CODEC_ID_H264;
365 vstream->need_parsing = AVSTREAM_PARSE_HEADERS;
366 ret = 3; // not 4, reading packet type will consume one byte
368 case FLV_CODECID_MPEG4:
369 par->codec_id = AV_CODEC_ID_MPEG4;
373 avpriv_request_sample(s, "Video codec (%x)", flv_codecid);
374 par->codec_tag = flv_codecid;
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;
385 static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize)
388 int length = avio_rb16(ioc);
389 if (length >= buffsize) {
390 avio_skip(ioc, length);
394 ret = avio_read(ioc, buffer, length);
398 return AVERROR_INVALIDDATA;
400 buffer[length] = '\0';
405 static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, int64_t max_pos)
407 FLVContext *flv = s->priv_data;
408 unsigned int timeslen = 0, fileposlen = 0, i;
410 int64_t *times = NULL;
411 int64_t *filepositions = NULL;
412 int ret = AVERROR(ENOSYS);
413 int64_t initial_pos = avio_tell(ioc);
415 if (flv->keyframe_count > 0) {
416 av_log(s, AV_LOG_DEBUG, "keyframes have been parsed\n");
419 av_assert0(!flv->keyframe_times);
420 av_assert0(!flv->keyframe_filepositions);
422 if (s->flags & AVFMT_FLAG_IGNIDX)
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;
430 // Expect array object in context
431 if (avio_r8(ioc) != AMF_DATA_TYPE_ARRAY)
434 arraylen = avio_rb32(ioc);
438 if (!strcmp(KEYFRAMES_TIMESTAMP_TAG , str_val) && !times) {
439 current_array = ×
441 } else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) &&
443 current_array = &filepositions;
444 fileposlen = arraylen;
446 // unexpected metatag inside keyframes, will not use such
447 // metadata for indexing
450 if (!(*current_array = av_mallocz(sizeof(**current_array) * arraylen))) {
451 ret = AVERROR(ENOMEM);
455 for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) {
456 if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER)
458 current_array[0][i] = av_int2double(avio_rb64(ioc));
460 if (times && filepositions) {
461 // All done, exiting at a position allowing amf_parse_object
462 // to finish parsing the object
468 if (timeslen == fileposlen && fileposlen>1 && max_pos <= filepositions[0]) {
469 for (i = 0; i < FFMIN(2,fileposlen); i++) {
470 flv->validate_index[i].pos = filepositions[i];
471 flv->validate_index[i].dts = times[i] * 1000;
472 flv->validate_count = i + 1;
474 flv->keyframe_times = times;
475 flv->keyframe_filepositions = filepositions;
476 flv->keyframe_count = timeslen;
478 filepositions = NULL;
481 av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n");
486 av_freep(&filepositions);
487 avio_seek(ioc, initial_pos, SEEK_SET);
491 static int amf_parse_object(AVFormatContext *s, AVStream *astream,
492 AVStream *vstream, const char *key,
493 int64_t max_pos, int depth)
495 AVCodecParameters *apar, *vpar;
496 FLVContext *flv = s->priv_data;
498 AMFDataType amf_type;
503 if (depth > MAX_DEPTH)
504 return AVERROR_PATCHWELCOME;
510 amf_type = avio_r8(ioc);
513 case AMF_DATA_TYPE_NUMBER:
514 num_val = av_int2double(avio_rb64(ioc));
516 case AMF_DATA_TYPE_BOOL:
517 num_val = avio_r8(ioc);
519 case AMF_DATA_TYPE_STRING:
520 if (amf_get_string(ioc, str_val, sizeof(str_val)) < 0) {
521 av_log(s, AV_LOG_ERROR, "AMF_DATA_TYPE_STRING parsing failed\n");
525 case AMF_DATA_TYPE_OBJECT:
527 (ioc->seekable & AVIO_SEEKABLE_NORMAL) &&
528 !strcmp(KEYFRAMES_TAG, key) && depth == 1)
529 if (parse_keyframes_index(s, ioc, max_pos) < 0)
530 av_log(s, AV_LOG_ERROR, "Keyframe index parsing failed\n");
532 add_keyframes_index(s);
533 while (avio_tell(ioc) < max_pos - 2 &&
534 amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
535 if (amf_parse_object(s, astream, vstream, str_val, max_pos,
537 return -1; // if we couldn't skip, bomb out.
538 if (avio_r8(ioc) != AMF_END_OF_OBJECT) {
539 av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_OBJECT\n");
543 case AMF_DATA_TYPE_NULL:
544 case AMF_DATA_TYPE_UNDEFINED:
545 case AMF_DATA_TYPE_UNSUPPORTED:
546 break; // these take up no additional space
547 case AMF_DATA_TYPE_MIXEDARRAY:
550 avio_skip(ioc, 4); // skip 32-bit max array index
551 while (avio_tell(ioc) < max_pos - 2 &&
552 amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
553 // this is the only case in which we would want a nested
554 // parse to not skip over the object
555 if (amf_parse_object(s, astream, vstream, str_val, max_pos,
559 if (v != AMF_END_OF_OBJECT) {
560 av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_MIXEDARRAY, found %d\n", v);
565 case AMF_DATA_TYPE_ARRAY:
567 unsigned int arraylen, i;
569 arraylen = avio_rb32(ioc);
570 for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++)
571 if (amf_parse_object(s, NULL, NULL, NULL, max_pos,
573 return -1; // if we couldn't skip, bomb out.
576 case AMF_DATA_TYPE_DATE:
577 // timestamp (double) and UTC offset (int16)
578 date.milliseconds = av_int2double(avio_rb64(ioc));
579 date.timezone = avio_rb16(ioc);
581 default: // unsupported type, we couldn't skip
582 av_log(s, AV_LOG_ERROR, "unsupported amf type %d\n", amf_type);
587 apar = astream ? astream->codecpar : NULL;
588 vpar = vstream ? vstream->codecpar : NULL;
590 // stream info doesn't live any deeper than the first object
592 if (amf_type == AMF_DATA_TYPE_NUMBER ||
593 amf_type == AMF_DATA_TYPE_BOOL) {
594 if (!strcmp(key, "duration"))
595 s->duration = num_val * AV_TIME_BASE;
596 else if (!strcmp(key, "videodatarate") &&
597 0 <= (int)(num_val * 1024.0))
598 flv->video_bit_rate = num_val * 1024.0;
599 else if (!strcmp(key, "audiodatarate") &&
600 0 <= (int)(num_val * 1024.0))
601 flv->audio_bit_rate = num_val * 1024.0;
602 else if (!strcmp(key, "datastream")) {
603 AVStream *st = create_stream(s, AVMEDIA_TYPE_SUBTITLE);
605 return AVERROR(ENOMEM);
606 st->codecpar->codec_id = AV_CODEC_ID_TEXT;
607 } else if (!strcmp(key, "framerate")) {
608 flv->framerate = av_d2q(num_val, 1000);
610 vstream->avg_frame_rate = flv->framerate;
611 } else if (flv->trust_metadata) {
612 if (!strcmp(key, "videocodecid") && vpar) {
613 int ret = flv_set_video_codec(s, vstream, num_val, 0);
616 } else if (!strcmp(key, "audiocodecid") && apar) {
617 int id = ((int)num_val) << FLV_AUDIO_CODECID_OFFSET;
618 flv_set_audio_codec(s, astream, apar, id);
619 } else if (!strcmp(key, "audiosamplerate") && apar) {
620 apar->sample_rate = num_val;
621 } else if (!strcmp(key, "audiosamplesize") && apar) {
622 apar->bits_per_coded_sample = num_val;
623 } else if (!strcmp(key, "stereo") && apar) {
624 apar->channels = num_val + 1;
625 apar->channel_layout = apar->channels == 2 ?
626 AV_CH_LAYOUT_STEREO :
628 } else if (!strcmp(key, "width") && vpar) {
629 vpar->width = num_val;
630 } else if (!strcmp(key, "height") && vpar) {
631 vpar->height = num_val;
635 if (amf_type == AMF_DATA_TYPE_STRING) {
636 if (!strcmp(key, "encoder")) {
638 if (1 == sscanf(str_val, "Open Broadcaster Software v0.%d", &version)) {
639 if (version > 0 && version <= 655)
640 flv->broken_sizes = 1;
642 } else if (!strcmp(key, "metadatacreator")) {
643 if ( !strcmp (str_val, "MEGA")
644 || !strncmp(str_val, "FlixEngine", 10))
645 flv->broken_sizes = 1;
650 if (amf_type == AMF_DATA_TYPE_OBJECT && s->nb_streams == 1 &&
651 ((!apar && !strcmp(key, "audiocodecid")) ||
652 (!vpar && !strcmp(key, "videocodecid"))))
653 s->ctx_flags &= ~AVFMTCTX_NOHEADER; //If there is either audio/video missing, codecid will be an empty object
655 if ((!strcmp(key, "duration") ||
656 !strcmp(key, "filesize") ||
657 !strcmp(key, "width") ||
658 !strcmp(key, "height") ||
659 !strcmp(key, "videodatarate") ||
660 !strcmp(key, "framerate") ||
661 !strcmp(key, "videocodecid") ||
662 !strcmp(key, "audiodatarate") ||
663 !strcmp(key, "audiosamplerate") ||
664 !strcmp(key, "audiosamplesize") ||
665 !strcmp(key, "stereo") ||
666 !strcmp(key, "audiocodecid") ||
667 !strcmp(key, "datastream")) && !flv->dump_full_metadata)
670 s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
671 if (amf_type == AMF_DATA_TYPE_BOOL) {
672 av_strlcpy(str_val, num_val > 0 ? "true" : "false",
674 av_dict_set(&s->metadata, key, str_val, 0);
675 } else if (amf_type == AMF_DATA_TYPE_NUMBER) {
676 snprintf(str_val, sizeof(str_val), "%.f", num_val);
677 av_dict_set(&s->metadata, key, str_val, 0);
678 } else if (amf_type == AMF_DATA_TYPE_STRING) {
679 av_dict_set(&s->metadata, key, str_val, 0);
680 } else if (amf_type == AMF_DATA_TYPE_DATE) {
684 time = date.milliseconds / 1000; // to seconds
685 localtime_r(&time, &t);
686 strftime(datestr, sizeof(datestr), "%a, %d %b %Y %H:%M:%S %z", &t);
688 av_dict_set(&s->metadata, key, datestr, 0);
695 #define TYPE_ONTEXTDATA 1
696 #define TYPE_ONCAPTION 2
697 #define TYPE_ONCAPTIONINFO 3
698 #define TYPE_UNKNOWN 9
700 static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
702 FLVContext *flv = s->priv_data;
704 AVStream *stream, *astream, *vstream;
705 AVStream av_unused *dstream;
715 // first object needs to be "onMetaData" string
717 if (type != AMF_DATA_TYPE_STRING ||
718 amf_get_string(ioc, buffer, sizeof(buffer)) < 0)
721 if (!strcmp(buffer, "onTextData"))
722 return TYPE_ONTEXTDATA;
724 if (!strcmp(buffer, "onCaption"))
725 return TYPE_ONCAPTION;
727 if (!strcmp(buffer, "onCaptionInfo"))
728 return TYPE_ONCAPTIONINFO;
730 if (strcmp(buffer, "onMetaData") && strcmp(buffer, "onCuePoint") && strcmp(buffer, "|RtmpSampleAccess")) {
731 av_log(s, AV_LOG_DEBUG, "Unknown type %s\n", buffer);
735 // find the streams now so that amf_parse_object doesn't need to do
736 // the lookup every time it is called.
737 for (i = 0; i < s->nb_streams; i++) {
738 stream = s->streams[i];
739 if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
741 flv->last_keyframe_stream_index = i;
742 } else if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
744 if (flv->last_keyframe_stream_index == -1)
745 flv->last_keyframe_stream_index = i;
746 } else if (stream->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
750 // parse the second object (we want a mixed array)
751 if (amf_parse_object(s, astream, vstream, buffer, next_pos, 0) < 0)
757 static int flv_read_header(AVFormatContext *s)
760 FLVContext *flv = s->priv_data;
762 int pre_tag_size = 0;
764 /* Actual FLV data at 0xe40000 in KUX file */
765 if(!strcmp(s->iformat->name, "kux"))
766 avio_skip(s->pb, 0xe40000);
769 flags = avio_r8(s->pb);
771 flv->missing_streams = flags & (FLV_HEADER_FLAG_HASVIDEO | FLV_HEADER_FLAG_HASAUDIO);
773 s->ctx_flags |= AVFMTCTX_NOHEADER;
775 offset = avio_rb32(s->pb);
776 avio_seek(s->pb, offset, SEEK_SET);
778 /* Annex E. The FLV File Format
781 * PreviousTagSize0 UI32 Always 0
783 pre_tag_size = avio_rb32(s->pb);
785 av_log(s, AV_LOG_WARNING, "Read FLV header error, input file is not a standard flv format, first PreviousTagSize0 always is 0\n");
789 flv->sum_flv_tag_size = 0;
790 flv->last_keyframe_stream_index = -1;
795 static int flv_read_close(AVFormatContext *s)
798 FLVContext *flv = s->priv_data;
799 for (i=0; i<FLV_STREAM_TYPE_NB; i++)
800 av_freep(&flv->new_extradata[i]);
801 av_freep(&flv->keyframe_times);
802 av_freep(&flv->keyframe_filepositions);
806 static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size)
812 if ((ret = ff_get_extradata(s, st->codecpar, s->pb, size)) < 0)
814 st->internal->need_context_update = 1;
818 static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream,
824 av_free(flv->new_extradata[stream]);
825 flv->new_extradata[stream] = av_mallocz(size +
826 AV_INPUT_BUFFER_PADDING_SIZE);
827 if (!flv->new_extradata[stream])
828 return AVERROR(ENOMEM);
829 flv->new_extradata_size[stream] = size;
830 avio_read(pb, flv->new_extradata[stream], size);
834 static void clear_index_entries(AVFormatContext *s, int64_t pos)
837 av_log(s, AV_LOG_WARNING,
838 "Found invalid index entries, clearing the index.\n");
839 for (i = 0; i < s->nb_streams; i++) {
840 AVStream *st = s->streams[i];
841 /* Remove all index entries that point to >= pos */
843 for (j = 0; j < st->internal->nb_index_entries; j++)
844 if (st->internal->index_entries[j].pos < pos)
845 st->internal->index_entries[out++] = st->internal->index_entries[j];
846 st->internal->nb_index_entries = out;
850 static int amf_skip_tag(AVIOContext *pb, AMFDataType type, int depth)
852 int nb = -1, ret, parse_name = 1;
854 if (depth > MAX_DEPTH)
855 return AVERROR_PATCHWELCOME;
858 case AMF_DATA_TYPE_NUMBER:
861 case AMF_DATA_TYPE_BOOL:
864 case AMF_DATA_TYPE_STRING:
865 avio_skip(pb, avio_rb16(pb));
867 case AMF_DATA_TYPE_ARRAY:
869 case AMF_DATA_TYPE_MIXEDARRAY:
871 case AMF_DATA_TYPE_OBJECT:
872 while(!pb->eof_reached && (nb-- > 0 || type != AMF_DATA_TYPE_ARRAY)) {
874 int size = avio_rb16(pb);
881 if ((ret = amf_skip_tag(pb, avio_r8(pb), depth + 1)) < 0)
885 case AMF_DATA_TYPE_NULL:
886 case AMF_DATA_TYPE_OBJECT_END:
889 return AVERROR_INVALIDDATA;
894 static int flv_data_packet(AVFormatContext *s, AVPacket *pkt,
895 int64_t dts, int64_t next)
897 AVIOContext *pb = s->pb;
900 int ret = AVERROR_INVALIDDATA;
904 switch (avio_r8(pb)) {
905 case AMF_DATA_TYPE_ARRAY:
907 case AMF_DATA_TYPE_MIXEDARRAY:
908 avio_seek(pb, 4, SEEK_CUR);
909 case AMF_DATA_TYPE_OBJECT:
915 while (array || (ret = amf_get_string(pb, buf, sizeof(buf))) > 0) {
916 AMFDataType type = avio_r8(pb);
917 if (type == AMF_DATA_TYPE_STRING && (array || !strcmp(buf, "text"))) {
918 length = avio_rb16(pb);
919 ret = av_get_packet(pb, pkt, length);
925 if ((ret = amf_skip_tag(pb, type, 0)) < 0)
931 ret = AVERROR_INVALIDDATA;
935 for (i = 0; i < s->nb_streams; i++) {
937 if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
941 if (i == s->nb_streams) {
942 st = create_stream(s, AVMEDIA_TYPE_SUBTITLE);
944 return AVERROR(ENOMEM);
945 st->codecpar->codec_id = AV_CODEC_ID_TEXT;
952 pkt->stream_index = st->index;
953 pkt->flags |= AV_PKT_FLAG_KEY;
956 avio_seek(s->pb, next + 4, SEEK_SET);
961 static int resync(AVFormatContext *s)
963 FLVContext *flv = s->priv_data;
965 int64_t pos = avio_tell(s->pb);
967 for (i=0; !avio_feof(s->pb); i++) {
968 int j = i & (RESYNC_BUFFER_SIZE-1);
969 int j1 = j + RESYNC_BUFFER_SIZE;
970 flv->resync_buffer[j ] =
971 flv->resync_buffer[j1] = avio_r8(s->pb);
974 uint8_t *d = flv->resync_buffer + j1 - 8;
978 d[3] < 5 && d[5] == 0) {
979 av_log(s, AV_LOG_WARNING, "Concatenated FLV detected, might fail to demux, decode and seek %"PRId64"\n", flv->last_ts);
980 flv->time_offset = flv->last_ts + 1;
981 flv->time_pos = avio_tell(s->pb);
986 unsigned lsize2 = AV_RB32(flv->resync_buffer + j1 - 4);
987 if (lsize2 >= 11 && lsize2 + 8LL < FFMIN(i, RESYNC_BUFFER_SIZE)) {
988 unsigned size2 = AV_RB24(flv->resync_buffer + j1 - lsize2 + 1 - 4);
989 unsigned lsize1 = AV_RB32(flv->resync_buffer + j1 - lsize2 - 8);
990 if (lsize1 >= 11 && lsize1 + 8LL + lsize2 < FFMIN(i, RESYNC_BUFFER_SIZE)) {
991 unsigned size1 = AV_RB24(flv->resync_buffer + j1 - lsize1 + 1 - lsize2 - 8);
992 if (size1 == lsize1 - 11 && size2 == lsize2 - 11) {
993 avio_seek(s->pb, pos + i - lsize1 - lsize2 - 8, SEEK_SET);
1003 static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
1005 FLVContext *flv = s->priv_data;
1006 int ret, i, size, flags;
1007 enum FlvTagType type;
1009 int64_t next, pos, meta_pos;
1010 int64_t dts, pts = AV_NOPTS_VALUE;
1011 int av_uninit(channels);
1012 int av_uninit(sample_rate);
1013 AVStream *st = NULL;
1018 /* pkt size is repeated at end. skip it */
1019 pos = avio_tell(s->pb);
1020 type = (avio_r8(s->pb) & 0x1F);
1022 size = avio_rb24(s->pb);
1023 flv->sum_flv_tag_size += size + 11;
1024 dts = avio_rb24(s->pb);
1025 dts |= (unsigned)avio_r8(s->pb) << 24;
1026 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));
1027 if (avio_feof(s->pb))
1029 avio_skip(s->pb, 3); /* stream id, always 0 */
1032 if (flv->validate_next < flv->validate_count) {
1033 int64_t validate_pos = flv->validate_index[flv->validate_next].pos;
1034 if (pos == validate_pos) {
1035 if (FFABS(dts - flv->validate_index[flv->validate_next].dts) <=
1036 VALIDATE_INDEX_TS_THRESH) {
1037 flv->validate_next++;
1039 clear_index_entries(s, validate_pos);
1040 flv->validate_count = 0;
1042 } else if (pos > validate_pos) {
1043 clear_index_entries(s, validate_pos);
1044 flv->validate_count = 0;
1053 next = size + avio_tell(s->pb);
1055 if (type == FLV_TAG_TYPE_AUDIO) {
1056 stream_type = FLV_STREAM_TYPE_AUDIO;
1057 flags = avio_r8(s->pb);
1059 } else if (type == FLV_TAG_TYPE_VIDEO) {
1060 stream_type = FLV_STREAM_TYPE_VIDEO;
1061 flags = avio_r8(s->pb);
1063 if ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_VIDEO_INFO_CMD)
1065 } else if (type == FLV_TAG_TYPE_META) {
1066 stream_type=FLV_STREAM_TYPE_SUBTITLE;
1067 if (size > 13 + 1 + 4) { // Header-type metadata stuff
1069 meta_pos = avio_tell(s->pb);
1070 type = flv_read_metabody(s, next);
1071 if (type == 0 && dts == 0 || type < 0) {
1072 if (type < 0 && flv->validate_count &&
1073 flv->validate_index[0].pos > next &&
1074 flv->validate_index[0].pos - 4 < next) {
1075 av_log(s, AV_LOG_WARNING, "Adjusting next position due to index mismatch\n");
1076 next = flv->validate_index[0].pos - 4;
1079 } else if (type == TYPE_ONTEXTDATA) {
1080 avpriv_request_sample(s, "OnTextData packet");
1081 return flv_data_packet(s, pkt, dts, next);
1082 } else if (type == TYPE_ONCAPTION) {
1083 return flv_data_packet(s, pkt, dts, next);
1084 } else if (type == TYPE_UNKNOWN) {
1085 stream_type = FLV_STREAM_TYPE_DATA;
1087 avio_seek(s->pb, meta_pos, SEEK_SET);
1090 av_log(s, AV_LOG_DEBUG,
1091 "Skipping flv packet: type %d, size %d, flags %d.\n",
1094 if (avio_seek(s->pb, next, SEEK_SET) != next) {
1095 // This can happen if flv_read_metabody above read past
1096 // next, on a non-seekable input, and the preceding data has
1097 // been flushed out from the IO buffer.
1098 av_log(s, AV_LOG_ERROR, "Unable to seek to the next packet\n");
1099 return AVERROR_INVALIDDATA;
1105 /* skip empty data packets */
1111 /* now find stream */
1112 for (i = 0; i < s->nb_streams; i++) {
1114 if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1115 if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
1116 (s->audio_codec_id || flv_same_audio_codec(st->codecpar, flags)))
1118 } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1119 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
1120 (s->video_codec_id || flv_same_video_codec(st->codecpar, flags)))
1122 } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1123 if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
1125 } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1126 if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
1130 if (i == s->nb_streams) {
1131 static const enum AVMediaType stream_types[] = {AVMEDIA_TYPE_VIDEO, AVMEDIA_TYPE_AUDIO, AVMEDIA_TYPE_SUBTITLE, AVMEDIA_TYPE_DATA};
1132 st = create_stream(s, stream_types[stream_type]);
1134 return AVERROR(ENOMEM);
1136 av_log(s, AV_LOG_TRACE, "%d %X %d \n", stream_type, flags, st->discard);
1138 if (flv->time_pos <= pos) {
1139 dts += flv->time_offset;
1142 if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1143 ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY ||
1144 stream_type == FLV_STREAM_TYPE_AUDIO))
1145 av_add_index_entry(st, pos, dts, size, 0, AVINDEX_KEYFRAME);
1147 if ((st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || stream_type == FLV_STREAM_TYPE_AUDIO)) ||
1148 (st->discard >= AVDISCARD_BIDIR && ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_DISP_INTER && stream_type == FLV_STREAM_TYPE_VIDEO)) ||
1149 st->discard >= AVDISCARD_ALL) {
1150 avio_seek(s->pb, next, SEEK_SET);
1155 // if not streamed and no duration from metadata then seek to end to find
1156 // the duration from the timestamps
1157 if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1158 (!s->duration || s->duration == AV_NOPTS_VALUE) &&
1159 !flv->searched_for_end) {
1161 const int64_t pos = avio_tell(s->pb);
1162 // Read the last 4 bytes of the file, this should be the size of the
1163 // previous FLV tag. Use the timestamp of its payload as duration.
1164 int64_t fsize = avio_size(s->pb);
1166 avio_seek(s->pb, fsize - 4, SEEK_SET);
1167 size = avio_rb32(s->pb);
1168 if (size > 0 && size < fsize) {
1169 // Seek to the start of the last FLV tag at position (fsize - 4 - size)
1170 // but skip the byte indicating the type.
1171 avio_seek(s->pb, fsize - 3 - size, SEEK_SET);
1172 if (size == avio_rb24(s->pb) + 11) {
1173 uint32_t ts = avio_rb24(s->pb);
1174 ts |= avio_r8(s->pb) << 24;
1176 s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
1177 else if (fsize >= 8 && fsize - 8 >= size) {
1179 goto retry_duration;
1184 avio_seek(s->pb, pos, SEEK_SET);
1185 flv->searched_for_end = 1;
1188 if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1189 int bits_per_coded_sample;
1190 channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1;
1191 sample_rate = 44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >>
1192 FLV_AUDIO_SAMPLERATE_OFFSET) >> 3;
1193 bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
1194 if (!st->codecpar->channels || !st->codecpar->sample_rate ||
1195 !st->codecpar->bits_per_coded_sample) {
1196 st->codecpar->channels = channels;
1197 st->codecpar->channel_layout = channels == 1
1199 : AV_CH_LAYOUT_STEREO;
1200 st->codecpar->sample_rate = sample_rate;
1201 st->codecpar->bits_per_coded_sample = bits_per_coded_sample;
1203 if (!st->codecpar->codec_id) {
1204 flv_set_audio_codec(s, st, st->codecpar,
1205 flags & FLV_AUDIO_CODECID_MASK);
1206 flv->last_sample_rate =
1207 sample_rate = st->codecpar->sample_rate;
1208 flv->last_channels =
1209 channels = st->codecpar->channels;
1211 AVCodecParameters *par = avcodec_parameters_alloc();
1213 ret = AVERROR(ENOMEM);
1216 par->sample_rate = sample_rate;
1217 par->bits_per_coded_sample = bits_per_coded_sample;
1218 flv_set_audio_codec(s, st, par, flags & FLV_AUDIO_CODECID_MASK);
1219 sample_rate = par->sample_rate;
1220 avcodec_parameters_free(&par);
1222 } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1223 int ret = flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK, 1);
1227 } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1228 st->codecpar->codec_id = AV_CODEC_ID_TEXT;
1229 } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1230 st->codecpar->codec_id = AV_CODEC_ID_NONE; // Opaque AMF data
1233 if (st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1234 st->codecpar->codec_id == AV_CODEC_ID_H264 ||
1235 st->codecpar->codec_id == AV_CODEC_ID_MPEG4) {
1236 int type = avio_r8(s->pb);
1240 ret = AVERROR_INVALIDDATA;
1244 if (st->codecpar->codec_id == AV_CODEC_ID_H264 || st->codecpar->codec_id == AV_CODEC_ID_MPEG4) {
1246 int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000;
1247 pts = av_sat_add64(dts, cts);
1248 if (cts < 0) { // dts might be wrong
1249 if (!flv->wrong_dts)
1250 av_log(s, AV_LOG_WARNING,
1251 "Negative cts, previous timestamps might be wrong.\n");
1253 } else if (FFABS(dts - pts) > 1000*60*15) {
1254 av_log(s, AV_LOG_WARNING,
1255 "invalid timestamps %"PRId64" %"PRId64"\n", dts, pts);
1256 dts = pts = AV_NOPTS_VALUE;
1259 if (type == 0 && (!st->codecpar->extradata || st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1260 st->codecpar->codec_id == AV_CODEC_ID_H264)) {
1261 AVDictionaryEntry *t;
1263 if (st->codecpar->extradata) {
1264 if ((ret = flv_queue_extradata(flv, s->pb, stream_type, size)) < 0)
1269 if ((ret = flv_get_extradata(s, st, size)) < 0)
1272 /* Workaround for buggy Omnia A/XE encoder */
1273 t = av_dict_get(s->metadata, "Encoder", NULL, 0);
1274 if (st->codecpar->codec_id == AV_CODEC_ID_AAC && t && !strcmp(t->value, "Omnia A/XE"))
1275 st->codecpar->extradata_size = 2;
1282 /* skip empty data packets */
1288 ret = av_get_packet(s->pb, pkt, size);
1292 pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts;
1293 pkt->stream_index = st->index;
1295 if (flv->new_extradata[stream_type]) {
1296 int ret = av_packet_add_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
1297 flv->new_extradata[stream_type],
1298 flv->new_extradata_size[stream_type]);
1300 flv->new_extradata[stream_type] = NULL;
1301 flv->new_extradata_size[stream_type] = 0;
1304 if (stream_type == FLV_STREAM_TYPE_AUDIO &&
1305 (sample_rate != flv->last_sample_rate ||
1306 channels != flv->last_channels)) {
1307 flv->last_sample_rate = sample_rate;
1308 flv->last_channels = channels;
1309 ff_add_param_change(pkt, channels, 0, sample_rate, 0, 0);
1312 if (stream_type == FLV_STREAM_TYPE_AUDIO ||
1313 (flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY ||
1314 stream_type == FLV_STREAM_TYPE_SUBTITLE ||
1315 stream_type == FLV_STREAM_TYPE_DATA)
1316 pkt->flags |= AV_PKT_FLAG_KEY;
1319 last = avio_rb32(s->pb);
1320 if (!flv->trust_datasize) {
1321 if (last != orig_size + 11 && last != orig_size + 10 &&
1322 !avio_feof(s->pb) &&
1323 (last != orig_size || !last) && last != flv->sum_flv_tag_size &&
1324 !flv->broken_sizes) {
1325 av_log(s, AV_LOG_ERROR, "Packet mismatch %d %d %d\n", last, orig_size + 11, flv->sum_flv_tag_size);
1326 avio_seek(s->pb, pos + 1, SEEK_SET);
1328 av_packet_unref(pkt);
1336 flv->last_ts = pkt->dts;
1341 static int flv_read_seek(AVFormatContext *s, int stream_index,
1342 int64_t ts, int flags)
1344 FLVContext *flv = s->priv_data;
1345 flv->validate_count = 0;
1346 return avio_seek_time(s->pb, stream_index, ts, flags);
1349 #define OFFSET(x) offsetof(FLVContext, x)
1350 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1351 static const AVOption options[] = {
1352 { "flv_metadata", "Allocate streams according to the onMetaData array", OFFSET(trust_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1353 { "flv_full_metadata", "Dump full metadata of the onMetadata", OFFSET(dump_full_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1354 { "flv_ignore_prevtag", "Ignore the Size of previous tag", OFFSET(trust_datasize), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1355 { "missing_streams", "", OFFSET(missing_streams), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0xFF, VD | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
1359 static const AVClass flv_class = {
1360 .class_name = "flvdec",
1361 .item_name = av_default_item_name,
1363 .version = LIBAVUTIL_VERSION_INT,
1366 AVInputFormat ff_flv_demuxer = {
1368 .long_name = NULL_IF_CONFIG_SMALL("FLV (Flash Video)"),
1369 .priv_data_size = sizeof(FLVContext),
1370 .read_probe = flv_probe,
1371 .read_header = flv_read_header,
1372 .read_packet = flv_read_packet,
1373 .read_seek = flv_read_seek,
1374 .read_close = flv_read_close,
1375 .extensions = "flv",
1376 .priv_class = &flv_class,
1379 static const AVClass live_flv_class = {
1380 .class_name = "live_flvdec",
1381 .item_name = av_default_item_name,
1383 .version = LIBAVUTIL_VERSION_INT,
1386 AVInputFormat ff_live_flv_demuxer = {
1388 .long_name = NULL_IF_CONFIG_SMALL("live RTMP FLV (Flash Video)"),
1389 .priv_data_size = sizeof(FLVContext),
1390 .read_probe = live_flv_probe,
1391 .read_header = flv_read_header,
1392 .read_packet = flv_read_packet,
1393 .read_seek = flv_read_seek,
1394 .read_close = flv_read_close,
1395 .extensions = "flv",
1396 .priv_class = &live_flv_class,
1397 .flags = AVFMT_TS_DISCONT
1400 static const AVClass kux_class = {
1401 .class_name = "kuxdec",
1402 .item_name = av_default_item_name,
1404 .version = LIBAVUTIL_VERSION_INT,
1407 AVInputFormat ff_kux_demuxer = {
1409 .long_name = NULL_IF_CONFIG_SMALL("KUX (YouKu)"),
1410 .priv_data_size = sizeof(FLVContext),
1411 .read_probe = kux_probe,
1412 .read_header = flv_read_header,
1413 .read_packet = flv_read_packet,
1414 .read_seek = flv_read_seek,
1415 .read_close = flv_read_close,
1416 .extensions = "kux",
1417 .priv_class = &kux_class,