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.

645 lines
21KB

  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_INT64, { .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. ff_metadata_conv(m, ff_vorbiscomment_metadata_conv, NULL);
  235. size = offset + ff_vorbiscomment_length(*m, vendor) + framing_bit;
  236. p = av_mallocz(size);
  237. if (!p)
  238. return NULL;
  239. p0 = p;
  240. p += offset;
  241. ff_vorbiscomment_write(&p, m, vendor);
  242. if (framing_bit)
  243. bytestream_put_byte(&p, 1);
  244. *header_len = size;
  245. return p0;
  246. }
  247. static int ogg_build_flac_headers(AVCodecContext *avctx,
  248. OGGStreamContext *oggstream, int bitexact,
  249. AVDictionary **m)
  250. {
  251. enum FLACExtradataFormat format;
  252. uint8_t *streaminfo;
  253. uint8_t *p;
  254. if (!avpriv_flac_is_extradata_valid(avctx, &format, &streaminfo))
  255. return -1;
  256. // first packet: STREAMINFO
  257. oggstream->header_len[0] = 51;
  258. oggstream->header[0] = av_mallocz(51); // per ogg flac specs
  259. p = oggstream->header[0];
  260. if (!p)
  261. return AVERROR(ENOMEM);
  262. bytestream_put_byte(&p, 0x7F);
  263. bytestream_put_buffer(&p, "FLAC", 4);
  264. bytestream_put_byte(&p, 1); // major version
  265. bytestream_put_byte(&p, 0); // minor version
  266. bytestream_put_be16(&p, 1); // headers packets without this one
  267. bytestream_put_buffer(&p, "fLaC", 4);
  268. bytestream_put_byte(&p, 0x00); // streaminfo
  269. bytestream_put_be24(&p, 34);
  270. bytestream_put_buffer(&p, streaminfo, FLAC_STREAMINFO_SIZE);
  271. // second packet: VorbisComment
  272. p = ogg_write_vorbiscomment(4, bitexact, &oggstream->header_len[1], m, 0);
  273. if (!p)
  274. return AVERROR(ENOMEM);
  275. oggstream->header[1] = p;
  276. bytestream_put_byte(&p, 0x84); // last metadata block and vorbis comment
  277. bytestream_put_be24(&p, oggstream->header_len[1] - 4);
  278. return 0;
  279. }
  280. #define SPEEX_HEADER_SIZE 80
  281. static int ogg_build_speex_headers(AVCodecContext *avctx,
  282. OGGStreamContext *oggstream, int bitexact,
  283. AVDictionary **m)
  284. {
  285. uint8_t *p;
  286. if (avctx->extradata_size < SPEEX_HEADER_SIZE)
  287. return -1;
  288. // first packet: Speex header
  289. p = av_mallocz(SPEEX_HEADER_SIZE);
  290. if (!p)
  291. return AVERROR(ENOMEM);
  292. oggstream->header[0] = p;
  293. oggstream->header_len[0] = SPEEX_HEADER_SIZE;
  294. bytestream_put_buffer(&p, avctx->extradata, SPEEX_HEADER_SIZE);
  295. AV_WL32(&oggstream->header[0][68], 0); // set extra_headers to 0
  296. // second packet: VorbisComment
  297. p = ogg_write_vorbiscomment(0, bitexact, &oggstream->header_len[1], m, 0);
  298. if (!p)
  299. return AVERROR(ENOMEM);
  300. oggstream->header[1] = p;
  301. return 0;
  302. }
  303. #define OPUS_HEADER_SIZE 19
  304. static int ogg_build_opus_headers(AVCodecContext *avctx,
  305. OGGStreamContext *oggstream, int bitexact,
  306. AVDictionary **m)
  307. {
  308. uint8_t *p;
  309. if (avctx->extradata_size < OPUS_HEADER_SIZE)
  310. return -1;
  311. /* first packet: Opus header */
  312. p = av_mallocz(avctx->extradata_size);
  313. if (!p)
  314. return AVERROR(ENOMEM);
  315. oggstream->header[0] = p;
  316. oggstream->header_len[0] = avctx->extradata_size;
  317. bytestream_put_buffer(&p, avctx->extradata, avctx->extradata_size);
  318. /* second packet: VorbisComment */
  319. p = ogg_write_vorbiscomment(8, bitexact, &oggstream->header_len[1], m, 0);
  320. if (!p)
  321. return AVERROR(ENOMEM);
  322. oggstream->header[1] = p;
  323. bytestream_put_buffer(&p, "OpusTags", 8);
  324. return 0;
  325. }
  326. static void ogg_write_pages(AVFormatContext *s, int flush)
  327. {
  328. OGGContext *ogg = s->priv_data;
  329. OGGPageList *next, *p;
  330. if (!ogg->page_list)
  331. return;
  332. for (p = ogg->page_list; p; ) {
  333. OGGStreamContext *oggstream =
  334. s->streams[p->page.stream_index]->priv_data;
  335. if (oggstream->page_count < 2 && !flush)
  336. break;
  337. ogg_write_page(s, &p->page,
  338. flush == 1 && oggstream->page_count == 1 ? 4 : 0); // eos
  339. next = p->next;
  340. av_freep(&p);
  341. p = next;
  342. }
  343. ogg->page_list = p;
  344. }
  345. static int ogg_write_header(AVFormatContext *s)
  346. {
  347. OGGContext *ogg = s->priv_data;
  348. OGGStreamContext *oggstream;
  349. int i, j;
  350. if (ogg->pref_size)
  351. av_log(s, AV_LOG_WARNING, "The pagesize option is deprecated\n");
  352. for (i = 0; i < s->nb_streams; i++) {
  353. AVStream *st = s->streams[i];
  354. unsigned serial_num = i;
  355. if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
  356. if (st->codec->codec_id == AV_CODEC_ID_OPUS)
  357. /* Opus requires a fixed 48kHz clock */
  358. avpriv_set_pts_info(st, 64, 1, 48000);
  359. else
  360. avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
  361. if (st->codec->codec_id != AV_CODEC_ID_VORBIS &&
  362. st->codec->codec_id != AV_CODEC_ID_THEORA &&
  363. st->codec->codec_id != AV_CODEC_ID_SPEEX &&
  364. st->codec->codec_id != AV_CODEC_ID_FLAC &&
  365. st->codec->codec_id != AV_CODEC_ID_OPUS) {
  366. av_log(s, AV_LOG_ERROR, "Unsupported codec id in stream %d\n", i);
  367. return -1;
  368. }
  369. if (!st->codec->extradata || !st->codec->extradata_size) {
  370. av_log(s, AV_LOG_ERROR, "No extradata present\n");
  371. return -1;
  372. }
  373. oggstream = av_mallocz(sizeof(*oggstream));
  374. oggstream->page.stream_index = i;
  375. if (!(s->flags & AVFMT_FLAG_BITEXACT))
  376. do {
  377. serial_num = av_get_random_seed();
  378. for (j = 0; j < i; j++) {
  379. OGGStreamContext *sc = s->streams[j]->priv_data;
  380. if (serial_num == sc->serial_num)
  381. break;
  382. }
  383. } while (j < i);
  384. oggstream->serial_num = serial_num;
  385. st->priv_data = oggstream;
  386. if (st->codec->codec_id == AV_CODEC_ID_FLAC) {
  387. int err = ogg_build_flac_headers(st->codec, oggstream,
  388. s->flags & AVFMT_FLAG_BITEXACT,
  389. &s->metadata);
  390. if (err) {
  391. av_log(s, AV_LOG_ERROR, "Error writing FLAC headers\n");
  392. av_freep(&st->priv_data);
  393. return err;
  394. }
  395. } else if (st->codec->codec_id == AV_CODEC_ID_SPEEX) {
  396. int err = ogg_build_speex_headers(st->codec, oggstream,
  397. s->flags & AVFMT_FLAG_BITEXACT,
  398. &s->metadata);
  399. if (err) {
  400. av_log(s, AV_LOG_ERROR, "Error writing Speex headers\n");
  401. av_freep(&st->priv_data);
  402. return err;
  403. }
  404. } else if (st->codec->codec_id == AV_CODEC_ID_OPUS) {
  405. int err = ogg_build_opus_headers(st->codec, oggstream,
  406. s->flags & AVFMT_FLAG_BITEXACT,
  407. &s->metadata);
  408. if (err) {
  409. av_log(s, AV_LOG_ERROR, "Error writing Opus headers\n");
  410. av_freep(&st->priv_data);
  411. return err;
  412. }
  413. } else {
  414. uint8_t *p;
  415. const char *cstr = st->codec->codec_id == AV_CODEC_ID_VORBIS ? "vorbis" : "theora";
  416. int header_type = st->codec->codec_id == AV_CODEC_ID_VORBIS ? 3 : 0x81;
  417. int framing_bit = st->codec->codec_id == AV_CODEC_ID_VORBIS ? 1 : 0;
  418. if (avpriv_split_xiph_headers(st->codec->extradata, st->codec->extradata_size,
  419. st->codec->codec_id == AV_CODEC_ID_VORBIS ? 30 : 42,
  420. oggstream->header, oggstream->header_len) < 0) {
  421. av_log(s, AV_LOG_ERROR, "Extradata corrupted\n");
  422. av_freep(&st->priv_data);
  423. return -1;
  424. }
  425. p = ogg_write_vorbiscomment(7, s->flags & AVFMT_FLAG_BITEXACT,
  426. &oggstream->header_len[1], &s->metadata,
  427. framing_bit);
  428. oggstream->header[1] = p;
  429. if (!p)
  430. return AVERROR(ENOMEM);
  431. bytestream_put_byte(&p, header_type);
  432. bytestream_put_buffer(&p, cstr, 6);
  433. if (st->codec->codec_id == AV_CODEC_ID_THEORA) {
  434. /** KFGSHIFT is the width of the less significant section of the granule position
  435. The less significant section is the frame count since the last keyframe */
  436. oggstream->kfgshift = ((oggstream->header[0][40]&3)<<3)|(oggstream->header[0][41]>>5);
  437. oggstream->vrev = oggstream->header[0][9];
  438. av_log(s, AV_LOG_DEBUG, "theora kfgshift %d, vrev %d\n",
  439. oggstream->kfgshift, oggstream->vrev);
  440. }
  441. }
  442. }
  443. for (j = 0; j < s->nb_streams; j++) {
  444. OGGStreamContext *oggstream = s->streams[j]->priv_data;
  445. ogg_buffer_data(s, s->streams[j], oggstream->header[0],
  446. oggstream->header_len[0], 0, 1);
  447. oggstream->page.flags |= 2; // bos
  448. ogg_buffer_page(s, oggstream);
  449. }
  450. for (j = 0; j < s->nb_streams; j++) {
  451. AVStream *st = s->streams[j];
  452. OGGStreamContext *oggstream = st->priv_data;
  453. for (i = 1; i < 3; i++) {
  454. if (oggstream && oggstream->header_len[i])
  455. ogg_buffer_data(s, st, oggstream->header[i],
  456. oggstream->header_len[i], 0, 1);
  457. }
  458. ogg_buffer_page(s, oggstream);
  459. }
  460. oggstream->page.start_granule = AV_NOPTS_VALUE;
  461. ogg_write_pages(s, 2);
  462. return 0;
  463. }
  464. static int ogg_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
  465. {
  466. AVStream *st = s->streams[pkt->stream_index];
  467. OGGStreamContext *oggstream = st->priv_data;
  468. int ret;
  469. int64_t granule;
  470. if (st->codec->codec_id == AV_CODEC_ID_THEORA) {
  471. int64_t pts = oggstream->vrev < 1 ? pkt->pts : pkt->pts + pkt->duration;
  472. int pframe_count;
  473. if (pkt->flags & AV_PKT_FLAG_KEY)
  474. oggstream->last_kf_pts = pts;
  475. pframe_count = pts - oggstream->last_kf_pts;
  476. // prevent frame count from overflow if key frame flag is not set
  477. if (pframe_count >= (1<<oggstream->kfgshift)) {
  478. oggstream->last_kf_pts += pframe_count;
  479. pframe_count = 0;
  480. }
  481. granule = (oggstream->last_kf_pts<<oggstream->kfgshift) | pframe_count;
  482. } else if (st->codec->codec_id == AV_CODEC_ID_OPUS)
  483. granule = pkt->pts + pkt->duration + av_rescale_q(st->codec->delay, (AVRational){ 1, st->codec->sample_rate }, st->time_base);
  484. else
  485. granule = pkt->pts + pkt->duration;
  486. if (oggstream->page.start_granule == AV_NOPTS_VALUE)
  487. oggstream->page.start_granule = pkt->pts;
  488. ret = ogg_buffer_data(s, st, pkt->data, pkt->size, granule, 0);
  489. if (ret < 0)
  490. return ret;
  491. ogg_write_pages(s, 0);
  492. oggstream->last_granule = granule;
  493. return 0;
  494. }
  495. static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt)
  496. {
  497. int i;
  498. if (pkt)
  499. return ogg_write_packet_internal(s, pkt);
  500. for (i = 0; i < s->nb_streams; i++) {
  501. OGGStreamContext *oggstream = s->streams[i]->priv_data;
  502. if (oggstream->page.segments_count)
  503. ogg_buffer_page(s, oggstream);
  504. }
  505. ogg_write_pages(s, 2);
  506. return 0;
  507. }
  508. static int ogg_write_trailer(AVFormatContext *s)
  509. {
  510. int i;
  511. /* flush current page if needed */
  512. for (i = 0; i < s->nb_streams; i++) {
  513. OGGStreamContext *oggstream = s->streams[i]->priv_data;
  514. if (oggstream->page.size > 0)
  515. ogg_buffer_page(s, oggstream);
  516. }
  517. ogg_write_pages(s, 1);
  518. for (i = 0; i < s->nb_streams; i++) {
  519. AVStream *st = s->streams[i];
  520. OGGStreamContext *oggstream = st->priv_data;
  521. if (st->codec->codec_id == AV_CODEC_ID_FLAC ||
  522. st->codec->codec_id == AV_CODEC_ID_SPEEX ||
  523. st->codec->codec_id == AV_CODEC_ID_OPUS) {
  524. av_free(oggstream->header[0]);
  525. }
  526. av_freep(&oggstream->header[1]);
  527. av_freep(&st->priv_data);
  528. }
  529. return 0;
  530. }
  531. AVOutputFormat ff_ogg_muxer = {
  532. .name = "ogg",
  533. .long_name = NULL_IF_CONFIG_SMALL("Ogg"),
  534. .mime_type = "application/ogg",
  535. .extensions = "ogg,ogv,spx,opus",
  536. .priv_data_size = sizeof(OGGContext),
  537. .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
  538. AV_CODEC_ID_VORBIS : AV_CODEC_ID_FLAC,
  539. .video_codec = AV_CODEC_ID_THEORA,
  540. .write_header = ogg_write_header,
  541. .write_packet = ogg_write_packet,
  542. .write_trailer = ogg_write_trailer,
  543. .flags = AVFMT_TS_NEGATIVE | AVFMT_ALLOW_FLUSH,
  544. .priv_class = &ogg_muxer_class,
  545. };