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