You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

560 lines
19KB

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