]> git.sesse.net Git - ffmpeg/blob - libavformat/flvenc.c
ff6d14a24841426cf8a9b5fb02e1f54a9f121df8
[ffmpeg] / libavformat / flvenc.c
1 /*
2  * FLV muxer
3  * Copyright (c) 2003 The Libav Project
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include "libavutil/dict.h"
23 #include "libavutil/intfloat.h"
24 #include "avc.h"
25 #include "avformat.h"
26 #include "flv.h"
27 #include "internal.h"
28 #include "metadata.h"
29
30 #undef NDEBUG
31 #include <assert.h>
32
33 static const AVCodecTag flv_video_codec_ids[] = {
34     { AV_CODEC_ID_FLV1,     FLV_CODECID_H263 },
35     { AV_CODEC_ID_FLASHSV,  FLV_CODECID_SCREEN },
36     { AV_CODEC_ID_FLASHSV2, FLV_CODECID_SCREEN2 },
37     { AV_CODEC_ID_VP6F,     FLV_CODECID_VP6 },
38     { AV_CODEC_ID_VP6,      FLV_CODECID_VP6 },
39     { AV_CODEC_ID_H264,     FLV_CODECID_H264 },
40     { AV_CODEC_ID_NONE,     0 }
41 };
42
43 static const AVCodecTag flv_audio_codec_ids[] = {
44     { AV_CODEC_ID_MP3,        FLV_CODECID_MP3        >> FLV_AUDIO_CODECID_OFFSET },
45     { AV_CODEC_ID_PCM_U8,     FLV_CODECID_PCM        >> FLV_AUDIO_CODECID_OFFSET },
46     { AV_CODEC_ID_PCM_S16BE,  FLV_CODECID_PCM        >> FLV_AUDIO_CODECID_OFFSET },
47     { AV_CODEC_ID_PCM_S16LE,  FLV_CODECID_PCM_LE     >> FLV_AUDIO_CODECID_OFFSET },
48     { AV_CODEC_ID_ADPCM_SWF,  FLV_CODECID_ADPCM      >> FLV_AUDIO_CODECID_OFFSET },
49     { AV_CODEC_ID_AAC,        FLV_CODECID_AAC        >> FLV_AUDIO_CODECID_OFFSET },
50     { AV_CODEC_ID_NELLYMOSER, FLV_CODECID_NELLYMOSER >> FLV_AUDIO_CODECID_OFFSET },
51     { AV_CODEC_ID_PCM_MULAW,  FLV_CODECID_PCM_MULAW  >> FLV_AUDIO_CODECID_OFFSET },
52     { AV_CODEC_ID_PCM_ALAW,   FLV_CODECID_PCM_ALAW   >> FLV_AUDIO_CODECID_OFFSET },
53     { AV_CODEC_ID_SPEEX,      FLV_CODECID_SPEEX      >> FLV_AUDIO_CODECID_OFFSET },
54     { AV_CODEC_ID_NONE,       0 }
55 };
56
57 typedef struct FLVContext {
58     int     reserved;
59     int64_t duration_offset;
60     int64_t filesize_offset;
61     int64_t duration;
62     int64_t delay;      ///< first dts delay (needed for AVC & Speex)
63 } FLVContext;
64
65 typedef struct FLVStreamContext {
66     int64_t last_ts;    ///< last timestamp for each stream
67 } FLVStreamContext;
68
69 static int get_audio_flags(AVFormatContext *s, AVCodecContext *enc)
70 {
71     int flags = (enc->bits_per_coded_sample == 16) ? FLV_SAMPLESSIZE_16BIT
72                                                    : FLV_SAMPLESSIZE_8BIT;
73
74     if (enc->codec_id == AV_CODEC_ID_AAC) // specs force these parameters
75         return FLV_CODECID_AAC | FLV_SAMPLERATE_44100HZ |
76                FLV_SAMPLESSIZE_16BIT | FLV_STEREO;
77     else if (enc->codec_id == AV_CODEC_ID_SPEEX) {
78         if (enc->sample_rate != 16000) {
79             av_log(s, AV_LOG_ERROR,
80                    "flv only supports wideband (16kHz) Speex audio\n");
81             return -1;
82         }
83         if (enc->channels != 1) {
84             av_log(s, AV_LOG_ERROR, "flv only supports mono Speex audio\n");
85             return -1;
86         }
87         return FLV_CODECID_SPEEX | FLV_SAMPLERATE_11025HZ | FLV_SAMPLESSIZE_16BIT;
88     } else {
89         switch (enc->sample_rate) {
90         case 44100:
91             flags |= FLV_SAMPLERATE_44100HZ;
92             break;
93         case 22050:
94             flags |= FLV_SAMPLERATE_22050HZ;
95             break;
96         case 11025:
97             flags |= FLV_SAMPLERATE_11025HZ;
98             break;
99         case 16000: // nellymoser only
100         case  8000: // nellymoser only
101         case  5512: // not MP3
102             if (enc->codec_id != AV_CODEC_ID_MP3) {
103                 flags |= FLV_SAMPLERATE_SPECIAL;
104                 break;
105             }
106         default:
107             av_log(s, AV_LOG_ERROR,
108                    "flv does not support that sample rate, "
109                    "choose from (44100, 22050, 11025).\n");
110             return -1;
111         }
112     }
113
114     if (enc->channels > 1)
115         flags |= FLV_STEREO;
116
117     switch (enc->codec_id) {
118     case AV_CODEC_ID_MP3:
119         flags |= FLV_CODECID_MP3    | FLV_SAMPLESSIZE_16BIT;
120         break;
121     case AV_CODEC_ID_PCM_U8:
122         flags |= FLV_CODECID_PCM    | FLV_SAMPLESSIZE_8BIT;
123         break;
124     case AV_CODEC_ID_PCM_S16BE:
125         flags |= FLV_CODECID_PCM    | FLV_SAMPLESSIZE_16BIT;
126         break;
127     case AV_CODEC_ID_PCM_S16LE:
128         flags |= FLV_CODECID_PCM_LE | FLV_SAMPLESSIZE_16BIT;
129         break;
130     case AV_CODEC_ID_ADPCM_SWF:
131         flags |= FLV_CODECID_ADPCM  | FLV_SAMPLESSIZE_16BIT;
132         break;
133     case AV_CODEC_ID_NELLYMOSER:
134         if (enc->sample_rate == 8000)
135             flags |= FLV_CODECID_NELLYMOSER_8KHZ_MONO  | FLV_SAMPLESSIZE_16BIT;
136         else if (enc->sample_rate == 16000)
137             flags |= FLV_CODECID_NELLYMOSER_16KHZ_MONO | FLV_SAMPLESSIZE_16BIT;
138         else
139             flags |= FLV_CODECID_NELLYMOSER            | FLV_SAMPLESSIZE_16BIT;
140         break;
141     case AV_CODEC_ID_PCM_MULAW:
142         flags = FLV_CODECID_PCM_MULAW | FLV_SAMPLERATE_SPECIAL | FLV_SAMPLESSIZE_16BIT;
143         break;
144     case AV_CODEC_ID_PCM_ALAW:
145         flags = FLV_CODECID_PCM_ALAW  | FLV_SAMPLERATE_SPECIAL | FLV_SAMPLESSIZE_16BIT;
146         break;
147     case 0:
148         flags |= enc->codec_tag << 4;
149         break;
150     default:
151         av_log(s, AV_LOG_ERROR, "codec not compatible with flv\n");
152         return -1;
153     }
154
155     return flags;
156 }
157
158 static void put_amf_string(AVIOContext *pb, const char *str)
159 {
160     size_t len = strlen(str);
161     avio_wb16(pb, len);
162     avio_write(pb, str, len);
163 }
164
165 static void put_avc_eos_tag(AVIOContext *pb, unsigned ts)
166 {
167     avio_w8(pb, FLV_TAG_TYPE_VIDEO);
168     avio_wb24(pb, 5);               /* Tag Data Size */
169     avio_wb24(pb, ts);              /* lower 24 bits of timestamp in ms */
170     avio_w8(pb, (ts >> 24) & 0x7F); /* MSB of ts in ms */
171     avio_wb24(pb, 0);               /* StreamId = 0 */
172     avio_w8(pb, 23);                /* ub[4] FrameType = 1, ub[4] CodecId = 7 */
173     avio_w8(pb, 2);                 /* AVC end of sequence */
174     avio_wb24(pb, 0);               /* Always 0 for AVC EOS. */
175     avio_wb32(pb, 16);              /* Size of FLV tag */
176 }
177
178 static void put_amf_double(AVIOContext *pb, double d)
179 {
180     avio_w8(pb, AMF_DATA_TYPE_NUMBER);
181     avio_wb64(pb, av_double2int(d));
182 }
183
184 static void put_amf_bool(AVIOContext *pb, int b)
185 {
186     avio_w8(pb, AMF_DATA_TYPE_BOOL);
187     avio_w8(pb, !!b);
188 }
189
190 static int flv_write_header(AVFormatContext *s)
191 {
192     AVIOContext *pb = s->pb;
193     FLVContext *flv = s->priv_data;
194     AVCodecContext *audio_enc = NULL, *video_enc = NULL, *data_enc = NULL;
195     int i, metadata_count = 0;
196     double framerate = 0.0;
197     int64_t metadata_size_pos, data_size, metadata_count_pos;
198     AVDictionaryEntry *tag = NULL;
199
200     for (i = 0; i < s->nb_streams; i++) {
201         AVCodecContext *enc = s->streams[i]->codec;
202         FLVStreamContext *sc;
203         switch (enc->codec_type) {
204         case AVMEDIA_TYPE_VIDEO:
205             if (s->streams[i]->avg_frame_rate.den &&
206                 s->streams[i]->avg_frame_rate.num) {
207                 framerate = av_q2d(s->streams[i]->avg_frame_rate);
208             } else {
209                 framerate = 1 / av_q2d(s->streams[i]->codec->time_base);
210             }
211             video_enc = enc;
212             if (enc->codec_tag == 0) {
213                 av_log(s, AV_LOG_ERROR, "video codec not compatible with flv\n");
214                 return -1;
215             }
216             break;
217         case AVMEDIA_TYPE_AUDIO:
218             audio_enc = enc;
219             if (get_audio_flags(s, enc) < 0)
220                 return AVERROR_INVALIDDATA;
221             break;
222         case AVMEDIA_TYPE_DATA:
223             if (enc->codec_id != AV_CODEC_ID_TEXT) {
224                 av_log(s, AV_LOG_ERROR, "codec not compatible with flv\n");
225                 return AVERROR_INVALIDDATA;
226             }
227             data_enc = enc;
228             break;
229         default:
230             av_log(s, AV_LOG_ERROR, "codec not compatible with flv\n");
231             return -1;
232         }
233         avpriv_set_pts_info(s->streams[i], 32, 1, 1000); /* 32 bit pts in ms */
234
235         sc = av_mallocz(sizeof(FLVStreamContext));
236         if (!sc)
237             return AVERROR(ENOMEM);
238         s->streams[i]->priv_data = sc;
239         sc->last_ts = -1;
240     }
241
242     flv->delay = AV_NOPTS_VALUE;
243
244     avio_write(pb, "FLV", 3);
245     avio_w8(pb, 1);
246     avio_w8(pb, FLV_HEADER_FLAG_HASAUDIO * !!audio_enc +
247                 FLV_HEADER_FLAG_HASVIDEO * !!video_enc);
248     avio_wb32(pb, 9);
249     avio_wb32(pb, 0);
250
251     for (i = 0; i < s->nb_streams; i++)
252         if (s->streams[i]->codec->codec_tag == 5) {
253             avio_w8(pb, 8);     // message type
254             avio_wb24(pb, 0);   // include flags
255             avio_wb24(pb, 0);   // time stamp
256             avio_wb32(pb, 0);   // reserved
257             avio_wb32(pb, 11);  // size
258             flv->reserved = 5;
259         }
260
261     /* write meta_tag */
262     avio_w8(pb, 18);            // tag type META
263     metadata_size_pos = avio_tell(pb);
264     avio_wb24(pb, 0);           // size of data part (sum of all parts below)
265     avio_wb24(pb, 0);           // timestamp
266     avio_wb32(pb, 0);           // reserved
267
268     /* now data of data_size size */
269
270     /* first event name as a string */
271     avio_w8(pb, AMF_DATA_TYPE_STRING);
272     put_amf_string(pb, "onMetaData"); // 12 bytes
273
274     /* mixed array (hash) with size and string/type/data tuples */
275     avio_w8(pb, AMF_DATA_TYPE_MIXEDARRAY);
276     metadata_count_pos = avio_tell(pb);
277     metadata_count = 5 * !!video_enc +
278                      5 * !!audio_enc +
279                      1 * !!data_enc  +
280                      2; // +2 for duration and file size
281
282     avio_wb32(pb, metadata_count);
283
284     put_amf_string(pb, "duration");
285     flv->duration_offset= avio_tell(pb);
286
287     // fill in the guessed duration, it'll be corrected later if incorrect
288     put_amf_double(pb, s->duration / AV_TIME_BASE);
289
290     if (video_enc) {
291         put_amf_string(pb, "width");
292         put_amf_double(pb, video_enc->width);
293
294         put_amf_string(pb, "height");
295         put_amf_double(pb, video_enc->height);
296
297         put_amf_string(pb, "videodatarate");
298         put_amf_double(pb, video_enc->bit_rate / 1024.0);
299
300         put_amf_string(pb, "framerate");
301         put_amf_double(pb, framerate);
302
303         put_amf_string(pb, "videocodecid");
304         put_amf_double(pb, video_enc->codec_tag);
305     }
306
307     if (audio_enc) {
308         put_amf_string(pb, "audiodatarate");
309         put_amf_double(pb, audio_enc->bit_rate / 1024.0);
310
311         put_amf_string(pb, "audiosamplerate");
312         put_amf_double(pb, audio_enc->sample_rate);
313
314         put_amf_string(pb, "audiosamplesize");
315         put_amf_double(pb, audio_enc->codec_id == AV_CODEC_ID_PCM_U8 ? 8 : 16);
316
317         put_amf_string(pb, "stereo");
318         put_amf_bool(pb, audio_enc->channels == 2);
319
320         put_amf_string(pb, "audiocodecid");
321         put_amf_double(pb, audio_enc->codec_tag);
322     }
323
324     if (data_enc) {
325         put_amf_string(pb, "datastream");
326         put_amf_double(pb, 0.0);
327     }
328
329     while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
330         put_amf_string(pb, tag->key);
331         avio_w8(pb, AMF_DATA_TYPE_STRING);
332         put_amf_string(pb, tag->value);
333         metadata_count++;
334     }
335
336     put_amf_string(pb, "filesize");
337     flv->filesize_offset = avio_tell(pb);
338     put_amf_double(pb, 0); // delayed write
339
340     put_amf_string(pb, "");
341     avio_w8(pb, AMF_END_OF_OBJECT);
342
343     /* write total size of tag */
344     data_size = avio_tell(pb) - metadata_size_pos - 10;
345
346     avio_seek(pb, metadata_count_pos, SEEK_SET);
347     avio_wb32(pb, metadata_count);
348
349     avio_seek(pb, metadata_size_pos, SEEK_SET);
350     avio_wb24(pb, data_size);
351     avio_skip(pb, data_size + 10 - 3);
352     avio_wb32(pb, data_size + 11);
353
354     for (i = 0; i < s->nb_streams; i++) {
355         AVCodecContext *enc = s->streams[i]->codec;
356         if (enc->codec_id == AV_CODEC_ID_AAC || enc->codec_id == AV_CODEC_ID_H264) {
357             int64_t pos;
358             avio_w8(pb, enc->codec_type == AVMEDIA_TYPE_VIDEO ?
359                     FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO);
360             avio_wb24(pb, 0); // size patched later
361             avio_wb24(pb, 0); // ts
362             avio_w8(pb, 0);   // ts ext
363             avio_wb24(pb, 0); // streamid
364             pos = avio_tell(pb);
365             if (enc->codec_id == AV_CODEC_ID_AAC) {
366                 avio_w8(pb, get_audio_flags(s, enc));
367                 avio_w8(pb, 0); // AAC sequence header
368                 avio_write(pb, enc->extradata, enc->extradata_size);
369             } else {
370                 avio_w8(pb, enc->codec_tag | FLV_FRAME_KEY); // flags
371                 avio_w8(pb, 0); // AVC sequence header
372                 avio_wb24(pb, 0); // composition time
373                 ff_isom_write_avcc(pb, enc->extradata, enc->extradata_size);
374             }
375             data_size = avio_tell(pb) - pos;
376             avio_seek(pb, -data_size - 10, SEEK_CUR);
377             avio_wb24(pb, data_size);
378             avio_skip(pb, data_size + 10 - 3);
379             avio_wb32(pb, data_size + 11); // previous tag size
380         }
381     }
382
383     return 0;
384 }
385
386 static int flv_write_trailer(AVFormatContext *s)
387 {
388     int64_t file_size;
389
390     AVIOContext *pb = s->pb;
391     FLVContext *flv = s->priv_data;
392     int i;
393
394     /* Add EOS tag */
395     for (i = 0; i < s->nb_streams; i++) {
396         AVCodecContext *enc = s->streams[i]->codec;
397         FLVStreamContext *sc = s->streams[i]->priv_data;
398         if (enc->codec_type == AVMEDIA_TYPE_VIDEO &&
399             enc->codec_id == AV_CODEC_ID_H264)
400             put_avc_eos_tag(pb, sc->last_ts);
401     }
402
403     file_size = avio_tell(pb);
404
405     /* update information */
406     if (avio_seek(pb, flv->duration_offset, SEEK_SET) < 0)
407         av_log(s, AV_LOG_WARNING, "Failed to update header with correct duration.\n");
408     else
409         put_amf_double(pb, flv->duration / (double)1000);
410     if (avio_seek(pb, flv->filesize_offset, SEEK_SET) < 0)
411         av_log(s, AV_LOG_WARNING, "Failed to update header with correct filesize.\n");
412     else
413         put_amf_double(pb, file_size);
414
415     avio_seek(pb, file_size, SEEK_SET);
416     return 0;
417 }
418
419 static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
420 {
421     AVIOContext *pb      = s->pb;
422     AVCodecContext *enc  = s->streams[pkt->stream_index]->codec;
423     FLVContext *flv      = s->priv_data;
424     FLVStreamContext *sc = s->streams[pkt->stream_index]->priv_data;
425     unsigned ts;
426     int size = pkt->size;
427     uint8_t *data = NULL;
428     int flags = 0, flags_size;
429
430     if (enc->codec_id == AV_CODEC_ID_VP6 || enc->codec_id == AV_CODEC_ID_VP6F ||
431         enc->codec_id == AV_CODEC_ID_AAC)
432         flags_size = 2;
433     else if (enc->codec_id == AV_CODEC_ID_H264)
434         flags_size = 5;
435     else
436         flags_size = 1;
437
438     switch (enc->codec_type) {
439     case AVMEDIA_TYPE_VIDEO:
440         avio_w8(pb, FLV_TAG_TYPE_VIDEO);
441
442         flags = enc->codec_tag;
443         if (flags == 0) {
444             av_log(s, AV_LOG_ERROR,
445                    "video codec %X not compatible with flv\n",
446                    enc->codec_id);
447             return -1;
448         }
449
450         flags |= pkt->flags & AV_PKT_FLAG_KEY ? FLV_FRAME_KEY : FLV_FRAME_INTER;
451         break;
452     case AVMEDIA_TYPE_AUDIO:
453         flags = get_audio_flags(s, enc);
454
455         assert(size);
456
457         avio_w8(pb, FLV_TAG_TYPE_AUDIO);
458         break;
459     case AVMEDIA_TYPE_DATA:
460         avio_w8(pb, FLV_TAG_TYPE_META);
461         break;
462     default:
463         return AVERROR(EINVAL);
464     }
465
466     if (enc->codec_id == AV_CODEC_ID_H264)
467         /* check if extradata looks like MP4 */
468         if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1)
469             if (ff_avc_parse_nal_units_buf(pkt->data, &data, &size) < 0)
470                 return -1;
471
472     if (flv->delay == AV_NOPTS_VALUE)
473         flv->delay = -pkt->dts;
474
475     if (pkt->dts < -flv->delay) {
476         av_log(s, AV_LOG_WARNING,
477                "Packets are not in the proper order with respect to DTS\n");
478         return AVERROR(EINVAL);
479     }
480
481     ts = pkt->dts + flv->delay; // add delay to force positive dts
482
483     /* check Speex packet duration */
484     if (enc->codec_id == AV_CODEC_ID_SPEEX && ts - sc->last_ts > 160)
485         av_log(s, AV_LOG_WARNING, "Warning: Speex stream has more than "
486                                   "8 frames per packet. Adobe Flash "
487                                   "Player cannot handle this!\n");
488
489     if (sc->last_ts < ts)
490         sc->last_ts = ts;
491
492     avio_wb24(pb, size + flags_size);
493     avio_wb24(pb, ts);
494     avio_w8(pb, (ts >> 24) & 0x7F); // timestamps are 32 bits _signed_
495     avio_wb24(pb, flv->reserved);
496
497     if (enc->codec_type == AVMEDIA_TYPE_DATA) {
498         int data_size;
499         int metadata_size_pos = avio_tell(pb);
500         avio_w8(pb, AMF_DATA_TYPE_STRING);
501         put_amf_string(pb, "onTextData");
502         avio_w8(pb, AMF_DATA_TYPE_MIXEDARRAY);
503         avio_wb32(pb, 2);
504         put_amf_string(pb, "type");
505         avio_w8(pb, AMF_DATA_TYPE_STRING);
506         put_amf_string(pb, "Text");
507         put_amf_string(pb, "text");
508         avio_w8(pb, AMF_DATA_TYPE_STRING);
509         put_amf_string(pb, pkt->data);
510         put_amf_string(pb, "");
511         avio_w8(pb, AMF_END_OF_OBJECT);
512         /* write total size of tag */
513         data_size = avio_tell(pb) - metadata_size_pos;
514         avio_seek(pb, metadata_size_pos - 10, SEEK_SET);
515         avio_wb24(pb, data_size);
516         avio_seek(pb, data_size + 10 - 3, SEEK_CUR);
517         avio_wb32(pb, data_size + 11);
518     } else {
519         avio_w8(pb,flags);
520         if (enc->codec_id == AV_CODEC_ID_VP6)
521             avio_w8(pb, 0);
522         if (enc->codec_id == AV_CODEC_ID_VP6F)
523             avio_w8(pb, enc->extradata_size ? enc->extradata[0] : 0);
524         else if (enc->codec_id == AV_CODEC_ID_AAC)
525             avio_w8(pb, 1); // AAC raw
526         else if (enc->codec_id == AV_CODEC_ID_H264) {
527             avio_w8(pb, 1); // AVC NALU
528             avio_wb24(pb, pkt->pts - pkt->dts);
529         }
530
531         avio_write(pb, data ? data : pkt->data, size);
532
533         avio_wb32(pb, size + flags_size + 11); // previous tag size
534         flv->duration = FFMAX(flv->duration,
535                               pkt->pts + flv->delay + pkt->duration);
536     }
537
538     avio_flush(pb);
539     av_free(data);
540
541     return pb->error;
542 }
543
544 AVOutputFormat ff_flv_muxer = {
545     .name           = "flv",
546     .long_name      = NULL_IF_CONFIG_SMALL("FLV (Flash Video)"),
547     .mime_type      = "video/x-flv",
548     .extensions     = "flv",
549     .priv_data_size = sizeof(FLVContext),
550     .audio_codec    = CONFIG_LIBMP3LAME ? AV_CODEC_ID_MP3 : AV_CODEC_ID_ADPCM_SWF,
551     .video_codec    = AV_CODEC_ID_FLV1,
552     .write_header   = flv_write_header,
553     .write_packet   = flv_write_packet,
554     .write_trailer  = flv_write_trailer,
555     .codec_tag      = (const AVCodecTag* const []) {
556                           flv_video_codec_ids, flv_audio_codec_ids, 0
557                       },
558     .flags          = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS |
559                       AVFMT_TS_NONSTRICT,
560 };