Libav
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 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 
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 OGGPage {
39  int64_t start_granule;
40  int64_t granule;
46  uint16_t size;
47 } OGGPage;
48 
49 typedef struct OGGStreamContext {
50  unsigned page_counter;
51  uint8_t *header[3];
52  int header_len[3];
54  int kfgshift;
55  int64_t last_kf_pts;
56  int vrev;
57  int eos;
58  unsigned page_count;
60  unsigned serial_num;
61  int64_t last_granule;
63 
64 typedef struct OGGPageList {
66  struct OGGPageList *next;
67 } OGGPageList;
68 
69 typedef struct OGGContext {
70  const AVClass *class;
72  int pref_size;
73  int64_t pref_duration;
75 } OGGContext;
76 
77 #define OFFSET(x) offsetof(OGGContext, x)
78 #define PARAM AV_OPT_FLAG_ENCODING_PARAM
79 
80 static const AVOption options[] = {
81  { "serial_offset", "serial number offset",
82  OFFSET(serial_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, PARAM },
83  { "pagesize", "preferred page size in bytes (deprecated)",
84  OFFSET(pref_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MAX_PAGE_SIZE, PARAM },
85  { "page_duration", "preferred page duration, in microseconds",
86  OFFSET(pref_duration), AV_OPT_TYPE_INT64, { .i64 = 1000000 }, 0, INT64_MAX, PARAM },
87  { NULL },
88 };
89 
90 #define OGG_CLASS(flavor)\
91 static const AVClass flavor ## _muxer_class = {\
92  .class_name = #flavor " muxer",\
93  .item_name = av_default_item_name,\
94  .option = options,\
95  .version = LIBAVUTIL_VERSION_INT,\
96 };
97 
98 static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset)
99 {
100  int64_t pos = avio_tell(pb);
101  uint32_t checksum = ffio_get_checksum(pb);
102  avio_seek(pb, crc_offset, SEEK_SET);
103  avio_wb32(pb, checksum);
104  avio_seek(pb, pos, SEEK_SET);
105 }
106 
107 static int ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
108 {
109  OGGStreamContext *oggstream = s->streams[page->stream_index]->priv_data;
110  AVIOContext *pb;
111  int64_t crc_offset;
112  int ret, size;
113  uint8_t *buf;
114 
115  ret = avio_open_dyn_buf(&pb);
116  if (ret < 0)
117  return ret;
119  ffio_wfourcc(pb, "OggS");
120  avio_w8(pb, 0);
121  avio_w8(pb, page->flags | extra_flags);
122  avio_wl64(pb, page->granule);
123  avio_wl32(pb, oggstream->serial_num);
124  avio_wl32(pb, oggstream->page_counter++);
125  crc_offset = avio_tell(pb);
126  avio_wl32(pb, 0); // crc
127  avio_w8(pb, page->segments_count);
128  avio_write(pb, page->segments, page->segments_count);
129  avio_write(pb, page->data, page->size);
130 
131  ogg_update_checksum(s, pb, crc_offset);
132  avio_flush(pb);
133 
134  size = avio_close_dyn_buf(pb, &buf);
135  if (size < 0)
136  return size;
137 
138  avio_write(s->pb, buf, size);
139  avio_flush(s->pb);
140  av_free(buf);
141  oggstream->page_count--;
142  return 0;
143 }
144 
145 static int64_t ogg_granule_to_timestamp(OGGStreamContext *oggstream, int64_t granule)
146 {
147  if (oggstream->kfgshift)
148  return (granule>>oggstream->kfgshift) +
149  (granule & ((1<<oggstream->kfgshift)-1));
150  else
151  return granule;
152 }
153 
155 {
156  AVStream *st2 = s->streams[next->stream_index];
157  AVStream *st = s->streams[page->stream_index];
158  int64_t next_granule, cur_granule;
159 
160  if (next->granule == -1 || page->granule == -1)
161  return 0;
162 
163  next_granule = av_rescale_q(ogg_granule_to_timestamp(st2->priv_data, next->granule),
164  st2->time_base, AV_TIME_BASE_Q);
165  cur_granule = av_rescale_q(ogg_granule_to_timestamp(st->priv_data, page->granule),
166  st ->time_base, AV_TIME_BASE_Q);
167  return next_granule > cur_granule;
168 }
169 
170 static int ogg_reset_cur_page(OGGStreamContext *oggstream)
171 {
172  oggstream->page.granule = -1;
173  oggstream->page.flags = 0;
174  oggstream->page.segments_count = 0;
175  oggstream->page.size = 0;
176  return 0;
177 }
178 
180 {
181  OGGContext *ogg = s->priv_data;
182  OGGPageList **p = &ogg->page_list;
183  OGGPageList *l = av_mallocz(sizeof(*l));
184 
185  if (!l)
186  return AVERROR(ENOMEM);
187  l->page = oggstream->page;
188 
189  oggstream->page.start_granule = oggstream->page.granule;
190  oggstream->page_count++;
191  ogg_reset_cur_page(oggstream);
192 
193  while (*p) {
194  if (ogg_compare_granule(s, &(*p)->page, &l->page))
195  break;
196  p = &(*p)->next;
197  }
198  l->next = *p;
199  *p = l;
200 
201  return 0;
202 }
203 
205  uint8_t *data, unsigned size, int64_t granule,
206  int header)
207 {
208  OGGStreamContext *oggstream = st->priv_data;
209  OGGContext *ogg = s->priv_data;
210  int total_segments = size / 255 + 1;
211  uint8_t *p = data;
212  int i, segments, len, flush = 0;
213 
214  // Handles VFR by flushing page because this frame needs to have a timestamp
215  if (st->codecpar->codec_id == AV_CODEC_ID_THEORA && !header &&
216  ogg_granule_to_timestamp(oggstream, granule) >
217  ogg_granule_to_timestamp(oggstream, oggstream->last_granule) + 1) {
218  if (oggstream->page.granule != -1)
219  ogg_buffer_page(s, oggstream);
220  flush = 1;
221  }
222 
223  // avoid a continued page
224  if (!header && oggstream->page.size > 0 &&
225  MAX_PAGE_SIZE - oggstream->page.size < size) {
226  ogg_buffer_page(s, oggstream);
227  }
228 
229  for (i = 0; i < total_segments; ) {
230  OGGPage *page = &oggstream->page;
231 
232  segments = FFMIN(total_segments - i, 255 - page->segments_count);
233 
234  if (i && !page->segments_count)
235  page->flags |= 1; // continued packet
236 
237  memset(page->segments+page->segments_count, 255, segments - 1);
238  page->segments_count += segments - 1;
239 
240  len = FFMIN(size, segments*255);
241  page->segments[page->segments_count++] = len - (segments-1)*255;
242  memcpy(page->data+page->size, p, len);
243  p += len;
244  size -= len;
245  i += segments;
246  page->size += len;
247 
248  if (i == total_segments)
249  page->granule = granule;
250 
251  if (!header) {
252  AVStream *st = s->streams[page->stream_index];
253 
254  int64_t start = av_rescale_q(page->start_granule, st->time_base,
256  int64_t next = av_rescale_q(page->granule, st->time_base,
258 
259  if (page->segments_count == 255 ||
260  (ogg->pref_size > 0 && page->size >= ogg->pref_size) ||
261  (ogg->pref_duration > 0 && next - start >= ogg->pref_duration)) {
262  ogg_buffer_page(s, oggstream);
263  }
264  }
265  }
266 
267  if (flush && oggstream->page.granule != -1)
268  ogg_buffer_page(s, oggstream);
269 
270  return 0;
271 }
272 
273 static uint8_t *ogg_write_vorbiscomment(int offset, int bitexact,
274  int *header_len, AVDictionary **m, int framing_bit)
275 {
276  const char *vendor = bitexact ? "Libav" : LIBAVFORMAT_IDENT;
277  int size;
278  uint8_t *p, *p0;
279 
281 
282  size = offset + ff_vorbiscomment_length(*m, vendor) + framing_bit;
283  p = av_mallocz(size);
284  if (!p)
285  return NULL;
286  p0 = p;
287 
288  p += offset;
289  ff_vorbiscomment_write(&p, m, vendor);
290  if (framing_bit)
291  bytestream_put_byte(&p, 1);
292 
293  *header_len = size;
294  return p0;
295 }
296 
298  OGGStreamContext *oggstream, int bitexact,
299  AVDictionary **m)
300 {
301  uint8_t *p;
302 
304  return AVERROR(EINVAL);
305 
306  // first packet: STREAMINFO
307  oggstream->header_len[0] = 51;
308  oggstream->header[0] = av_mallocz(51); // per ogg flac specs
309  p = oggstream->header[0];
310  if (!p)
311  return AVERROR(ENOMEM);
312  bytestream_put_byte(&p, 0x7F);
313  bytestream_put_buffer(&p, "FLAC", 4);
314  bytestream_put_byte(&p, 1); // major version
315  bytestream_put_byte(&p, 0); // minor version
316  bytestream_put_be16(&p, 1); // headers packets without this one
317  bytestream_put_buffer(&p, "fLaC", 4);
318  bytestream_put_byte(&p, 0x00); // streaminfo
319  bytestream_put_be24(&p, 34);
321 
322  // second packet: VorbisComment
323  p = ogg_write_vorbiscomment(4, bitexact, &oggstream->header_len[1], m, 0);
324  if (!p)
325  return AVERROR(ENOMEM);
326  oggstream->header[1] = p;
327  bytestream_put_byte(&p, 0x84); // last metadata block and vorbis comment
328  bytestream_put_be24(&p, oggstream->header_len[1] - 4);
329 
330  return 0;
331 }
332 
333 #define SPEEX_HEADER_SIZE 80
334 
336  OGGStreamContext *oggstream, int bitexact,
337  AVDictionary **m)
338 {
339  uint8_t *p;
340 
342  return -1;
343 
344  // first packet: Speex header
346  if (!p)
347  return AVERROR(ENOMEM);
348  oggstream->header[0] = p;
349  oggstream->header_len[0] = SPEEX_HEADER_SIZE;
351  AV_WL32(&oggstream->header[0][68], 0); // set extra_headers to 0
352 
353  // second packet: VorbisComment
354  p = ogg_write_vorbiscomment(0, bitexact, &oggstream->header_len[1], m, 0);
355  if (!p)
356  return AVERROR(ENOMEM);
357  oggstream->header[1] = p;
358 
359  return 0;
360 }
361 
362 #define OPUS_HEADER_SIZE 19
363 
365  OGGStreamContext *oggstream, int bitexact,
366  AVDictionary **m)
367 {
368  uint8_t *p;
369 
370  if (par->extradata_size < OPUS_HEADER_SIZE)
371  return -1;
372 
373  /* first packet: Opus header */
374  p = av_mallocz(par->extradata_size);
375  if (!p)
376  return AVERROR(ENOMEM);
377  oggstream->header[0] = p;
378  oggstream->header_len[0] = par->extradata_size;
380 
381  /* second packet: VorbisComment */
382  p = ogg_write_vorbiscomment(8, bitexact, &oggstream->header_len[1], m, 0);
383  if (!p)
384  return AVERROR(ENOMEM);
385  oggstream->header[1] = p;
386  bytestream_put_buffer(&p, "OpusTags", 8);
387 
388  return 0;
389 }
390 
392 {
393  OGGContext *ogg = s->priv_data;
394  OGGPageList *next, *p;
395 
396  if (!ogg->page_list)
397  return;
398 
399  for (p = ogg->page_list; p; ) {
400  OGGStreamContext *oggstream =
402  if (oggstream->page_count < 2 && !flush)
403  break;
404  ogg_write_page(s, &p->page,
405  flush == 1 && oggstream->page_count == 1 ? 4 : 0); // eos
406  next = p->next;
407  av_freep(&p);
408  p = next;
409  }
410  ogg->page_list = p;
411 }
412 
414 {
415  OGGContext *ogg = s->priv_data;
416  OGGStreamContext *oggstream;
417  int i, j;
418 
419  if (ogg->pref_size)
420  av_log(s, AV_LOG_WARNING, "The pagesize option is deprecated\n");
421 
422  for (i = 0; i < s->nb_streams; i++) {
423  AVStream *st = s->streams[i];
424  unsigned serial_num = i + ogg->serial_offset;
425 
427  if (st->codecpar->codec_id == AV_CODEC_ID_OPUS)
428  /* Opus requires a fixed 48kHz clock */
429  avpriv_set_pts_info(st, 64, 1, 48000);
430  else
431  avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
432 
433  if (st->codecpar->codec_id != AV_CODEC_ID_VORBIS &&
438  av_log(s, AV_LOG_ERROR, "Unsupported codec id in stream %d\n", i);
439  return -1;
440  }
441 
442  if (!st->codecpar->extradata || !st->codecpar->extradata_size) {
443  av_log(s, AV_LOG_ERROR, "No extradata present\n");
444  return -1;
445  }
446  oggstream = av_mallocz(sizeof(*oggstream));
447  if (!oggstream)
448  return AVERROR(ENOMEM);
449  oggstream->page.stream_index = i;
450 
451  if (!(s->flags & AVFMT_FLAG_BITEXACT))
452  do {
453  serial_num = av_get_random_seed();
454  for (j = 0; j < i; j++) {
455  OGGStreamContext *sc = s->streams[j]->priv_data;
456  if (serial_num == sc->serial_num)
457  break;
458  }
459  } while (j < i);
460  oggstream->serial_num = serial_num;
461 
462  st->priv_data = oggstream;
463  if (st->codecpar->codec_id == AV_CODEC_ID_FLAC) {
464  int err = ogg_build_flac_headers(st->codecpar, oggstream,
466  &s->metadata);
467  if (err) {
468  av_log(s, AV_LOG_ERROR, "Error writing FLAC headers\n");
469  av_freep(&st->priv_data);
470  return err;
471  }
472  } else if (st->codecpar->codec_id == AV_CODEC_ID_SPEEX) {
473  int err = ogg_build_speex_headers(st->codecpar, oggstream,
475  &s->metadata);
476  if (err) {
477  av_log(s, AV_LOG_ERROR, "Error writing Speex headers\n");
478  av_freep(&st->priv_data);
479  return err;
480  }
481  } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) {
482  int err = ogg_build_opus_headers(st->codecpar, oggstream,
484  &s->metadata);
485  if (err) {
486  av_log(s, AV_LOG_ERROR, "Error writing Opus headers\n");
487  av_freep(&st->priv_data);
488  return err;
489  }
490  } else {
491  uint8_t *p;
492  const char *cstr = st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? "vorbis" : "theora";
493  int header_type = st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? 3 : 0x81;
494  int framing_bit = st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? 1 : 0;
495 
497  st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? 30 : 42,
498  oggstream->header, oggstream->header_len) < 0) {
499  av_log(s, AV_LOG_ERROR, "Extradata corrupted\n");
500  av_freep(&st->priv_data);
501  return -1;
502  }
503 
505  &oggstream->header_len[1], &s->metadata,
506  framing_bit);
507  oggstream->header[1] = p;
508  if (!p)
509  return AVERROR(ENOMEM);
510 
511  bytestream_put_byte(&p, header_type);
512  bytestream_put_buffer(&p, cstr, 6);
513 
514  if (st->codecpar->codec_id == AV_CODEC_ID_THEORA) {
517  oggstream->kfgshift = ((oggstream->header[0][40]&3)<<3)|(oggstream->header[0][41]>>5);
518  oggstream->vrev = oggstream->header[0][9];
519  av_log(s, AV_LOG_DEBUG, "theora kfgshift %d, vrev %d\n",
520  oggstream->kfgshift, oggstream->vrev);
521  }
522  }
523  }
524 
525  for (j = 0; j < s->nb_streams; j++) {
526  OGGStreamContext *oggstream = s->streams[j]->priv_data;
527  ogg_buffer_data(s, s->streams[j], oggstream->header[0],
528  oggstream->header_len[0], 0, 1);
529  oggstream->page.flags |= 2; // bos
530  ogg_buffer_page(s, oggstream);
531  }
532  for (j = 0; j < s->nb_streams; j++) {
533  AVStream *st = s->streams[j];
534  OGGStreamContext *oggstream = st->priv_data;
535  for (i = 1; i < 3; i++) {
536  if (oggstream->header_len[i])
537  ogg_buffer_data(s, st, oggstream->header[i],
538  oggstream->header_len[i], 0, 1);
539  }
540  ogg_buffer_page(s, oggstream);
541  }
542 
543  oggstream->page.start_granule = AV_NOPTS_VALUE;
544 
545  ogg_write_pages(s, 2);
546 
547  return 0;
548 }
549 
551 {
552  AVStream *st = s->streams[pkt->stream_index];
553  OGGStreamContext *oggstream = st->priv_data;
554  int ret;
555  int64_t granule;
556 
557  if (st->codecpar->codec_id == AV_CODEC_ID_THEORA) {
558  int64_t pts = oggstream->vrev < 1 ? pkt->pts : pkt->pts + pkt->duration;
559  int pframe_count;
560  if (pkt->flags & AV_PKT_FLAG_KEY)
561  oggstream->last_kf_pts = pts;
562  pframe_count = pts - oggstream->last_kf_pts;
563  // prevent frame count from overflow if key frame flag is not set
564  if (pframe_count >= (1<<oggstream->kfgshift)) {
565  oggstream->last_kf_pts += pframe_count;
566  pframe_count = 0;
567  }
568  granule = (oggstream->last_kf_pts<<oggstream->kfgshift) | pframe_count;
569  } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS)
570  granule = pkt->pts + pkt->duration +
572  (AVRational){ 1, st->codecpar->sample_rate },
573  st->time_base);
574  else
575  granule = pkt->pts + pkt->duration;
576 
577  if (oggstream->page.start_granule == AV_NOPTS_VALUE)
578  oggstream->page.start_granule = pkt->pts;
579 
580  ret = ogg_buffer_data(s, st, pkt->data, pkt->size, granule, 0);
581  if (ret < 0)
582  return ret;
583 
584  ogg_write_pages(s, 0);
585 
586  oggstream->last_granule = granule;
587 
588  return 0;
589 }
590 
592 {
593  int i;
594 
595  if (pkt)
596  return ogg_write_packet_internal(s, pkt);
597 
598  for (i = 0; i < s->nb_streams; i++) {
599  OGGStreamContext *oggstream = s->streams[i]->priv_data;
600  if (oggstream->page.segments_count)
601  ogg_buffer_page(s, oggstream);
602  }
603 
604  ogg_write_pages(s, 2);
605  return 0;
606 }
607 
609 {
610  int i;
611 
612  /* flush current page if needed */
613  for (i = 0; i < s->nb_streams; i++) {
614  OGGStreamContext *oggstream = s->streams[i]->priv_data;
615 
616  if (oggstream->page.size > 0)
617  ogg_buffer_page(s, oggstream);
618  }
619 
620  ogg_write_pages(s, 1);
621 
622  for (i = 0; i < s->nb_streams; i++) {
623  AVStream *st = s->streams[i];
624  OGGStreamContext *oggstream = st->priv_data;
625  if (st->codecpar->codec_id == AV_CODEC_ID_FLAC ||
628  av_free(oggstream->header[0]);
629  }
630  av_freep(&oggstream->header[1]);
631  av_freep(&st->priv_data);
632  }
633  return 0;
634 }
635 
636 #if CONFIG_OGG_MUXER
637 OGG_CLASS(ogg)
638 AVOutputFormat ff_ogg_muxer = {
639  .name = "ogg",
640  .long_name = NULL_IF_CONFIG_SMALL("Ogg"),
641  .mime_type = "application/ogg",
642  .extensions = "ogg,ogv",
643  .priv_data_size = sizeof(OGGContext),
644  .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
646  .video_codec = AV_CODEC_ID_THEORA,
651  .priv_class = &ogg_muxer_class,
652 };
653 #endif
654 
655 #if CONFIG_OGA_MUXER
656 OGG_CLASS(oga)
657 AVOutputFormat ff_oga_muxer = {
658  .name = "oga",
659  .long_name = NULL_IF_CONFIG_SMALL("Ogg Audio"),
660  .mime_type = "audio/ogg",
661  .extensions = "oga",
662  .priv_data_size = sizeof(OGGContext),
663  .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
669  .priv_class = &oga_muxer_class,
670 };
671 #endif
672 
673 #if CONFIG_SPX_MUXER
674 OGG_CLASS(spx)
675 AVOutputFormat ff_spx_muxer = {
676  .name = "spx",
677  .long_name = NULL_IF_CONFIG_SMALL("Ogg Speex"),
678  .mime_type = "audio/ogg",
679  .extensions = "spx",
680  .priv_data_size = sizeof(OGGContext),
681  .audio_codec = AV_CODEC_ID_SPEEX,
686  .priv_class = &spx_muxer_class,
687 };
688 #endif
689 
690 #if CONFIG_OPUS_MUXER
691 OGG_CLASS(opus)
692 AVOutputFormat ff_opus_muxer = {
693  .name = "opus",
694  .long_name = NULL_IF_CONFIG_SMALL("Ogg Opus"),
695  .mime_type = "audio/ogg",
696  .extensions = "opus",
697  .priv_data_size = sizeof(OGGContext),
698  .audio_codec = AV_CODEC_ID_OPUS,
703  .priv_class = &opus_muxer_class,
704 };
705 #endif
int header_len[3]
Definition: oggenc.c:52
static int ogg_write_header(AVFormatContext *s)
Definition: oggenc.c:413
int64_t granule
Definition: oggenc.c:40
int64_t last_granule
last packet granule
Definition: oggenc.c:61
Bytestream IO Context.
Definition: avio.h:104
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1155
AVOption.
Definition: opt.h:234
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:130
unsigned page_count
number of page buffered
Definition: oggenc.c:58
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:2986
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3483
int size
Definition: avcodec.h:1347
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:242
uint8_t data[MAX_PAGE_SIZE]
Definition: oggenc.c:45
OGGPage page
Definition: oggenc.c:65
void * priv_data
Definition: avformat.h:720
OGGPage page
current page
Definition: oggenc.c:59
#define AVFMT_ALLOW_FLUSH
Format allows flushing.
Definition: avformat.h:429
#define OGG_CLASS(flavor)
Definition: oggenc.c:90
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1143
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3475
#define OPUS_HEADER_SIZE
Definition: oggenc.c:362
int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m, const char *vendor_string)
Write a VorbisComment into a buffer.
Definition: vorbiscomment.c:53
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:202
static int ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
Definition: oggenc.c:107
Format I/O context.
Definition: avformat.h:940
static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset)
Definition: oggenc.c:98
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:316
uint8_t
AVOptions.
uint16_t size
Definition: oggenc.c:46
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1364
#define MAX_PAGE_SIZE
Definition: oggenc.c:36
uint8_t segments_count
Definition: oggenc.c:43
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1008
static int ogg_build_speex_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
Definition: oggenc.c:335
int64_t last_kf_pts
Definition: oggenc.c:55
int initial_padding
Audio only.
Definition: avcodec.h:3579
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1051
uint8_t * data
Definition: avcodec.h:1346
int ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string)
Calculate the length in bytes of a VorbisComment.
Definition: vorbiscomment.c:40
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:295
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:221
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
Definition: avio_internal.h:66
Definition: oggenc.c:38
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1068
static const AVOption options[]
Definition: oggenc.c:80
static int write_trailer(AVFormatContext *s)
Definition: assenc.c:64
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1378
static int ogg_build_flac_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
Definition: oggenc.c:297
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:386
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:99
unsigned page_counter
Definition: oggenc.c:50
const AVMetadataConv ff_vorbiscomment_metadata_conv[]
VorbisComment metadata conversion mapping.
Definition: vorbiscomment.c:33
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1148
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:190
static int ogg_buffer_data(AVFormatContext *s, AVStream *st, uint8_t *data, unsigned size, int64_t granule, int header)
Definition: oggenc.c:204
static int ogg_build_opus_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
Definition: oggenc.c:364
FLAC (Free Lossless Audio Codec) decoder/demuxer common functions.
int64_t start_granule
Definition: oggenc.c:39
#define AVERROR(e)
Definition: error.h:43
struct OGGPageList * next
Definition: oggenc.c:66
int pref_size
preferred page size (0 => fill all segments)
Definition: oggenc.c:72
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:145
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3479
uint8_t flags
Definition: oggenc.c:42
static int ogg_reset_cur_page(OGGStreamContext *oggstream)
Definition: oggenc.c:170
static int64_t ogg_granule_to_timestamp(OGGStreamContext *oggstream, int64_t granule)
Definition: oggenc.c:145
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1352
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3501
static int ogg_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
Definition: oggenc.c:550
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:996
static int ogg_write_trailer(AVFormatContext *s)
Definition: oggenc.c:608
#define LIBAVFORMAT_IDENT
Definition: version.h:44
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
Definition: aviobuf.c:524
int void avio_flush(AVIOContext *s)
Definition: aviobuf.c:236
#define FFMIN(a, b)
Definition: common.h:66
int serial_offset
Definition: oggenc.c:74
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:504
const char * name
Definition: avformat.h:450
static int ogg_compare_granule(AVFormatContext *s, OGGPage *next, OGGPage *page)
Definition: oggenc.c:154
#define FLAC_STREAMINFO_SIZE
Definition: flac.h:34
#define CONFIG_LIBVORBIS_ENCODER
Definition: config.h:1162
static volatile int checksum
Definition: adler32.c:27
uint8_t * header[3]
Definition: oggenc.c:51
#define SPEEX_HEADER_SIZE
Definition: oggenc.c:333
Stream structure.
Definition: avformat.h:705
NULL
Definition: eval.c:55
static uint8_t * ogg_write_vorbiscomment(int offset, int bitexact, int *header_len, AVDictionary **m, int framing_bit)
Definition: oggenc.c:273
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:247
AVIOContext * pb
I/O context.
Definition: avformat.h:982
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:200
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
Definition: avconv.c:278
static int ogg_buffer_page(AVFormatContext *s, OGGStreamContext *oggstream)
Definition: oggenc.c:179
int stream_index
Definition: oggenc.c:41
static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: oggenc.c:591
Describe the class of an AVClass context structure.
Definition: log.h:34
rational number numerator/denominator
Definition: rational.h:43
unsigned long ffio_get_checksum(AVIOContext *s)
Definition: aviobuf.c:516
int avpriv_split_xiph_headers(uint8_t *extradata, int extradata_size, int first_header_size, 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:24
unsigned serial_num
serial number
Definition: oggenc.c:60
#define PARAM
Definition: oggenc.c:78
static int64_t pts
Global timestamp for the audio frames.
OGGPageList * page_list
Definition: oggenc.c:71
int sample_rate
Audio only.
Definition: avcodec.h:3564
Main libavformat public API header.
#define OFFSET(x)
Definition: oggenc.c:77
static av_cold void flush(AVCodecContext *avctx)
Flush (reset) the frame ID after seeking.
Definition: alsdec.c:1797
int kfgshift
for theora granule
Definition: oggenc.c:54
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:26
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:365
Definition: oggdec.h:96
int len
void * priv_data
Format private data.
Definition: avformat.h:968
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:373
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3497
#define AV_WL32(p, val)
Definition: intreadwrite.h:263
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:324
uint8_t segments[255]
Definition: oggenc.c:44
uint32_t av_get_random_seed(void)
Get random data.
Definition: random_seed.c:95
AVCodecParameters * codecpar
Definition: avformat.h:831
int stream_index
Definition: avcodec.h:1348
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:742
int64_t pref_duration
preferred page duration (0 => fill all segments)
Definition: oggenc.c:73
#define AVFMT_TS_NEGATIVE
Format allows muxing negative timestamps.
Definition: avformat.h:435
static void ogg_write_pages(AVFormatContext *s, int flush)
Definition: oggenc.c:391
This structure stores compressed data.
Definition: avcodec.h:1323
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:211
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1339
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:235