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.

628 lines
20KB

  1. /*
  2. * Ogg muxer
  3. * Copyright (c) 2007 Baptiste Coudurier <baptiste dot coudurier at free dot fr>
  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 <stdint.h>
  22. #include "libavutil/crc.h"
  23. #include "libavutil/mathematics.h"
  24. #include "libavutil/opt.h"
  25. #include "libavutil/random_seed.h"
  26. #include "libavcodec/xiph.h"
  27. #include "libavcodec/bytestream.h"
  28. #include "libavcodec/flac.h"
  29. #include "avformat.h"
  30. #include "avio_internal.h"
  31. #include "internal.h"
  32. #include "vorbiscomment.h"
  33. #define MAX_PAGE_SIZE 65025
  34. typedef struct {
  35. int64_t start_granule;
  36. int64_t granule;
  37. int stream_index;
  38. uint8_t flags;
  39. uint8_t segments_count;
  40. uint8_t segments[255];
  41. uint8_t data[MAX_PAGE_SIZE];
  42. uint16_t size;
  43. } OGGPage;
  44. typedef struct {
  45. unsigned page_counter;
  46. uint8_t *header[3];
  47. int header_len[3];
  48. /** for theora granule */
  49. int kfgshift;
  50. int64_t last_kf_pts;
  51. int vrev;
  52. int eos;
  53. unsigned page_count; ///< number of page buffered
  54. OGGPage page; ///< current page
  55. unsigned serial_num; ///< serial number
  56. int64_t last_granule; ///< last packet granule
  57. } OGGStreamContext;
  58. typedef struct OGGPageList {
  59. OGGPage page;
  60. struct OGGPageList *next;
  61. } OGGPageList;
  62. typedef struct {
  63. const AVClass *class;
  64. OGGPageList *page_list;
  65. int pref_size; ///< preferred page size (0 => fill all segments)
  66. int64_t pref_duration; ///< preferred page duration (0 => fill all segments)
  67. } OGGContext;
  68. #define OFFSET(x) offsetof(OGGContext, x)
  69. #define PARAM AV_OPT_FLAG_ENCODING_PARAM
  70. static const AVOption options[] = {
  71. { "pagesize", "preferred page size in bytes (deprecated)",
  72. OFFSET(pref_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MAX_PAGE_SIZE, PARAM },
  73. { "page_duration", "preferred page duration, in microseconds",
  74. OFFSET(pref_duration), AV_OPT_TYPE_INT, { .i64 = 1000000 }, 0, INT64_MAX, PARAM },
  75. { NULL },
  76. };
  77. static const AVClass ogg_muxer_class = {
  78. .class_name = "Ogg muxer",
  79. .item_name = av_default_item_name,
  80. .option = options,
  81. .version = LIBAVUTIL_VERSION_INT,
  82. };
  83. static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset)
  84. {
  85. int64_t pos = avio_tell(pb);
  86. uint32_t checksum = ffio_get_checksum(pb);
  87. avio_seek(pb, crc_offset, SEEK_SET);
  88. avio_wb32(pb, checksum);
  89. avio_seek(pb, pos, SEEK_SET);
  90. }
  91. static int ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
  92. {
  93. OGGStreamContext *oggstream = s->streams[page->stream_index]->priv_data;
  94. AVIOContext *pb;
  95. int64_t crc_offset;
  96. int ret, size;
  97. uint8_t *buf;
  98. ret = avio_open_dyn_buf(&pb);
  99. if (ret < 0)
  100. return ret;
  101. ffio_init_checksum(pb, ff_crc04C11DB7_update, 0);
  102. ffio_wfourcc(pb, "OggS");
  103. avio_w8(pb, 0);
  104. avio_w8(pb, page->flags | extra_flags);
  105. avio_wl64(pb, page->granule);
  106. avio_wl32(pb, oggstream->serial_num);
  107. avio_wl32(pb, oggstream->page_counter++);
  108. crc_offset = avio_tell(pb);
  109. avio_wl32(pb, 0); // crc
  110. avio_w8(pb, page->segments_count);
  111. avio_write(pb, page->segments, page->segments_count);
  112. avio_write(pb, page->data, page->size);
  113. ogg_update_checksum(s, pb, crc_offset);
  114. avio_flush(pb);
  115. size = avio_close_dyn_buf(pb, &buf);
  116. if (size < 0)
  117. return size;
  118. avio_write(s->pb, buf, size);
  119. avio_flush(s->pb);
  120. av_free(buf);
  121. oggstream->page_count--;
  122. return 0;
  123. }
  124. static int64_t ogg_granule_to_timestamp(OGGStreamContext *oggstream, int64_t granule)
  125. {
  126. if (oggstream->kfgshift)
  127. return (granule>>oggstream->kfgshift) +
  128. (granule & ((1<<oggstream->kfgshift)-1));
  129. else
  130. return granule;
  131. }
  132. static int ogg_compare_granule(AVFormatContext *s, OGGPage *next, OGGPage *page)
  133. {
  134. AVStream *st2 = s->streams[next->stream_index];
  135. AVStream *st = s->streams[page->stream_index];
  136. int64_t next_granule, cur_granule;
  137. if (next->granule == -1 || page->granule == -1)
  138. return 0;
  139. next_granule = av_rescale_q(ogg_granule_to_timestamp(st2->priv_data, next->granule),
  140. st2->time_base, AV_TIME_BASE_Q);
  141. cur_granule = av_rescale_q(ogg_granule_to_timestamp(st->priv_data, page->granule),
  142. st ->time_base, AV_TIME_BASE_Q);
  143. return next_granule > cur_granule;
  144. }
  145. static int ogg_reset_cur_page(OGGStreamContext *oggstream)
  146. {
  147. oggstream->page.granule = -1;
  148. oggstream->page.flags = 0;
  149. oggstream->page.segments_count = 0;
  150. oggstream->page.size = 0;
  151. return 0;
  152. }
  153. static int ogg_buffer_page(AVFormatContext *s, OGGStreamContext *oggstream)
  154. {
  155. OGGContext *ogg = s->priv_data;
  156. OGGPageList **p = &ogg->page_list;
  157. OGGPageList *l = av_mallocz(sizeof(*l));
  158. if (!l)
  159. return AVERROR(ENOMEM);
  160. l->page = oggstream->page;
  161. oggstream->page.start_granule = oggstream->page.granule;
  162. oggstream->page_count++;
  163. ogg_reset_cur_page(oggstream);
  164. while (*p) {
  165. if (ogg_compare_granule(s, &(*p)->page, &l->page))
  166. break;
  167. p = &(*p)->next;
  168. }
  169. l->next = *p;
  170. *p = l;
  171. return 0;
  172. }
  173. static int ogg_buffer_data(AVFormatContext *s, AVStream *st,
  174. uint8_t *data, unsigned size, int64_t granule,
  175. int header)
  176. {
  177. OGGStreamContext *oggstream = st->priv_data;
  178. OGGContext *ogg = s->priv_data;
  179. int total_segments = size / 255 + 1;
  180. uint8_t *p = data;
  181. int i, segments, len, flush = 0;
  182. // Handles VFR by flushing page because this frame needs to have a timestamp
  183. if (st->codec->codec_id == AV_CODEC_ID_THEORA && !header &&
  184. ogg_granule_to_timestamp(oggstream, granule) >
  185. ogg_granule_to_timestamp(oggstream, oggstream->last_granule) + 1) {
  186. if (oggstream->page.granule != -1)
  187. ogg_buffer_page(s, oggstream);
  188. flush = 1;
  189. }
  190. // avoid a continued page
  191. if (!header && oggstream->page.size > 0 &&
  192. MAX_PAGE_SIZE - oggstream->page.size < size) {
  193. ogg_buffer_page(s, oggstream);
  194. }
  195. for (i = 0; i < total_segments; ) {
  196. OGGPage *page = &oggstream->page;
  197. segments = FFMIN(total_segments - i, 255 - page->segments_count);
  198. if (i && !page->segments_count)
  199. page->flags |= 1; // continued packet
  200. memset(page->segments+page->segments_count, 255, segments - 1);
  201. page->segments_count += segments - 1;
  202. len = FFMIN(size, segments*255);
  203. page->segments[page->segments_count++] = len - (segments-1)*255;
  204. memcpy(page->data+page->size, p, len);
  205. p += len;
  206. size -= len;
  207. i += segments;
  208. page->size += len;
  209. if (i == total_segments)
  210. page->granule = granule;
  211. if (!header) {
  212. AVStream *st = s->streams[page->stream_index];
  213. int64_t start = av_rescale_q(page->start_granule, st->time_base,
  214. AV_TIME_BASE_Q);
  215. int64_t next = av_rescale_q(page->granule, st->time_base,
  216. AV_TIME_BASE_Q);
  217. if (page->segments_count == 255 ||
  218. (ogg->pref_size > 0 && page->size >= ogg->pref_size) ||
  219. (ogg->pref_duration > 0 && next - start >= ogg->pref_duration)) {
  220. ogg_buffer_page(s, oggstream);
  221. }
  222. }
  223. }
  224. if (flush && oggstream->page.granule != -1)
  225. ogg_buffer_page(s, oggstream);
  226. return 0;
  227. }
  228. static uint8_t *ogg_write_vorbiscomment(int offset, int bitexact,
  229. int *header_len, AVDictionary **m, int framing_bit)
  230. {
  231. const char *vendor = bitexact ? "Libav" : LIBAVFORMAT_IDENT;
  232. int size;
  233. uint8_t *p, *p0;
  234. unsigned int count;
  235. ff_metadata_conv(m, ff_vorbiscomment_metadata_conv, NULL);
  236. size = offset + ff_vorbiscomment_length(*m, vendor, &count) + framing_bit;
  237. p = av_mallocz(size);
  238. if (!p)
  239. return NULL;
  240. p0 = p;
  241. p += offset;
  242. ff_vorbiscomment_write(&p, m, vendor, count);
  243. if (framing_bit)
  244. bytestream_put_byte(&p, 1);
  245. *header_len = size;
  246. return p0;
  247. }
  248. static int ogg_build_flac_headers(AVCodecContext *avctx,
  249. OGGStreamContext *oggstream, int bitexact,
  250. AVDictionary **m)
  251. {
  252. enum FLACExtradataFormat format;
  253. uint8_t *streaminfo;
  254. uint8_t *p;
  255. if (!avpriv_flac_is_extradata_valid(avctx, &format, &streaminfo))
  256. return -1;
  257. // first packet: STREAMINFO
  258. oggstream->header_len[0] = 51;
  259. oggstream->header[0] = av_mallocz(51); // per ogg flac specs
  260. p = oggstream->header[0];
  261. if (!p)
  262. return AVERROR(ENOMEM);
  263. bytestream_put_byte(&p, 0x7F);
  264. bytestream_put_buffer(&p, "FLAC", 4);
  265. bytestream_put_byte(&p, 1); // major version
  266. bytestream_put_byte(&p, 0); // minor version
  267. bytestream_put_be16(&p, 1); // headers packets without this one
  268. bytestream_put_buffer(&p, "fLaC", 4);
  269. bytestream_put_byte(&p, 0x00); // streaminfo
  270. bytestream_put_be24(&p, 34);
  271. bytestream_put_buffer(&p, streaminfo, FLAC_STREAMINFO_SIZE);
  272. // second packet: VorbisComment
  273. p = ogg_write_vorbiscomment(4, bitexact, &oggstream->header_len[1], m, 0);
  274. if (!p)
  275. return AVERROR(ENOMEM);
  276. oggstream->header[1] = p;
  277. bytestream_put_byte(&p, 0x84); // last metadata block and vorbis comment
  278. bytestream_put_be24(&p, oggstream->header_len[1] - 4);
  279. return 0;
  280. }
  281. #define SPEEX_HEADER_SIZE 80
  282. static int ogg_build_speex_headers(AVCodecContext *avctx,
  283. OGGStreamContext *oggstream, int bitexact,
  284. AVDictionary **m)
  285. {
  286. uint8_t *p;
  287. if (avctx->extradata_size < SPEEX_HEADER_SIZE)
  288. return -1;
  289. // first packet: Speex header
  290. p = av_mallocz(SPEEX_HEADER_SIZE);
  291. if (!p)
  292. return AVERROR(ENOMEM);
  293. oggstream->header[0] = p;
  294. oggstream->header_len[0] = SPEEX_HEADER_SIZE;
  295. bytestream_put_buffer(&p, avctx->extradata, SPEEX_HEADER_SIZE);
  296. AV_WL32(&oggstream->header[0][68], 0); // set extra_headers to 0
  297. // second packet: VorbisComment
  298. p = ogg_write_vorbiscomment(0, bitexact, &oggstream->header_len[1], m, 0);
  299. if (!p)
  300. return AVERROR(ENOMEM);
  301. oggstream->header[1] = p;
  302. return 0;
  303. }
  304. #define OPUS_HEADER_SIZE 19
  305. static int ogg_build_opus_headers(AVCodecContext *avctx,
  306. OGGStreamContext *oggstream, int bitexact,
  307. AVDictionary **m)
  308. {
  309. uint8_t *p;
  310. if (avctx->extradata_size < OPUS_HEADER_SIZE)
  311. return -1;
  312. /* first packet: Opus header */
  313. p = av_mallocz(avctx->extradata_size);
  314. if (!p)
  315. return AVERROR(ENOMEM);
  316. oggstream->header[0] = p;
  317. oggstream->header_len[0] = avctx->extradata_size;
  318. bytestream_put_buffer(&p, avctx->extradata, avctx->extradata_size);
  319. /* second packet: VorbisComment */
  320. p = ogg_write_vorbiscomment(8, bitexact, &oggstream->header_len[1], m, 0);
  321. if (!p)
  322. return AVERROR(ENOMEM);
  323. oggstream->header[1] = p;
  324. bytestream_put_buffer(&p, "OpusTags", 8);
  325. return 0;
  326. }
  327. static int ogg_write_header(AVFormatContext *s)
  328. {
  329. OGGContext *ogg = s->priv_data;
  330. OGGStreamContext *oggstream;
  331. int i, j;
  332. if (ogg->pref_size)
  333. av_log(s, AV_LOG_WARNING, "The pagesize option is deprecated\n");
  334. for (i = 0; i < s->nb_streams; i++) {
  335. AVStream *st = s->streams[i];
  336. unsigned serial_num = i;
  337. if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
  338. if (st->codec->codec_id == AV_CODEC_ID_OPUS)
  339. /* Opus requires a fixed 48kHz clock */
  340. avpriv_set_pts_info(st, 64, 1, 48000);
  341. else
  342. avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
  343. else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
  344. avpriv_set_pts_info(st, 64, st->codec->time_base.num, st->codec->time_base.den);
  345. if (st->codec->codec_id != AV_CODEC_ID_VORBIS &&
  346. st->codec->codec_id != AV_CODEC_ID_THEORA &&
  347. st->codec->codec_id != AV_CODEC_ID_SPEEX &&
  348. st->codec->codec_id != AV_CODEC_ID_FLAC &&
  349. st->codec->codec_id != AV_CODEC_ID_OPUS) {
  350. av_log(s, AV_LOG_ERROR, "Unsupported codec id in stream %d\n", i);
  351. return -1;
  352. }
  353. if (!st->codec->extradata || !st->codec->extradata_size) {
  354. av_log(s, AV_LOG_ERROR, "No extradata present\n");
  355. return -1;
  356. }
  357. oggstream = av_mallocz(sizeof(*oggstream));
  358. oggstream->page.stream_index = i;
  359. if (!(st->codec->flags & CODEC_FLAG_BITEXACT))
  360. do {
  361. serial_num = av_get_random_seed();
  362. for (j = 0; j < i; j++) {
  363. OGGStreamContext *sc = s->streams[j]->priv_data;
  364. if (serial_num == sc->serial_num)
  365. break;
  366. }
  367. } while (j < i);
  368. oggstream->serial_num = serial_num;
  369. st->priv_data = oggstream;
  370. if (st->codec->codec_id == AV_CODEC_ID_FLAC) {
  371. int err = ogg_build_flac_headers(st->codec, oggstream,
  372. st->codec->flags & CODEC_FLAG_BITEXACT,
  373. &s->metadata);
  374. if (err) {
  375. av_log(s, AV_LOG_ERROR, "Error writing FLAC headers\n");
  376. av_freep(&st->priv_data);
  377. return err;
  378. }
  379. } else if (st->codec->codec_id == AV_CODEC_ID_SPEEX) {
  380. int err = ogg_build_speex_headers(st->codec, oggstream,
  381. st->codec->flags & CODEC_FLAG_BITEXACT,
  382. &s->metadata);
  383. if (err) {
  384. av_log(s, AV_LOG_ERROR, "Error writing Speex headers\n");
  385. av_freep(&st->priv_data);
  386. return err;
  387. }
  388. } else if (st->codec->codec_id == AV_CODEC_ID_OPUS) {
  389. int err = ogg_build_opus_headers(st->codec, oggstream,
  390. st->codec->flags & CODEC_FLAG_BITEXACT,
  391. &s->metadata);
  392. if (err) {
  393. av_log(s, AV_LOG_ERROR, "Error writing Opus headers\n");
  394. av_freep(&st->priv_data);
  395. return err;
  396. }
  397. } else {
  398. uint8_t *p;
  399. const char *cstr = st->codec->codec_id == AV_CODEC_ID_VORBIS ? "vorbis" : "theora";
  400. int header_type = st->codec->codec_id == AV_CODEC_ID_VORBIS ? 3 : 0x81;
  401. int framing_bit = st->codec->codec_id == AV_CODEC_ID_VORBIS ? 1 : 0;
  402. if (avpriv_split_xiph_headers(st->codec->extradata, st->codec->extradata_size,
  403. st->codec->codec_id == AV_CODEC_ID_VORBIS ? 30 : 42,
  404. oggstream->header, oggstream->header_len) < 0) {
  405. av_log(s, AV_LOG_ERROR, "Extradata corrupted\n");
  406. av_freep(&st->priv_data);
  407. return -1;
  408. }
  409. p = ogg_write_vorbiscomment(7, st->codec->flags & CODEC_FLAG_BITEXACT,
  410. &oggstream->header_len[1], &s->metadata,
  411. framing_bit);
  412. oggstream->header[1] = p;
  413. if (!p)
  414. return AVERROR(ENOMEM);
  415. bytestream_put_byte(&p, header_type);
  416. bytestream_put_buffer(&p, cstr, 6);
  417. if (st->codec->codec_id == AV_CODEC_ID_THEORA) {
  418. /** KFGSHIFT is the width of the less significant section of the granule position
  419. The less significant section is the frame count since the last keyframe */
  420. oggstream->kfgshift = ((oggstream->header[0][40]&3)<<3)|(oggstream->header[0][41]>>5);
  421. oggstream->vrev = oggstream->header[0][9];
  422. av_log(s, AV_LOG_DEBUG, "theora kfgshift %d, vrev %d\n",
  423. oggstream->kfgshift, oggstream->vrev);
  424. }
  425. }
  426. }
  427. for (j = 0; j < s->nb_streams; j++) {
  428. OGGStreamContext *oggstream = s->streams[j]->priv_data;
  429. ogg_buffer_data(s, s->streams[j], oggstream->header[0],
  430. oggstream->header_len[0], 0, 1);
  431. oggstream->page.flags |= 2; // bos
  432. ogg_buffer_page(s, oggstream);
  433. }
  434. for (j = 0; j < s->nb_streams; j++) {
  435. AVStream *st = s->streams[j];
  436. OGGStreamContext *oggstream = st->priv_data;
  437. for (i = 1; i < 3; i++) {
  438. if (oggstream && oggstream->header_len[i])
  439. ogg_buffer_data(s, st, oggstream->header[i],
  440. oggstream->header_len[i], 0, 1);
  441. }
  442. ogg_buffer_page(s, oggstream);
  443. }
  444. oggstream->page.start_granule = AV_NOPTS_VALUE;
  445. return 0;
  446. }
  447. static void ogg_write_pages(AVFormatContext *s, int flush)
  448. {
  449. OGGContext *ogg = s->priv_data;
  450. OGGPageList *next, *p;
  451. if (!ogg->page_list)
  452. return;
  453. for (p = ogg->page_list; p; ) {
  454. OGGStreamContext *oggstream =
  455. s->streams[p->page.stream_index]->priv_data;
  456. if (oggstream->page_count < 2 && !flush)
  457. break;
  458. ogg_write_page(s, &p->page,
  459. flush && oggstream->page_count == 1 ? 4 : 0); // eos
  460. next = p->next;
  461. av_freep(&p);
  462. p = next;
  463. }
  464. ogg->page_list = p;
  465. }
  466. static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt)
  467. {
  468. AVStream *st = s->streams[pkt->stream_index];
  469. OGGStreamContext *oggstream = st->priv_data;
  470. int ret;
  471. int64_t granule;
  472. if (st->codec->codec_id == AV_CODEC_ID_THEORA) {
  473. int64_t pts = oggstream->vrev < 1 ? pkt->pts : pkt->pts + pkt->duration;
  474. int pframe_count;
  475. if (pkt->flags & AV_PKT_FLAG_KEY)
  476. oggstream->last_kf_pts = pts;
  477. pframe_count = pts - oggstream->last_kf_pts;
  478. // prevent frame count from overflow if key frame flag is not set
  479. if (pframe_count >= (1<<oggstream->kfgshift)) {
  480. oggstream->last_kf_pts += pframe_count;
  481. pframe_count = 0;
  482. }
  483. granule = (oggstream->last_kf_pts<<oggstream->kfgshift) | pframe_count;
  484. } else if (st->codec->codec_id == AV_CODEC_ID_OPUS)
  485. granule = pkt->pts + pkt->duration + av_rescale_q(st->codec->delay, (AVRational){ 1, st->codec->sample_rate }, st->time_base);
  486. else
  487. granule = pkt->pts + pkt->duration;
  488. if (oggstream->page.start_granule == AV_NOPTS_VALUE)
  489. oggstream->page.start_granule = pkt->pts;
  490. ret = ogg_buffer_data(s, st, pkt->data, pkt->size, granule, 0);
  491. if (ret < 0)
  492. return ret;
  493. ogg_write_pages(s, 0);
  494. oggstream->last_granule = granule;
  495. return 0;
  496. }
  497. static int ogg_write_trailer(AVFormatContext *s)
  498. {
  499. int i;
  500. /* flush current page if needed */
  501. for (i = 0; i < s->nb_streams; i++) {
  502. OGGStreamContext *oggstream = s->streams[i]->priv_data;
  503. if (oggstream->page.size > 0)
  504. ogg_buffer_page(s, oggstream);
  505. }
  506. ogg_write_pages(s, 1);
  507. for (i = 0; i < s->nb_streams; i++) {
  508. AVStream *st = s->streams[i];
  509. OGGStreamContext *oggstream = st->priv_data;
  510. if (st->codec->codec_id == AV_CODEC_ID_FLAC ||
  511. st->codec->codec_id == AV_CODEC_ID_SPEEX ||
  512. st->codec->codec_id == AV_CODEC_ID_OPUS) {
  513. av_free(oggstream->header[0]);
  514. }
  515. av_freep(&oggstream->header[1]);
  516. av_freep(&st->priv_data);
  517. }
  518. return 0;
  519. }
  520. AVOutputFormat ff_ogg_muxer = {
  521. .name = "ogg",
  522. .long_name = NULL_IF_CONFIG_SMALL("Ogg"),
  523. .mime_type = "application/ogg",
  524. .extensions = "ogg,ogv,spx,opus",
  525. .priv_data_size = sizeof(OGGContext),
  526. .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
  527. AV_CODEC_ID_VORBIS : AV_CODEC_ID_FLAC,
  528. .video_codec = AV_CODEC_ID_THEORA,
  529. .write_header = ogg_write_header,
  530. .write_packet = ogg_write_packet,
  531. .write_trailer = ogg_write_trailer,
  532. .flags = AVFMT_TS_NEGATIVE,
  533. .priv_class = &ogg_muxer_class,
  534. };