FFmpeg
oggenc.c
Go to the documentation of this file.
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 "config_components.h"
23 
24 #include <stdint.h>
25 
26 #include "libavutil/crc.h"
27 #include "libavutil/mathematics.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/random_seed.h"
30 #include "libavcodec/xiph.h"
31 #include "libavcodec/bytestream.h"
32 #include "libavcodec/flac.h"
33 #include "avformat.h"
34 #include "avio_internal.h"
35 #include "internal.h"
36 #include "mux.h"
37 #include "version.h"
38 #include "vorbiscomment.h"
39 
40 #define MAX_PAGE_SIZE 65025
41 
42 typedef struct OGGPage {
43  int64_t start_granule;
44  int64_t granule;
46  uint8_t flags;
47  uint8_t segments_count;
48  uint8_t segments[255];
49  uint8_t data[MAX_PAGE_SIZE];
50  uint16_t size;
51 } OGGPage;
52 
53 typedef struct OGGStreamContext {
54  unsigned page_counter;
55  uint8_t *header[3];
56  int header_len[3];
57  /** for theora granule */
58  int kfgshift;
59  int64_t last_kf_pts;
60  int vrev;
61  /* for VP8 granule */
62  int isvp8;
63  int eos;
64  unsigned page_count; ///< number of page buffered
65  OGGPage page; ///< current page
66  unsigned serial_num; ///< serial number
67  int64_t last_granule; ///< last packet granule
69 
70 typedef struct OGGPageList {
72  struct OGGPageList *next;
73 } OGGPageList;
74 
75 typedef struct OGGContext {
76  const AVClass *class;
78  int pref_size; ///< preferred page size (0 => fill all segments)
79  int64_t pref_duration; ///< preferred page duration (0 => fill all segments)
81 } OGGContext;
82 
83 #define OFFSET(x) offsetof(OGGContext, x)
84 #define PARAM AV_OPT_FLAG_ENCODING_PARAM
85 
86 static const AVOption options[] = {
87  { "serial_offset", "serial number offset",
88  OFFSET(serial_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, PARAM },
89  { "oggpagesize", "Set preferred Ogg page size.",
90  OFFSET(pref_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, MAX_PAGE_SIZE, PARAM},
91  { "pagesize", "preferred page size in bytes (deprecated)",
92  OFFSET(pref_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MAX_PAGE_SIZE, PARAM },
93  { "page_duration", "preferred page duration, in microseconds",
94  OFFSET(pref_duration), AV_OPT_TYPE_INT64, { .i64 = 1000000 }, 0, INT64_MAX, PARAM },
95  { NULL },
96 };
97 
98 static const AVClass ogg_muxer_class = {
99  .class_name = "Ogg (audio/video/Speex/Opus) muxer",
100  .item_name = av_default_item_name,
101  .option = options,
102  .version = LIBAVUTIL_VERSION_INT,
103 };
104 
105 static void ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
106 {
107  OGGStreamContext *oggstream = s->streams[page->stream_index]->priv_data;
108  uint8_t buf[4 + 1 + 1 + 8 + 4 + 4 + 4 + 1 + 255], *ptr = buf, *crc_pos;
109  const AVCRC *crc_table = av_crc_get_table(AV_CRC_32_IEEE);
110  uint32_t crc;
111 
112  bytestream_put_le32(&ptr, MKTAG('O', 'g', 'g', 'S'));
113  bytestream_put_byte(&ptr, 0);
114  bytestream_put_byte(&ptr, page->flags | extra_flags);
115  bytestream_put_le64(&ptr, page->granule);
116  bytestream_put_le32(&ptr, oggstream->serial_num);
117  bytestream_put_le32(&ptr, oggstream->page_counter++);
118  crc_pos = ptr;
119  bytestream_put_le32(&ptr, 0);
120  bytestream_put_byte(&ptr, page->segments_count);
121  bytestream_put_buffer(&ptr, page->segments, page->segments_count);
122 
123  crc = av_crc(crc_table, 0, buf, ptr - buf);
124  crc = av_crc(crc_table, crc, page->data, page->size);
125  bytestream_put_be32(&crc_pos, crc);
126 
127  avio_write(s->pb, buf, ptr - buf);
128  avio_write(s->pb, page->data, page->size);
130  oggstream->page_count--;
131 }
132 
133 static int ogg_key_granule(OGGStreamContext *oggstream, int64_t granule)
134 {
135  return (oggstream->kfgshift && !(granule & ((1<<oggstream->kfgshift)-1))) ||
136  (oggstream->isvp8 && !((granule >> 3) & 0x07ffffff));
137 }
138 
139 static int64_t ogg_granule_to_timestamp(OGGStreamContext *oggstream, int64_t granule)
140 {
141  if (oggstream->kfgshift)
142  return (granule>>oggstream->kfgshift) +
143  (granule & ((1<<oggstream->kfgshift)-1));
144  else if (oggstream->isvp8)
145  return granule >> 32;
146  else
147  return granule;
148 }
149 
151 {
152  AVStream *st2 = s->streams[next->stream_index];
153  AVStream *st = s->streams[page->stream_index];
154  int64_t next_granule, cur_granule;
155 
156  if (next->granule == -1 || page->granule == -1)
157  return 0;
158 
159  next_granule = av_rescale_q(ogg_granule_to_timestamp(st2->priv_data, next->granule),
160  st2->time_base, AV_TIME_BASE_Q);
161  cur_granule = av_rescale_q(ogg_granule_to_timestamp(st->priv_data, page->granule),
162  st ->time_base, AV_TIME_BASE_Q);
163  return next_granule > cur_granule;
164 }
165 
166 static int ogg_reset_cur_page(OGGStreamContext *oggstream)
167 {
168  oggstream->page.granule = -1;
169  oggstream->page.flags = 0;
170  oggstream->page.segments_count = 0;
171  oggstream->page.size = 0;
172  return 0;
173 }
174 
176 {
177  OGGContext *ogg = s->priv_data;
178  OGGPageList **p = &ogg->page_list;
179  OGGPageList *l = av_mallocz(sizeof(*l));
180 
181  if (!l)
182  return AVERROR(ENOMEM);
183  l->page = oggstream->page;
184 
185  oggstream->page.start_granule = ogg_granule_to_timestamp(oggstream, oggstream->page.granule);
186  oggstream->page_count++;
187  ogg_reset_cur_page(oggstream);
188 
189  while (*p) {
190  if (ogg_compare_granule(s, &(*p)->page, &l->page))
191  break;
192  p = &(*p)->next;
193  }
194  l->next = *p;
195  *p = l;
196 
197  return 0;
198 }
199 
201  const uint8_t *data, unsigned size, int64_t granule,
202  int header)
203 {
204  OGGStreamContext *oggstream = st->priv_data;
205  OGGContext *ogg = s->priv_data;
206  int total_segments = size / 255 + 1;
207  const uint8_t *p = data;
208  int i, segments, len, flush = 0;
209 
210  // Handles VFR by flushing page because this frame needs to have a timestamp
211  // For theora and VP8, keyframes also need to have a timestamp to correctly mark
212  // them as such, otherwise seeking will not work correctly at the very
213  // least with old libogg versions.
214  // Do not try to flush header packets though, that will create broken files.
216  (ogg_granule_to_timestamp(oggstream, granule) >
217  ogg_granule_to_timestamp(oggstream, oggstream->last_granule) + 1 ||
218  ogg_key_granule(oggstream, granule))) {
219  if (oggstream->page.granule != -1)
220  ogg_buffer_page(s, oggstream);
221  flush = 1;
222  }
223 
224  // avoid a continued page
225  if (!header && oggstream->page.size > 0 &&
226  MAX_PAGE_SIZE - oggstream->page.size < size) {
227  ogg_buffer_page(s, oggstream);
228  }
229 
230  for (i = 0; i < total_segments; ) {
231  OGGPage *page = &oggstream->page;
232 
233  segments = FFMIN(total_segments - i, 255 - page->segments_count);
234 
235  if (i && !page->segments_count)
236  page->flags |= 1; // continued packet
237 
238  memset(page->segments+page->segments_count, 255, segments - 1);
239  page->segments_count += segments - 1;
240 
241  len = FFMIN(size, segments*255);
242  page->segments[page->segments_count++] = len - (segments-1)*255;
243  memcpy(page->data+page->size, p, len);
244  p += len;
245  size -= len;
246  i += segments;
247  page->size += len;
248 
249  if (i == total_segments)
250  page->granule = granule;
251 
252  {
253  AVStream *st = s->streams[page->stream_index];
254 
255  int64_t start = av_rescale_q(page->start_granule, st->time_base,
257  int64_t next = av_rescale_q(ogg_granule_to_timestamp(oggstream, page->granule),
259 
260  if (page->segments_count == 255) {
261  ogg_buffer_page(s, oggstream);
262  } else if (!header) {
263  if ((ogg->pref_size > 0 && page->size >= ogg->pref_size) ||
264  (ogg->pref_duration > 0 && next - start >= ogg->pref_duration)) {
265  ogg_buffer_page(s, oggstream);
266  }
267  }
268  }
269  }
270 
271  if (flush && oggstream->page.granule != -1)
272  ogg_buffer_page(s, oggstream);
273 
274  return 0;
275 }
276 
277 static uint8_t *ogg_write_vorbiscomment(int64_t offset, int bitexact,
278  int *header_len, AVDictionary **m, int framing_bit,
279  AVChapter **chapters, unsigned int nb_chapters)
280 {
281  const char *vendor = bitexact ? "ffmpeg" : LIBAVFORMAT_IDENT;
282  FFIOContext pb;
283  int64_t size;
284  uint8_t *p;
285 
287 
288  size = offset + ff_vorbiscomment_length(*m, vendor, chapters, nb_chapters) + framing_bit;
289  if (size > INT_MAX)
290  return NULL;
291  p = av_mallocz(size);
292  if (!p)
293  return NULL;
294 
296  ff_vorbiscomment_write(&pb.pub, *m, vendor, chapters, nb_chapters);
297  if (framing_bit)
298  avio_w8(&pb.pub, 1);
299 
300  *header_len = size;
301  return p;
302 }
303 
305  OGGStreamContext *oggstream, int bitexact,
306  AVDictionary **m)
307 {
308  uint8_t *p;
309 
311  return AVERROR(EINVAL);
312 
313  // first packet: STREAMINFO
314  oggstream->header_len[0] = 51;
315  oggstream->header[0] = av_mallocz(51); // per ogg flac specs
316  p = oggstream->header[0];
317  if (!p)
318  return AVERROR(ENOMEM);
319  bytestream_put_byte(&p, 0x7F);
320  bytestream_put_buffer(&p, "FLAC", 4);
321  bytestream_put_byte(&p, 1); // major version
322  bytestream_put_byte(&p, 0); // minor version
323  bytestream_put_be16(&p, 1); // headers packets without this one
324  bytestream_put_buffer(&p, "fLaC", 4);
325  bytestream_put_byte(&p, 0x00); // streaminfo
326  bytestream_put_be24(&p, 34);
328 
329  // second packet: VorbisComment
330  p = ogg_write_vorbiscomment(4, bitexact, &oggstream->header_len[1], m, 0, NULL, 0);
331  if (!p)
332  return AVERROR(ENOMEM);
333  oggstream->header[1] = p;
334  bytestream_put_byte(&p, 0x84); // last metadata block and vorbis comment
335  bytestream_put_be24(&p, oggstream->header_len[1] - 4);
336 
337  return 0;
338 }
339 
340 #define SPEEX_HEADER_SIZE 80
341 
343  OGGStreamContext *oggstream, int bitexact,
344  AVDictionary **m)
345 {
346  uint8_t *p;
347 
349  return AVERROR_INVALIDDATA;
350 
351  // first packet: Speex header
353  if (!p)
354  return AVERROR(ENOMEM);
355  oggstream->header[0] = p;
356  oggstream->header_len[0] = SPEEX_HEADER_SIZE;
358  AV_WL32(&oggstream->header[0][68], 0); // set extra_headers to 0
359 
360  // second packet: VorbisComment
361  p = ogg_write_vorbiscomment(0, bitexact, &oggstream->header_len[1], m, 0, NULL, 0);
362  if (!p)
363  return AVERROR(ENOMEM);
364  oggstream->header[1] = p;
365 
366  return 0;
367 }
368 
369 #define OPUS_HEADER_SIZE 19
370 
372  OGGStreamContext *oggstream, int bitexact,
373  AVDictionary **m, AVChapter **chapters,
374  unsigned int nb_chapters)
375 {
376  uint8_t *p;
377 
378  if (par->extradata_size < OPUS_HEADER_SIZE)
379  return AVERROR_INVALIDDATA;
380 
381  /* first packet: Opus header */
382  p = av_mallocz(par->extradata_size);
383  if (!p)
384  return AVERROR(ENOMEM);
385  oggstream->header[0] = p;
386  oggstream->header_len[0] = par->extradata_size;
388 
389  /* second packet: VorbisComment */
390  p = ogg_write_vorbiscomment(8, bitexact, &oggstream->header_len[1], m, 0, chapters, nb_chapters);
391  if (!p)
392  return AVERROR(ENOMEM);
393  oggstream->header[1] = p;
394  bytestream_put_buffer(&p, "OpusTags", 8);
395 
396  return 0;
397 }
398 
399 #define VP8_HEADER_SIZE 26
400 
402  OGGStreamContext *oggstream, int bitexact)
403 {
404  AVCodecParameters *par = st->codecpar;
405  uint8_t *p;
406 
407  /* first packet: VP8 header */
409  if (!p)
410  return AVERROR(ENOMEM);
411  oggstream->header[0] = p;
412  oggstream->header_len[0] = VP8_HEADER_SIZE;
413  bytestream_put_byte(&p, 0x4f); // HDRID
414  bytestream_put_buffer(&p, "VP80", 4); // Identifier
415  bytestream_put_byte(&p, 1); // HDRTYP
416  bytestream_put_byte(&p, 1); // VMAJ
417  bytestream_put_byte(&p, 0); // VMIN
418  bytestream_put_be16(&p, par->width);
419  bytestream_put_be16(&p, par->height);
420  bytestream_put_be24(&p, par->sample_aspect_ratio.num);
421  bytestream_put_be24(&p, par->sample_aspect_ratio.den);
422  if (st->r_frame_rate.num > 0 && st->r_frame_rate.den > 0) {
423  // OggVP8 requires pts to increase by 1 per visible frame, so use the least common
424  // multiple framerate if available.
425  av_log(s, AV_LOG_DEBUG, "Changing time base from %d/%d to %d/%d\n",
426  st->time_base.num, st->time_base.den,
427  st->r_frame_rate.den, st->r_frame_rate.num);
429  }
430  bytestream_put_be32(&p, st->time_base.den);
431  bytestream_put_be32(&p, st->time_base.num);
432 
433  /* optional second packet: VorbisComment */
435  p = ogg_write_vorbiscomment(7, bitexact, &oggstream->header_len[1], &st->metadata, 0, NULL, 0);
436  if (!p)
437  return AVERROR(ENOMEM);
438  oggstream->header[1] = p;
439  bytestream_put_byte(&p, 0x4f); // HDRID
440  bytestream_put_buffer(&p, "VP80", 4); // Identifier
441  bytestream_put_byte(&p, 2); // HDRTYP
442  bytestream_put_byte(&p, 0x20);
443  }
444 
445  oggstream->isvp8 = 1;
446 
447  return 0;
448 }
449 
451 {
452  OGGContext *ogg = s->priv_data;
453  OGGPageList *next, *p;
454 
455  if (!ogg->page_list)
456  return;
457 
458  for (p = ogg->page_list; p; ) {
459  OGGStreamContext *oggstream =
460  s->streams[p->page.stream_index]->priv_data;
461  if (oggstream->page_count < 2 && !flush)
462  break;
463  ogg_write_page(s, &p->page,
464  flush == 1 && oggstream->page_count == 1 ? 4 : 0); // eos
465  next = p->next;
466  av_freep(&p);
467  p = next;
468  }
469  ogg->page_list = p;
470 }
471 
473 {
474  OGGContext *ogg = s->priv_data;
475  OGGStreamContext *oggstream = NULL;
476  int i, j;
477 
478  if (ogg->pref_size)
479  av_log(s, AV_LOG_WARNING, "The pagesize option is deprecated\n");
480 
481  for (i = 0; i < s->nb_streams; i++) {
482  AVStream *st = s->streams[i];
483  unsigned serial_num = i + ogg->serial_offset;
484 
485  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
486  if (st->codecpar->codec_id == AV_CODEC_ID_OPUS)
487  /* Opus requires a fixed 48kHz clock */
488  avpriv_set_pts_info(st, 64, 1, 48000);
489  else
490  avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
491  }
492 
493  if (st->codecpar->codec_id != AV_CODEC_ID_VORBIS &&
499  av_log(s, AV_LOG_ERROR, "Unsupported codec id in stream %d\n", i);
500  return AVERROR(EINVAL);
501  }
502 
503  if ((!st->codecpar->extradata || !st->codecpar->extradata_size) &&
505  av_log(s, AV_LOG_ERROR, "No extradata present\n");
506  return AVERROR_INVALIDDATA;
507  }
508  oggstream = av_mallocz(sizeof(*oggstream));
509  if (!oggstream)
510  return AVERROR(ENOMEM);
511 
512  oggstream->page.stream_index = i;
513 
514  if (!(s->flags & AVFMT_FLAG_BITEXACT))
515  do {
516  serial_num = av_get_random_seed();
517  for (j = 0; j < i; j++) {
518  OGGStreamContext *sc = s->streams[j]->priv_data;
519  if (serial_num == sc->serial_num)
520  break;
521  }
522  } while (j < i);
523  oggstream->serial_num = serial_num;
524 
525  av_dict_copy(&st->metadata, s->metadata, AV_DICT_DONT_OVERWRITE);
526 
527  st->priv_data = oggstream;
528  if (st->codecpar->codec_id == AV_CODEC_ID_FLAC) {
529  int err = ogg_build_flac_headers(st->codecpar, oggstream,
530  s->flags & AVFMT_FLAG_BITEXACT,
531  &st->metadata);
532  if (err) {
533  av_log(s, AV_LOG_ERROR, "Error writing FLAC headers\n");
534  return err;
535  }
536  } else if (st->codecpar->codec_id == AV_CODEC_ID_SPEEX) {
537  int err = ogg_build_speex_headers(st->codecpar, oggstream,
538  s->flags & AVFMT_FLAG_BITEXACT,
539  &st->metadata);
540  if (err) {
541  av_log(s, AV_LOG_ERROR, "Error writing Speex headers\n");
542  return err;
543  }
544  } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) {
545  int err = ogg_build_opus_headers(st->codecpar, oggstream,
546  s->flags & AVFMT_FLAG_BITEXACT,
547  &st->metadata, s->chapters, s->nb_chapters);
548  if (err) {
549  av_log(s, AV_LOG_ERROR, "Error writing Opus headers\n");
550  return err;
551  }
552  } else if (st->codecpar->codec_id == AV_CODEC_ID_VP8) {
553  int err = ogg_build_vp8_headers(s, st, oggstream,
554  s->flags & AVFMT_FLAG_BITEXACT);
555  if (err) {
556  av_log(s, AV_LOG_ERROR, "Error writing VP8 headers\n");
557  return err;
558  }
559  } else {
560  uint8_t *p;
561  const char *cstr = st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? "vorbis" : "theora";
562  int header_type = st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? 3 : 0x81;
563  int framing_bit = st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? 1 : 0;
564 
566  st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? 30 : 42,
567  (const uint8_t**)oggstream->header, oggstream->header_len) < 0) {
568  av_log(s, AV_LOG_ERROR, "Extradata corrupted\n");
569  oggstream->header[1] = NULL;
570  return AVERROR_INVALIDDATA;
571  }
572 
574  &oggstream->header_len[1], &st->metadata,
575  framing_bit, NULL, 0);
576  oggstream->header[1] = p;
577  if (!p)
578  return AVERROR(ENOMEM);
579 
580  bytestream_put_byte(&p, header_type);
581  bytestream_put_buffer(&p, cstr, 6);
582 
583  if (st->codecpar->codec_id == AV_CODEC_ID_THEORA) {
584  int den = AV_RB32(oggstream->header[0] + 22), num = AV_RB32(oggstream->header[0] + 26);
585  /* Make sure to use time base stored in the Theora stream header to write
586  correct timestamps */
587  if (st->time_base.num != num || st->time_base.den != den) {
588  av_log(s, AV_LOG_DEBUG, "Changing time base from %d/%d to %d/%d\n",
589  st->time_base.num, st->time_base.den, num, den);
590  avpriv_set_pts_info(st, 64, num, den);
591  }
592  /** KFGSHIFT is the width of the less significant section of the granule position
593  The less significant section is the frame count since the last keyframe */
594  oggstream->kfgshift = ((oggstream->header[0][40]&3)<<3)|(oggstream->header[0][41]>>5);
595  oggstream->vrev = oggstream->header[0][9];
596  av_log(s, AV_LOG_DEBUG, "theora kfgshift %d, vrev %d\n",
597  oggstream->kfgshift, oggstream->vrev);
598  }
599  }
600  }
601 
602  return 0;
603 }
604 
606 {
607  OGGStreamContext *oggstream = NULL;
608  int i, j;
609 
610  for (j = 0; j < s->nb_streams; j++) {
611  oggstream = s->streams[j]->priv_data;
612  ogg_buffer_data(s, s->streams[j], oggstream->header[0],
613  oggstream->header_len[0], 0, 1);
614  oggstream->page.flags |= 2; // bos
615  ogg_buffer_page(s, oggstream);
616  }
617  for (j = 0; j < s->nb_streams; j++) {
618  AVStream *st = s->streams[j];
619  oggstream = st->priv_data;
620  for (i = 1; i < 3; i++) {
621  if (oggstream->header_len[i])
622  ogg_buffer_data(s, st, oggstream->header[i],
623  oggstream->header_len[i], 0, 1);
624  }
625  ogg_buffer_page(s, oggstream);
626  }
627 
628  oggstream->page.start_granule = AV_NOPTS_VALUE;
629 
630  ogg_write_pages(s, 2);
631 
632  return 0;
633 }
634 
636 {
637  AVStream *st = s->streams[pkt->stream_index];
638  OGGStreamContext *oggstream = st->priv_data;
639  int ret;
640  int64_t granule;
641 
642  if (st->codecpar->codec_id == AV_CODEC_ID_THEORA) {
643  int64_t pts = oggstream->vrev < 1 ? pkt->pts : pkt->pts + pkt->duration;
644  int pframe_count;
645  if (pkt->flags & AV_PKT_FLAG_KEY)
646  oggstream->last_kf_pts = pts;
647  pframe_count = pts - oggstream->last_kf_pts;
648  // prevent frame count from overflow if key frame flag is not set
649  if (pframe_count >= (1<<oggstream->kfgshift)) {
650  oggstream->last_kf_pts += pframe_count;
651  pframe_count = 0;
652  }
653  granule = (oggstream->last_kf_pts<<oggstream->kfgshift) | pframe_count;
654  } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS)
655  granule = pkt->pts + pkt->duration +
657  (AVRational){ 1, st->codecpar->sample_rate },
658  st->time_base);
659  else if (st->codecpar->codec_id == AV_CODEC_ID_VP8) {
660  int64_t pts, invcnt, dist;
661  int visible;
662 
663  visible = (pkt->data[0] >> 4) & 1;
664  pts = pkt->pts + pkt->duration;
665  invcnt = (oggstream->last_granule >> 30) & 3;
666  invcnt = visible ? 3 : (invcnt == 3 ? 0 : invcnt + 1);
667  dist = (pkt->flags & AV_PKT_FLAG_KEY) ? 0 : ((oggstream->last_granule >> 3) & 0x07ffffff) + 1;
668 
669  granule = (pts << 32) | (invcnt << 30) | (dist << 3);
670  } else
671  granule = pkt->pts + pkt->duration;
672 
673  if (oggstream->page.start_granule == AV_NOPTS_VALUE)
674  oggstream->page.start_granule = pkt->pts;
675 
676  ret = ogg_buffer_data(s, st, pkt->data, pkt->size, granule, 0);
677  if (ret < 0)
678  return ret;
679 
680  ogg_write_pages(s, 0);
681 
682  oggstream->last_granule = granule;
683 
684  return 0;
685 }
686 
688 {
689  int i;
690 
691  if (pkt)
692  return pkt->size ? ogg_write_packet_internal(s, pkt) : 0;
693 
694  for (i = 0; i < s->nb_streams; i++) {
695  OGGStreamContext *oggstream = s->streams[i]->priv_data;
696  if (oggstream->page.segments_count)
697  ogg_buffer_page(s, oggstream);
698  }
699 
700  ogg_write_pages(s, 2);
701  return 1;
702 }
703 
705 {
706  int i;
707 
708  /* flush current page if needed */
709  for (i = 0; i < s->nb_streams; i++) {
710  OGGStreamContext *oggstream = s->streams[i]->priv_data;
711 
712  if (oggstream->page.size > 0)
713  ogg_buffer_page(s, oggstream);
714  }
715 
716  ogg_write_pages(s, 1);
717 
718  return 0;
719 }
720 
722 {
723  OGGContext *ogg = s->priv_data;
724  OGGPageList *p = ogg->page_list;
725  int i;
726 
727  for (i = 0; i < s->nb_streams; i++) {
728  AVStream *st = s->streams[i];
729  OGGStreamContext *oggstream = st->priv_data;
730  if (!oggstream)
731  continue;
732  if (st->codecpar->codec_id == AV_CODEC_ID_FLAC ||
736  av_freep(&oggstream->header[0]);
737  }
738  av_freep(&oggstream->header[1]);
739  }
740 
741  while (p) {
742  OGGPageList *next = p->next;
743  av_free(p);
744  p = next;
745  }
746  ogg->page_list = NULL;
747 }
748 
749 #if CONFIG_OGG_MUXER
751  .p.name = "ogg",
752  .p.long_name = NULL_IF_CONFIG_SMALL("Ogg"),
753  .p.mime_type = "application/ogg",
754  .p.extensions = "ogg"
755 #if !CONFIG_OGV_MUXER
756  ",ogv"
757 #endif
758 #if !CONFIG_SPX_MUXER
759  ",spx"
760 #endif
761 #if !CONFIG_OPUS_MUXER
762  ",opus"
763 #endif
764  ,
765  .priv_data_size = sizeof(OGGContext),
766  .p.audio_codec = CONFIG_LIBVORBIS_ENCODER ?
768  .p.video_codec = AV_CODEC_ID_THEORA,
769  .init = ogg_init,
770  .write_header = ogg_write_header,
771  .write_packet = ogg_write_packet,
772  .write_trailer = ogg_write_trailer,
773  .deinit = ogg_free,
775  .p.flags = AVFMT_TS_NEGATIVE | AVFMT_TS_NONSTRICT | AVFMT_ALLOW_FLUSH,
776 #else
778 #endif
779  .p.priv_class = &ogg_muxer_class,
780  .flags_internal = FF_FMT_ALLOW_FLUSH,
781 };
782 #endif
783 
784 #if CONFIG_OGA_MUXER
786  .p.name = "oga",
787  .p.long_name = NULL_IF_CONFIG_SMALL("Ogg Audio"),
788  .p.mime_type = "audio/ogg",
789  .p.extensions = "oga",
790  .priv_data_size = sizeof(OGGContext),
791  .p.audio_codec = AV_CODEC_ID_FLAC,
792  .init = ogg_init,
793  .write_header = ogg_write_header,
794  .write_packet = ogg_write_packet,
795  .write_trailer = ogg_write_trailer,
796  .deinit = ogg_free,
798  .p.flags = AVFMT_TS_NEGATIVE | AVFMT_ALLOW_FLUSH,
799 #else
800  .p.flags = AVFMT_TS_NEGATIVE,
801 #endif
802  .p.priv_class = &ogg_muxer_class,
803  .flags_internal = FF_FMT_ALLOW_FLUSH,
804 };
805 #endif
806 
807 #if CONFIG_OGV_MUXER
809  .p.name = "ogv",
810  .p.long_name = NULL_IF_CONFIG_SMALL("Ogg Video"),
811  .p.mime_type = "video/ogg",
812  .p.extensions = "ogv",
813  .priv_data_size = sizeof(OGGContext),
814  .p.audio_codec = CONFIG_LIBVORBIS_ENCODER ?
816  .p.video_codec = CONFIG_LIBTHEORA_ENCODER ?
818  .init = ogg_init,
819  .write_header = ogg_write_header,
820  .write_packet = ogg_write_packet,
821  .write_trailer = ogg_write_trailer,
822  .deinit = ogg_free,
824  .p.flags = AVFMT_TS_NEGATIVE | AVFMT_TS_NONSTRICT | AVFMT_ALLOW_FLUSH,
825 #else
827 #endif
828  .p.priv_class = &ogg_muxer_class,
829  .flags_internal = FF_FMT_ALLOW_FLUSH,
830 };
831 #endif
832 
833 #if CONFIG_SPX_MUXER
835  .p.name = "spx",
836  .p.long_name = NULL_IF_CONFIG_SMALL("Ogg Speex"),
837  .p.mime_type = "audio/ogg",
838  .p.extensions = "spx",
839  .priv_data_size = sizeof(OGGContext),
840  .p.audio_codec = AV_CODEC_ID_SPEEX,
841  .init = ogg_init,
842  .write_header = ogg_write_header,
843  .write_packet = ogg_write_packet,
844  .write_trailer = ogg_write_trailer,
845  .deinit = ogg_free,
847  .p.flags = AVFMT_TS_NEGATIVE | AVFMT_ALLOW_FLUSH,
848 #else
849  .p.flags = AVFMT_TS_NEGATIVE,
850 #endif
851  .p.priv_class = &ogg_muxer_class,
852  .flags_internal = FF_FMT_ALLOW_FLUSH,
853 };
854 #endif
855 
856 #if CONFIG_OPUS_MUXER
858  .p.name = "opus",
859  .p.long_name = NULL_IF_CONFIG_SMALL("Ogg Opus"),
860  .p.mime_type = "audio/ogg",
861  .p.extensions = "opus",
862  .priv_data_size = sizeof(OGGContext),
863  .p.audio_codec = AV_CODEC_ID_OPUS,
864  .init = ogg_init,
865  .write_header = ogg_write_header,
866  .write_packet = ogg_write_packet,
867  .write_trailer = ogg_write_trailer,
868  .deinit = ogg_free,
870  .p.flags = AVFMT_TS_NEGATIVE | AVFMT_ALLOW_FLUSH,
871 #else
872  .p.flags = AVFMT_TS_NEGATIVE,
873 #endif
874  .p.priv_class = &ogg_muxer_class,
875  .flags_internal = FF_FMT_ALLOW_FLUSH,
876 };
877 #endif
VP8_HEADER_SIZE
#define VP8_HEADER_SIZE
Definition: oggenc.c:399
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:69
LIBAVFORMAT_IDENT
#define LIBAVFORMAT_IDENT
Definition: version.h:45
OGGContext::pref_duration
int64_t pref_duration
preferred page duration (0 => fill all segments)
Definition: oggenc.c:79
AVOutputFormat::name
const char * name
Definition: avformat.h:511
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:424
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
AVCRC
uint32_t AVCRC
Definition: crc.h:46
AVStream::priv_data
void * priv_data
Definition: avformat.h:866
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:264
ogg_compare_granule
static int ogg_compare_granule(AVFormatContext *s, OGGPage *next, OGGPage *page)
Definition: oggenc.c:150
ff_metadata_conv
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:26
AVPacket::data
uint8_t * data
Definition: packet.h:491
vorbiscomment.h
OGGPageList
Definition: oggenc.c:70
AVOption
AVOption.
Definition: opt.h:251
data
const char data[16]
Definition: mxf.c:148
ogg_write_vorbiscomment
static uint8_t * ogg_write_vorbiscomment(int64_t offset, int bitexact, int *header_len, AVDictionary **m, int framing_bit, AVChapter **chapters, unsigned int nb_chapters)
Definition: oggenc.c:277
AV_DICT_IGNORE_SUFFIX
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
Definition: dict.h:75
OGGStreamContext::last_granule
int64_t last_granule
last packet granule
Definition: oggenc.c:67
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:509
mathematics.h
AVDictionary
Definition: dict.c:34
AV_CODEC_ID_FLAC
@ AV_CODEC_ID_FLAC
Definition: codec_id.h:454
ff_ogg_muxer
const FFOutputFormat ff_ogg_muxer
ogg_muxer_class
static const AVClass ogg_muxer_class
Definition: oggenc.c:98
ogg
Definition: oggdec.h:101
FFIOContext
Definition: avio_internal.h:28
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:546
OGGPageList::next
struct OGGPageList * next
Definition: oggenc.c:72
OGGStreamContext::page_count
unsigned page_count
number of page buffered
Definition: oggenc.c:64
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:36
av_get_random_seed
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
Definition: random_seed.c:167
xiph.h
OGGPageList::page
OGGPage page
Definition: oggenc.c:71
crc.h
avio_write_marker
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
Definition: aviobuf.c:508
OGGStreamContext::page
OGGPage page
current page
Definition: oggenc.c:65
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: avformat.c:761
AV_CODEC_ID_SPEEX
@ AV_CODEC_ID_SPEEX
Definition: codec_id.h:477
FF_FMT_ALLOW_FLUSH
#define FF_FMT_ALLOW_FLUSH
Definition: mux.h:30
OFFSET
#define OFFSET(x)
Definition: oggenc.c:83
ff_vorbiscomment_write
int ff_vorbiscomment_write(AVIOContext *pb, const AVDictionary *m, const char *vendor_string, AVChapter **chapters, unsigned int nb_chapters)
Write a VorbisComment into an AVIOContext.
Definition: vorbiscomment.c:65
AVChapter
Definition: avformat.h:1074
ogg_write_header
static int ogg_write_header(AVFormatContext *s)
Definition: oggenc.c:605
pts
static int64_t pts
Definition: transcode_aac.c:643
AVRational::num
int num
Numerator.
Definition: rational.h:59
OGGStreamContext::eos
int eos
Definition: oggenc.c:63
OGGStreamContext::page_counter
unsigned page_counter
Definition: oggenc.c:54
ogg_write_packet_internal
static int ogg_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
Definition: oggenc.c:635
ogg_write_pages
static void ogg_write_pages(AVFormatContext *s, int flush)
Definition: oggenc.c:450
SPEEX_HEADER_SIZE
#define SPEEX_HEADER_SIZE
Definition: oggenc.c:340
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
OGGStreamContext::isvp8
int isvp8
Definition: oggenc.c:62
ogg_init
static int ogg_init(AVFormatContext *s)
Definition: oggenc.c:472
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:62
ogg_build_vp8_headers
static int ogg_build_vp8_headers(AVFormatContext *s, AVStream *st, OGGStreamContext *oggstream, int bitexact)
Definition: oggenc.c:401
s
#define s(width, name)
Definition: cbs_vp9.c:198
ff_spx_muxer
const FFOutputFormat ff_spx_muxer
AVCodecParameters::sample_aspect_ratio
AVRational sample_aspect_ratio
Video only.
Definition: codec_par.h:131
ogg_buffer_data
static int ogg_buffer_data(AVFormatContext *s, AVStream *st, const uint8_t *data, unsigned size, int64_t granule, int header)
Definition: oggenc.c:200
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
OGGStreamContext::last_kf_pts
int64_t last_kf_pts
Definition: oggenc.c:59
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:121
AV_OPT_TYPE_INT64
@ AV_OPT_TYPE_INT64
Definition: opt.h:226
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
ff_vorbiscomment_metadata_conv
const AVMetadataConv ff_vorbiscomment_metadata_conv[]
VorbisComment metadata conversion mapping.
Definition: vorbiscomment.c:33
OGGPage::granule
int64_t granule
Definition: oggenc.c:44
ogg_free
static void ogg_free(AVFormatContext *s)
Definition: oggenc.c:721
ogg_buffer_page
static int ogg_buffer_page(AVFormatContext *s, OGGStreamContext *oggstream)
Definition: oggenc.c:175
OGGStreamContext
Definition: oggenc.c:53
ff_opus_muxer
const FFOutputFormat ff_opus_muxer
AVFormatContext
Format I/O context.
Definition: avformat.h:1115
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:864
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
OGGContext::serial_offset
int serial_offset
Definition: oggenc.c:80
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:880
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:921
FLAC_STREAMINFO_SIZE
#define FLAC_STREAMINFO_SIZE
Definition: flac.h:32
FFOutputFormat
Definition: mux.h:32
AV_DICT_DONT_OVERWRITE
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
Definition: dict.h:81
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:226
options
static const AVOption options[]
Definition: oggenc.c:86
OGGStreamContext::header
uint8_t * header[3]
Definition: oggenc.c:55
ff_vorbiscomment_length
int64_t ff_vorbiscomment_length(const AVDictionary *m, const char *vendor_string, AVChapter **chapters, unsigned int nb_chapters)
Calculate the length in bytes of a VorbisComment.
Definition: vorbiscomment.c:41
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:171
OGGContext::pref_size
int pref_size
preferred page size (0 => fill all segments)
Definition: oggenc.c:78
MAX_PAGE_SIZE
#define MAX_PAGE_SIZE
Definition: oggenc.c:40
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:73
OGGPage::segments
uint8_t segments[255]
Definition: oggenc.c:48
AVPacket::size
int size
Definition: packet.h:492
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
FFIOContext::pub
AVIOContext pub
Definition: avio_internal.h:29
size
int size
Definition: twinvq_data.h:10344
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
PARAM
#define PARAM
Definition: oggenc.c:84
AV_CODEC_ID_OPUS
@ AV_CODEC_ID_OPUS
Definition: codec_id.h:502
header
static const uint8_t header[24]
Definition: sdr2.c:67
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:248
OGGPage::stream_index
int stream_index
Definition: oggenc.c:45
av_crc_get_table
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:497
OGGPage::data
uint8_t data[MAX_PAGE_SIZE]
Definition: oggenc.c:49
ff_ogv_muxer
const FFOutputFormat ff_ogv_muxer
ogg_build_opus_headers
static int ogg_build_opus_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m, AVChapter **chapters, unsigned int nb_chapters)
Definition: oggenc.c:371
bytestream_put_buffer
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:372
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:484
avio_internal.h
OGGPage::segments_count
uint8_t segments_count
Definition: oggenc.c:47
ogg_build_flac_headers
static int ogg_build_flac_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
Definition: oggenc.c:304
AV_CODEC_ID_THEORA
@ AV_CODEC_ID_THEORA
Definition: codec_id.h:82
AVCodecParameters::height
int height
Definition: codec_par.h:122
OGGPage::start_granule
int64_t start_granule
Definition: oggenc.c:43
else
else
Definition: snow.txt:125
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
ogg_write_trailer
static int ogg_write_trailer(AVFormatContext *s)
Definition: oggenc.c:704
len
int len
Definition: vorbis_enc_data.h:426
AV_CRC_32_IEEE
@ AV_CRC_32_IEEE
Definition: crc.h:52
FF_API_ALLOW_FLUSH
#define FF_API_ALLOW_FLUSH
Definition: version_major.h:50
ff_oga_muxer
const FFOutputFormat ff_oga_muxer
AVFMT_TS_NEGATIVE
#define AVFMT_TS_NEGATIVE
Format allows muxing negative timestamps.
Definition: avformat.h:495
AVFMT_TS_NONSTRICT
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:492
version.h
ret
ret
Definition: filter_design.txt:187
AVFMT_FLAG_BITEXACT
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1250
AVStream
Stream structure.
Definition: avformat.h:841
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
OGGContext
Definition: oggenc.c:75
OGGPage
Definition: oggenc.c:42
ogg_write_page
static void ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
Definition: oggenc.c:105
avformat.h
ffio_init_write_context
void ffio_init_write_context(FFIOContext *s, uint8_t *buffer, int buffer_size)
Wrap a buffer in an AVIOContext for writing.
Definition: aviobuf.c:139
OGGStreamContext::serial_num
unsigned serial_num
serial number
Definition: oggenc.c:66
random_seed.h
ogg_granule_to_timestamp
static int64_t ogg_granule_to_timestamp(OGGStreamContext *oggstream, int64_t granule)
Definition: oggenc.c:139
av_crc
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
Definition: crc.c:392
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
ogg_build_speex_headers
static int ogg_build_speex_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
Definition: oggenc.c:342
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:1007
OGGPage::size
uint16_t size
Definition: oggenc.c:50
OGGPage::flags
uint8_t flags
Definition: oggenc.c:46
OGGContext::page_list
OGGPageList * page_list
Definition: oggenc.c:77
OGGStreamContext::vrev
int vrev
Definition: oggenc.c:60
AVPacket::stream_index
int stream_index
Definition: packet.h:493
avpriv_split_xiph_headers
int avpriv_split_xiph_headers(const uint8_t *extradata, int extradata_size, int first_header_size, const uint8_t *header_start[3], int header_len[3])
Split a single extradata buffer into the three headers that most Xiph codecs use.
Definition: xiph.c:26
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:367
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:468
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:239
OGGStreamContext::kfgshift
int kfgshift
for theora granule
Definition: oggenc.c:58
bytestream.h
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:192
OGGStreamContext::header_len
int header_len[3]
Definition: oggenc.c:56
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
OPUS_HEADER_SIZE
#define OPUS_HEADER_SIZE
Definition: oggenc.c:369
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
AV_CODEC_ID_VORBIS
@ AV_CODEC_ID_VORBIS
Definition: codec_id.h:447
ogg_write_packet
static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: oggenc.c:687
flac.h
AVCodecParameters::initial_padding
int initial_padding
Audio only.
Definition: codec_par.h:190
AVIO_DATA_MARKER_FLUSH_POINT
@ AVIO_DATA_MARKER_FLUSH_POINT
A point in the output bytestream where the underlying AVIOContext might flush the buffer depending on...
Definition: avio.h:151
mux.h
ogg_key_granule
static int ogg_key_granule(OGGStreamContext *oggstream, int64_t granule)
Definition: oggenc.c:133
ogg_reset_cur_page
static int ogg_reset_cur_page(OGGStreamContext *oggstream)
Definition: oggenc.c:166