flvenc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. /*
  2. * FLV muxer
  3. * Copyright (c) 2003 The FFmpeg Project
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/intreadwrite.h"
  22. #include "libavutil/intfloat_readwrite.h"
  23. #include "avformat.h"
  24. #include "flv.h"
  25. #include "internal.h"
  26. #include "avc.h"
  27. #include "metadata.h"
  28. #include "libavutil/dict.h"
  29. #undef NDEBUG
  30. #include <assert.h>
  31. static const AVCodecTag flv_video_codec_ids[] = {
  32. {CODEC_ID_FLV1, FLV_CODECID_H263 },
  33. {CODEC_ID_H263, FLV_CODECID_REALH263},
  34. {CODEC_ID_MPEG4, FLV_CODECID_MPEG4 },
  35. {CODEC_ID_FLASHSV, FLV_CODECID_SCREEN},
  36. {CODEC_ID_FLASHSV2, FLV_CODECID_SCREEN2},
  37. {CODEC_ID_VP6F, FLV_CODECID_VP6 },
  38. {CODEC_ID_VP6, FLV_CODECID_VP6 },
  39. {CODEC_ID_H264, FLV_CODECID_H264 },
  40. {CODEC_ID_NONE, 0}
  41. };
  42. static const AVCodecTag flv_audio_codec_ids[] = {
  43. {CODEC_ID_MP3, FLV_CODECID_MP3 >> FLV_AUDIO_CODECID_OFFSET},
  44. {CODEC_ID_PCM_U8, FLV_CODECID_PCM >> FLV_AUDIO_CODECID_OFFSET},
  45. {CODEC_ID_PCM_S16BE, FLV_CODECID_PCM >> FLV_AUDIO_CODECID_OFFSET},
  46. {CODEC_ID_PCM_S16LE, FLV_CODECID_PCM_LE >> FLV_AUDIO_CODECID_OFFSET},
  47. {CODEC_ID_ADPCM_SWF, FLV_CODECID_ADPCM >> FLV_AUDIO_CODECID_OFFSET},
  48. {CODEC_ID_AAC, FLV_CODECID_AAC >> FLV_AUDIO_CODECID_OFFSET},
  49. {CODEC_ID_NELLYMOSER, FLV_CODECID_NELLYMOSER >> FLV_AUDIO_CODECID_OFFSET},
  50. {CODEC_ID_SPEEX, FLV_CODECID_SPEEX >> FLV_AUDIO_CODECID_OFFSET},
  51. {CODEC_ID_NONE, 0}
  52. };
  53. typedef struct FLVContext {
  54. int reserved;
  55. int64_t duration_offset;
  56. int64_t filesize_offset;
  57. int64_t duration;
  58. int64_t delay; ///< first dts delay (needed for AVC & Speex)
  59. } FLVContext;
  60. typedef struct FLVStreamContext {
  61. int64_t last_ts; ///< last timestamp for each stream
  62. } FLVStreamContext;
  63. static int get_audio_flags(AVCodecContext *enc){
  64. int flags = (enc->bits_per_coded_sample == 16) ? FLV_SAMPLESSIZE_16BIT : FLV_SAMPLESSIZE_8BIT;
  65. if (enc->codec_id == CODEC_ID_AAC) // specs force these parameters
  66. return FLV_CODECID_AAC | FLV_SAMPLERATE_44100HZ | FLV_SAMPLESSIZE_16BIT | FLV_STEREO;
  67. else if (enc->codec_id == CODEC_ID_SPEEX) {
  68. if (enc->sample_rate != 16000) {
  69. av_log(enc, AV_LOG_ERROR, "flv only supports wideband (16kHz) Speex audio\n");
  70. return -1;
  71. }
  72. if (enc->channels != 1) {
  73. av_log(enc, AV_LOG_ERROR, "flv only supports mono Speex audio\n");
  74. return -1;
  75. }
  76. return FLV_CODECID_SPEEX | FLV_SAMPLERATE_11025HZ | FLV_SAMPLESSIZE_16BIT;
  77. } else {
  78. switch (enc->sample_rate) {
  79. case 44100:
  80. flags |= FLV_SAMPLERATE_44100HZ;
  81. break;
  82. case 22050:
  83. flags |= FLV_SAMPLERATE_22050HZ;
  84. break;
  85. case 11025:
  86. flags |= FLV_SAMPLERATE_11025HZ;
  87. break;
  88. case 8000: //nellymoser only
  89. case 5512: //not mp3
  90. if(enc->codec_id != CODEC_ID_MP3){
  91. flags |= FLV_SAMPLERATE_SPECIAL;
  92. break;
  93. }
  94. default:
  95. av_log(enc, AV_LOG_ERROR, "flv does not support that sample rate, choose from (44100, 22050, 11025).\n");
  96. return -1;
  97. }
  98. }
  99. if (enc->channels > 1) {
  100. flags |= FLV_STEREO;
  101. }
  102. switch(enc->codec_id){
  103. case CODEC_ID_MP3:
  104. flags |= FLV_CODECID_MP3 | FLV_SAMPLESSIZE_16BIT;
  105. break;
  106. case CODEC_ID_PCM_U8:
  107. flags |= FLV_CODECID_PCM | FLV_SAMPLESSIZE_8BIT;
  108. break;
  109. case CODEC_ID_PCM_S16BE:
  110. flags |= FLV_CODECID_PCM | FLV_SAMPLESSIZE_16BIT;
  111. break;
  112. case CODEC_ID_PCM_S16LE:
  113. flags |= FLV_CODECID_PCM_LE | FLV_SAMPLESSIZE_16BIT;
  114. break;
  115. case CODEC_ID_ADPCM_SWF:
  116. flags |= FLV_CODECID_ADPCM | FLV_SAMPLESSIZE_16BIT;
  117. break;
  118. case CODEC_ID_NELLYMOSER:
  119. if (enc->sample_rate == 8000) {
  120. flags |= FLV_CODECID_NELLYMOSER_8KHZ_MONO | FLV_SAMPLESSIZE_16BIT;
  121. } else {
  122. flags |= FLV_CODECID_NELLYMOSER | FLV_SAMPLESSIZE_16BIT;
  123. }
  124. break;
  125. case 0:
  126. flags |= enc->codec_tag<<4;
  127. break;
  128. default:
  129. av_log(enc, AV_LOG_ERROR, "codec not compatible with flv\n");
  130. return -1;
  131. }
  132. return flags;
  133. }
  134. static void put_amf_string(AVIOContext *pb, const char *str)
  135. {
  136. size_t len = strlen(str);
  137. avio_wb16(pb, len);
  138. avio_write(pb, str, len);
  139. }
  140. static void put_avc_eos_tag(AVIOContext *pb, unsigned ts) {
  141. avio_w8(pb, FLV_TAG_TYPE_VIDEO);
  142. avio_wb24(pb, 5); /* Tag Data Size */
  143. avio_wb24(pb, ts); /* lower 24 bits of timestamp in ms*/
  144. avio_w8(pb, (ts >> 24) & 0x7F); /* MSB of ts in ms*/
  145. avio_wb24(pb, 0); /* StreamId = 0 */
  146. avio_w8(pb, 23); /* ub[4] FrameType = 1, ub[4] CodecId = 7 */
  147. avio_w8(pb, 2); /* AVC end of sequence */
  148. avio_wb24(pb, 0); /* Always 0 for AVC EOS. */
  149. avio_wb32(pb, 16); /* Size of FLV tag */
  150. }
  151. static void put_amf_double(AVIOContext *pb, double d)
  152. {
  153. avio_w8(pb, AMF_DATA_TYPE_NUMBER);
  154. avio_wb64(pb, av_dbl2int(d));
  155. }
  156. static void put_amf_bool(AVIOContext *pb, int b) {
  157. avio_w8(pb, AMF_DATA_TYPE_BOOL);
  158. avio_w8(pb, !!b);
  159. }
  160. static int flv_write_header(AVFormatContext *s)
  161. {
  162. AVIOContext *pb = s->pb;
  163. FLVContext *flv = s->priv_data;
  164. AVCodecContext *audio_enc = NULL, *video_enc = NULL;
  165. int i, metadata_count = 0;
  166. double framerate = 0.0;
  167. int64_t metadata_size_pos, data_size, metadata_count_pos;
  168. AVDictionaryEntry *tag = NULL;
  169. for(i=0; i<s->nb_streams; i++){
  170. AVCodecContext *enc = s->streams[i]->codec;
  171. FLVStreamContext *sc;
  172. if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
  173. if (s->streams[i]->r_frame_rate.den && s->streams[i]->r_frame_rate.num) {
  174. framerate = av_q2d(s->streams[i]->r_frame_rate);
  175. } else {
  176. framerate = 1/av_q2d(s->streams[i]->codec->time_base);
  177. }
  178. video_enc = enc;
  179. if(enc->codec_tag == 0) {
  180. av_log(enc, AV_LOG_ERROR, "video codec not compatible with flv\n");
  181. return -1;
  182. }
  183. } else if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
  184. audio_enc = enc;
  185. if(get_audio_flags(enc)<0)
  186. return -1;
  187. }
  188. av_set_pts_info(s->streams[i], 32, 1, 1000); /* 32 bit pts in ms */
  189. sc = av_mallocz(sizeof(FLVStreamContext));
  190. if (!sc)
  191. return AVERROR(ENOMEM);
  192. s->streams[i]->priv_data = sc;
  193. sc->last_ts = -1;
  194. }
  195. flv->delay = AV_NOPTS_VALUE;
  196. avio_write(pb, "FLV", 3);
  197. avio_w8(pb,1);
  198. avio_w8(pb, FLV_HEADER_FLAG_HASAUDIO * !!audio_enc
  199. + FLV_HEADER_FLAG_HASVIDEO * !!video_enc);
  200. avio_wb32(pb,9);
  201. avio_wb32(pb,0);
  202. for(i=0; i<s->nb_streams; i++){
  203. if(s->streams[i]->codec->codec_tag == 5){
  204. avio_w8(pb,8); // message type
  205. avio_wb24(pb,0); // include flags
  206. avio_wb24(pb,0); // time stamp
  207. avio_wb32(pb,0); // reserved
  208. avio_wb32(pb,11); // size
  209. flv->reserved=5;
  210. }
  211. }
  212. /* write meta_tag */
  213. avio_w8(pb, 18); // tag type META
  214. metadata_size_pos= avio_tell(pb);
  215. avio_wb24(pb, 0); // size of data part (sum of all parts below)
  216. avio_wb24(pb, 0); // time stamp
  217. avio_wb32(pb, 0); // reserved
  218. /* now data of data_size size */
  219. /* first event name as a string */
  220. avio_w8(pb, AMF_DATA_TYPE_STRING);
  221. put_amf_string(pb, "onMetaData"); // 12 bytes
  222. /* mixed array (hash) with size and string/type/data tuples */
  223. avio_w8(pb, AMF_DATA_TYPE_MIXEDARRAY);
  224. metadata_count_pos = avio_tell(pb);
  225. metadata_count = 5*!!video_enc + 5*!!audio_enc + 2; // +2 for duration and file size
  226. avio_wb32(pb, metadata_count);
  227. put_amf_string(pb, "duration");
  228. flv->duration_offset= avio_tell(pb);
  229. put_amf_double(pb, s->duration / AV_TIME_BASE); // fill in the guessed duration, it'll be corrected later if incorrect
  230. if(video_enc){
  231. put_amf_string(pb, "width");
  232. put_amf_double(pb, video_enc->width);
  233. put_amf_string(pb, "height");
  234. put_amf_double(pb, video_enc->height);
  235. put_amf_string(pb, "videodatarate");
  236. put_amf_double(pb, video_enc->bit_rate / 1024.0);
  237. put_amf_string(pb, "framerate");
  238. put_amf_double(pb, framerate);
  239. put_amf_string(pb, "videocodecid");
  240. put_amf_double(pb, video_enc->codec_tag);
  241. }
  242. if(audio_enc){
  243. put_amf_string(pb, "audiodatarate");
  244. put_amf_double(pb, audio_enc->bit_rate / 1024.0);
  245. put_amf_string(pb, "audiosamplerate");
  246. put_amf_double(pb, audio_enc->sample_rate);
  247. put_amf_string(pb, "audiosamplesize");
  248. put_amf_double(pb, audio_enc->codec_id == CODEC_ID_PCM_U8 ? 8 : 16);
  249. put_amf_string(pb, "stereo");
  250. put_amf_bool(pb, audio_enc->channels == 2);
  251. put_amf_string(pb, "audiocodecid");
  252. put_amf_double(pb, audio_enc->codec_tag);
  253. }
  254. while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
  255. if( !strcmp(tag->key, "width")
  256. ||!strcmp(tag->key, "height")
  257. ||!strcmp(tag->key, "videodatarate")
  258. ||!strcmp(tag->key, "framerate")
  259. ||!strcmp(tag->key, "videocodecid")
  260. ||!strcmp(tag->key, "audiodatarate")
  261. ||!strcmp(tag->key, "audiosamplerate")
  262. ||!strcmp(tag->key, "audiosamplesize")
  263. ||!strcmp(tag->key, "stereo")
  264. ||!strcmp(tag->key, "audiocodecid")
  265. ||!strcmp(tag->key, "duration")
  266. ||!strcmp(tag->key, "onMetaData")
  267. ){
  268. av_log(s, AV_LOG_DEBUG, "ignoring metadata for %s\n", tag->key);
  269. continue;
  270. }
  271. put_amf_string(pb, tag->key);
  272. avio_w8(pb, AMF_DATA_TYPE_STRING);
  273. put_amf_string(pb, tag->value);
  274. metadata_count++;
  275. }
  276. put_amf_string(pb, "filesize");
  277. flv->filesize_offset= avio_tell(pb);
  278. put_amf_double(pb, 0); // delayed write
  279. put_amf_string(pb, "");
  280. avio_w8(pb, AMF_END_OF_OBJECT);
  281. /* write total size of tag */
  282. data_size= avio_tell(pb) - metadata_size_pos - 10;
  283. avio_seek(pb, metadata_count_pos, SEEK_SET);
  284. avio_wb32(pb, metadata_count);
  285. avio_seek(pb, metadata_size_pos, SEEK_SET);
  286. avio_wb24(pb, data_size);
  287. avio_skip(pb, data_size + 10 - 3);
  288. avio_wb32(pb, data_size + 11);
  289. for (i = 0; i < s->nb_streams; i++) {
  290. AVCodecContext *enc = s->streams[i]->codec;
  291. if (enc->codec_id == CODEC_ID_AAC || enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4) {
  292. int64_t pos;
  293. avio_w8(pb, enc->codec_type == AVMEDIA_TYPE_VIDEO ?
  294. FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO);
  295. avio_wb24(pb, 0); // size patched later
  296. avio_wb24(pb, 0); // ts
  297. avio_w8(pb, 0); // ts ext
  298. avio_wb24(pb, 0); // streamid
  299. pos = avio_tell(pb);
  300. if (enc->codec_id == CODEC_ID_AAC) {
  301. avio_w8(pb, get_audio_flags(enc));
  302. avio_w8(pb, 0); // AAC sequence header
  303. avio_write(pb, enc->extradata, enc->extradata_size);
  304. } else {
  305. avio_w8(pb, enc->codec_tag | FLV_FRAME_KEY); // flags
  306. avio_w8(pb, 0); // AVC sequence header
  307. avio_wb24(pb, 0); // composition time
  308. ff_isom_write_avcc(pb, enc->extradata, enc->extradata_size);
  309. }
  310. data_size = avio_tell(pb) - pos;
  311. avio_seek(pb, -data_size - 10, SEEK_CUR);
  312. avio_wb24(pb, data_size);
  313. avio_skip(pb, data_size + 10 - 3);
  314. avio_wb32(pb, data_size + 11); // previous tag size
  315. }
  316. }
  317. return 0;
  318. }
  319. static int flv_write_trailer(AVFormatContext *s)
  320. {
  321. int64_t file_size;
  322. AVIOContext *pb = s->pb;
  323. FLVContext *flv = s->priv_data;
  324. int i;
  325. /* Add EOS tag */
  326. for (i = 0; i < s->nb_streams; i++) {
  327. AVCodecContext *enc = s->streams[i]->codec;
  328. FLVStreamContext *sc = s->streams[i]->priv_data;
  329. if (enc->codec_type == AVMEDIA_TYPE_VIDEO &&
  330. (enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4)) {
  331. put_avc_eos_tag(pb, sc->last_ts);
  332. }
  333. }
  334. file_size = avio_tell(pb);
  335. /* update informations */
  336. avio_seek(pb, flv->duration_offset, SEEK_SET);
  337. put_amf_double(pb, flv->duration / (double)1000);
  338. avio_seek(pb, flv->filesize_offset, SEEK_SET);
  339. put_amf_double(pb, file_size);
  340. avio_seek(pb, file_size, SEEK_SET);
  341. return 0;
  342. }
  343. static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
  344. {
  345. AVIOContext *pb = s->pb;
  346. AVCodecContext *enc = s->streams[pkt->stream_index]->codec;
  347. FLVContext *flv = s->priv_data;
  348. FLVStreamContext *sc = s->streams[pkt->stream_index]->priv_data;
  349. unsigned ts;
  350. int size= pkt->size;
  351. uint8_t *data= NULL;
  352. int flags, flags_size;
  353. // av_log(s, AV_LOG_DEBUG, "type:%d pts: %"PRId64" size:%d\n", enc->codec_type, timestamp, size);
  354. if(enc->codec_id == CODEC_ID_VP6 || enc->codec_id == CODEC_ID_VP6F ||
  355. enc->codec_id == CODEC_ID_AAC)
  356. flags_size= 2;
  357. else if(enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4)
  358. flags_size= 5;
  359. else
  360. flags_size= 1;
  361. if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
  362. avio_w8(pb, FLV_TAG_TYPE_VIDEO);
  363. flags = enc->codec_tag;
  364. if(flags == 0) {
  365. av_log(enc, AV_LOG_ERROR, "video codec %s not compatible with flv\n", avcodec_get_name(enc->codec_id));
  366. return -1;
  367. }
  368. flags |= pkt->flags & AV_PKT_FLAG_KEY ? FLV_FRAME_KEY : FLV_FRAME_INTER;
  369. } else if (enc->codec_type == AVMEDIA_TYPE_AUDIO) {
  370. flags = get_audio_flags(enc);
  371. assert(size);
  372. avio_w8(pb, FLV_TAG_TYPE_AUDIO);
  373. } else {
  374. // In-band flv metadata ("scriptdata")
  375. assert(enc->codec_type == AVMEDIA_TYPE_DATA);
  376. avio_w8(pb, FLV_TAG_TYPE_META);
  377. flags_size = 0;
  378. flags = NULL;
  379. }
  380. if (enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4) {
  381. /* check if extradata looks like mp4 formated */
  382. if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) {
  383. if (ff_avc_parse_nal_units_buf(pkt->data, &data, &size) < 0)
  384. return -1;
  385. }
  386. } else if (enc->codec_id == CODEC_ID_AAC && pkt->size > 2 &&
  387. (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) {
  388. av_log(s, AV_LOG_ERROR, "malformated aac bitstream, use -absf aac_adtstoasc\n");
  389. return -1;
  390. }
  391. if (flv->delay == AV_NOPTS_VALUE)
  392. flv->delay = -pkt->dts;
  393. if (pkt->dts < -flv->delay) {
  394. av_log(s, AV_LOG_WARNING, "Packets are not in the proper order with "
  395. "respect to DTS\n");
  396. return AVERROR(EINVAL);
  397. }
  398. ts = pkt->dts + flv->delay; // add delay to force positive dts
  399. /* check Speex packet duration */
  400. if (enc->codec_id == CODEC_ID_SPEEX && ts - sc->last_ts > 160) {
  401. av_log(s, AV_LOG_WARNING, "Warning: Speex stream has more than "
  402. "8 frames per packet. Adobe Flash "
  403. "Player cannot handle this!\n");
  404. }
  405. if (sc->last_ts < ts)
  406. sc->last_ts = ts;
  407. avio_wb24(pb,size + flags_size);
  408. avio_wb24(pb,ts);
  409. avio_w8(pb,(ts >> 24) & 0x7F); // timestamps are 32bits _signed_
  410. avio_wb24(pb,flv->reserved);
  411. if(flags_size)
  412. avio_w8(pb,flags);
  413. if (enc->codec_id == CODEC_ID_VP6)
  414. avio_w8(pb,0);
  415. if (enc->codec_id == CODEC_ID_VP6F)
  416. avio_w8(pb, enc->extradata_size ? enc->extradata[0] : 0);
  417. else if (enc->codec_id == CODEC_ID_AAC)
  418. avio_w8(pb,1); // AAC raw
  419. else if (enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4) {
  420. avio_w8(pb,1); // AVC NALU
  421. avio_wb24(pb,pkt->pts - pkt->dts);
  422. }
  423. avio_write(pb, data ? data : pkt->data, size);
  424. avio_wb32(pb,size+flags_size+11); // previous tag size
  425. flv->duration = FFMAX(flv->duration, pkt->pts + flv->delay + pkt->duration);
  426. avio_flush(pb);
  427. av_free(data);
  428. return pb->error;
  429. }
  430. AVOutputFormat ff_flv_muxer = {
  431. .name = "flv",
  432. .long_name = NULL_IF_CONFIG_SMALL("FLV format"),
  433. .mime_type = "video/x-flv",
  434. .extensions = "flv",
  435. .priv_data_size = sizeof(FLVContext),
  436. #if CONFIG_LIBMP3LAME
  437. .audio_codec = CODEC_ID_MP3,
  438. #else // CONFIG_LIBMP3LAME
  439. .audio_codec = CODEC_ID_ADPCM_SWF,
  440. #endif // CONFIG_LIBMP3LAME
  441. .video_codec = CODEC_ID_FLV1,
  442. .write_header = flv_write_header,
  443. .write_packet = flv_write_packet,
  444. .write_trailer = flv_write_trailer,
  445. .codec_tag= (const AVCodecTag* const []){flv_video_codec_ids, flv_audio_codec_ids, 0},
  446. .flags= AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
  447. };