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 "libavutil/crc.h"
23 #include "libavutil/opt.h"
24 #include "libavutil/mathematics.h"
25 #include "libavutil/opt.h"
26 #include "libavutil/random_seed.h"
27 #include "libavcodec/xiph.h"
28 #include "libavcodec/bytestream.h"
29 #include "libavcodec/flac.h"
30 #include "avformat.h"
31 #include "avio_internal.h"
32 #include "internal.h"
33 #include "vorbiscomment.h"
34 
35 #define MAX_PAGE_SIZE 65025
36 
37 typedef struct {
38  int64_t start_granule;
39  int64_t granule;
45  uint16_t size;
46 } OGGPage;
47 
48 typedef struct {
49  unsigned page_counter;
51  int header_len[3];
52  /** for theora granule */
53  int kfgshift;
54  int64_t last_kf_pts;
55  int vrev;
56  int eos;
57  unsigned page_count; ///< number of page buffered
58  OGGPage page; ///< current page
59  unsigned serial_num; ///< serial number
60  int64_t last_granule; ///< last packet granule
62 
63 typedef struct OGGPageList {
65  struct OGGPageList *next;
66 } OGGPageList;
67 
68 typedef struct {
69  const AVClass *class;
71  int pref_size; ///< preferred page size (0 => fill all segments)
72  int64_t pref_duration; ///< preferred page duration (0 => fill all segments)
73 } OGGContext;
74 
75 #define OFFSET(x) offsetof(OGGContext, x)
76 #define PARAM AV_OPT_FLAG_ENCODING_PARAM
77 
78 static const AVOption options[] = {
79  { "oggpagesize", "Set preferred Ogg page size.",
80  offsetof(OGGContext, pref_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, MAX_PAGE_SIZE, AV_OPT_FLAG_ENCODING_PARAM},
81  { "pagesize", "preferred page size in bytes (deprecated)",
82  OFFSET(pref_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MAX_PAGE_SIZE, PARAM },
83  { "page_duration", "preferred page duration, in microseconds",
84  OFFSET(pref_duration), AV_OPT_TYPE_INT64, { .i64 = 1000000 }, 0, INT64_MAX, PARAM },
85  { NULL },
86 };
87 
88 static const AVClass ogg_muxer_class = {
89  .class_name = "Ogg muxer",
90  .item_name = av_default_item_name,
91  .option = options,
92  .version = LIBAVUTIL_VERSION_INT,
93 };
94 
95 
96 static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset)
97 {
98  int64_t pos = avio_tell(pb);
99  uint32_t checksum = ffio_get_checksum(pb);
100  avio_seek(pb, crc_offset, SEEK_SET);
101  avio_wb32(pb, checksum);
102  avio_seek(pb, pos, SEEK_SET);
103 }
104 
105 static int ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
106 {
107  OGGStreamContext *oggstream = s->streams[page->stream_index]->priv_data;
108  AVIOContext *pb;
109  int64_t crc_offset;
110  int ret, size;
111  uint8_t *buf;
112 
113  ret = avio_open_dyn_buf(&pb);
114  if (ret < 0)
115  return ret;
117  ffio_wfourcc(pb, "OggS");
118  avio_w8(pb, 0);
119  avio_w8(pb, page->flags | extra_flags);
120  avio_wl64(pb, page->granule);
121  avio_wl32(pb, oggstream->serial_num);
122  avio_wl32(pb, oggstream->page_counter++);
123  crc_offset = avio_tell(pb);
124  avio_wl32(pb, 0); // crc
125  avio_w8(pb, page->segments_count);
126  avio_write(pb, page->segments, page->segments_count);
127  avio_write(pb, page->data, page->size);
128 
129  ogg_update_checksum(s, pb, crc_offset);
130  avio_flush(pb);
131 
132  size = avio_close_dyn_buf(pb, &buf);
133  if (size < 0)
134  return size;
135 
136  avio_write(s->pb, buf, size);
137  avio_flush(s->pb);
138  av_free(buf);
139  oggstream->page_count--;
140  return 0;
141 }
142 
143 static int ogg_key_granule(OGGStreamContext *oggstream, int64_t granule)
144 {
145  return oggstream->kfgshift && !(granule & ((1<<oggstream->kfgshift)-1));
146 }
147 
148 static int64_t ogg_granule_to_timestamp(OGGStreamContext *oggstream, int64_t granule)
149 {
150  if (oggstream->kfgshift)
151  return (granule>>oggstream->kfgshift) +
152  (granule & ((1<<oggstream->kfgshift)-1));
153  else
154  return granule;
155 }
156 
158 {
159  AVStream *st2 = s->streams[next->stream_index];
160  AVStream *st = s->streams[page->stream_index];
161  int64_t next_granule, cur_granule;
162 
163  if (next->granule == -1 || page->granule == -1)
164  return 0;
165 
166  next_granule = av_rescale_q(ogg_granule_to_timestamp(st2->priv_data, next->granule),
167  st2->time_base, AV_TIME_BASE_Q);
168  cur_granule = av_rescale_q(ogg_granule_to_timestamp(st->priv_data, page->granule),
169  st ->time_base, AV_TIME_BASE_Q);
170  return next_granule > cur_granule;
171 }
172 
173 static int ogg_reset_cur_page(OGGStreamContext *oggstream)
174 {
175  oggstream->page.granule = -1;
176  oggstream->page.flags = 0;
177  oggstream->page.segments_count = 0;
178  oggstream->page.size = 0;
179  return 0;
180 }
181 
183 {
184  OGGContext *ogg = s->priv_data;
185  OGGPageList **p = &ogg->page_list;
186  OGGPageList *l = av_mallocz(sizeof(*l));
187 
188  if (!l)
189  return AVERROR(ENOMEM);
190  l->page = oggstream->page;
191 
192  oggstream->page.start_granule = oggstream->page.granule;
193  oggstream->page_count++;
194  ogg_reset_cur_page(oggstream);
195 
196  while (*p) {
197  if (ogg_compare_granule(s, &(*p)->page, &l->page))
198  break;
199  p = &(*p)->next;
200  }
201  l->next = *p;
202  *p = l;
203 
204  return 0;
205 }
206 
208  uint8_t *data, unsigned size, int64_t granule,
209  int header)
210 {
211  OGGStreamContext *oggstream = st->priv_data;
212  OGGContext *ogg = s->priv_data;
213  int total_segments = size / 255 + 1;
214  uint8_t *p = data;
215  int i, segments, len, flush = 0;
216 
217  // Handles VFR by flushing page because this frame needs to have a timestamp
218  // For theora, keyframes also need to have a timestamp to correctly mark
219  // them as such, otherwise seeking will not work correctly at the very
220  // least with old libogg versions.
221  // Do not try to flush header packets though, that will create broken files.
222  if (st->codec->codec_id == AV_CODEC_ID_THEORA && !header &&
223  (ogg_granule_to_timestamp(oggstream, granule) >
224  ogg_granule_to_timestamp(oggstream, oggstream->last_granule) + 1 ||
225  ogg_key_granule(oggstream, granule))) {
226  if (oggstream->page.granule != -1)
227  ogg_buffer_page(s, oggstream);
228  flush = 1;
229  }
230 
231  // avoid a continued page
232  if (!header && oggstream->page.size > 0 &&
233  MAX_PAGE_SIZE - oggstream->page.size < size) {
234  ogg_buffer_page(s, oggstream);
235  }
236 
237  for (i = 0; i < total_segments; ) {
238  OGGPage *page = &oggstream->page;
239 
240  segments = FFMIN(total_segments - i, 255 - page->segments_count);
241 
242  if (i && !page->segments_count)
243  page->flags |= 1; // continued packet
244 
245  memset(page->segments+page->segments_count, 255, segments - 1);
246  page->segments_count += segments - 1;
247 
248  len = FFMIN(size, segments*255);
249  page->segments[page->segments_count++] = len - (segments-1)*255;
250  memcpy(page->data+page->size, p, len);
251  p += len;
252  size -= len;
253  i += segments;
254  page->size += len;
255 
256  if (i == total_segments)
257  page->granule = granule;
258 
259  if (!header) {
260  AVStream *st = s->streams[page->stream_index];
261 
262  int64_t start = av_rescale_q(page->start_granule, st->time_base,
264  int64_t next = av_rescale_q(page->granule, st->time_base,
266 
267  if (page->segments_count == 255 ||
268  (ogg->pref_size > 0 && page->size >= ogg->pref_size) ||
269  (ogg->pref_duration > 0 && next - start >= ogg->pref_duration)) {
270  ogg_buffer_page(s, oggstream);
271  }
272  }
273  }
274 
275  if (flush && oggstream->page.granule != -1)
276  ogg_buffer_page(s, oggstream);
277 
278  return 0;
279 }
280 
281 static uint8_t *ogg_write_vorbiscomment(int offset, int bitexact,
282  int *header_len, AVDictionary **m, int framing_bit)
283 {
284  const char *vendor = bitexact ? "ffmpeg" : LIBAVFORMAT_IDENT;
285  int size;
286  uint8_t *p, *p0;
287  unsigned int count;
288 
290 
291  size = offset + ff_vorbiscomment_length(*m, vendor, &count) + framing_bit;
292  p = av_mallocz(size);
293  if (!p)
294  return NULL;
295  p0 = p;
296 
297  p += offset;
298  ff_vorbiscomment_write(&p, m, vendor, count);
299  if (framing_bit)
300  bytestream_put_byte(&p, 1);
301 
302  *header_len = size;
303  return p0;
304 }
305 
307  OGGStreamContext *oggstream, int bitexact,
308  AVDictionary **m)
309 {
311  uint8_t *streaminfo;
312  uint8_t *p;
313 
314  if (!avpriv_flac_is_extradata_valid(avctx, &format, &streaminfo))
315  return -1;
316 
317  // first packet: STREAMINFO
318  oggstream->header_len[0] = 51;
319  oggstream->header[0] = av_mallocz(51); // per ogg flac specs
320  p = oggstream->header[0];
321  if (!p)
322  return AVERROR(ENOMEM);
323  bytestream_put_byte(&p, 0x7F);
324  bytestream_put_buffer(&p, "FLAC", 4);
325  bytestream_put_byte(&p, 1); // major version
326  bytestream_put_byte(&p, 0); // minor version
327  bytestream_put_be16(&p, 1); // headers packets without this one
328  bytestream_put_buffer(&p, "fLaC", 4);
329  bytestream_put_byte(&p, 0x00); // streaminfo
330  bytestream_put_be24(&p, 34);
332 
333  // second packet: VorbisComment
334  p = ogg_write_vorbiscomment(4, bitexact, &oggstream->header_len[1], m, 0);
335  if (!p)
336  return AVERROR(ENOMEM);
337  oggstream->header[1] = p;
338  bytestream_put_byte(&p, 0x84); // last metadata block and vorbis comment
339  bytestream_put_be24(&p, oggstream->header_len[1] - 4);
340 
341  return 0;
342 }
343 
344 #define SPEEX_HEADER_SIZE 80
345 
347  OGGStreamContext *oggstream, int bitexact,
348  AVDictionary **m)
349 {
350  uint8_t *p;
351 
352  if (avctx->extradata_size < SPEEX_HEADER_SIZE)
353  return -1;
354 
355  // first packet: Speex header
357  if (!p)
358  return AVERROR(ENOMEM);
359  oggstream->header[0] = p;
360  oggstream->header_len[0] = SPEEX_HEADER_SIZE;
362  AV_WL32(&oggstream->header[0][68], 0); // set extra_headers to 0
363 
364  // second packet: VorbisComment
365  p = ogg_write_vorbiscomment(0, bitexact, &oggstream->header_len[1], m, 0);
366  if (!p)
367  return AVERROR(ENOMEM);
368  oggstream->header[1] = p;
369 
370  return 0;
371 }
372 
373 #define OPUS_HEADER_SIZE 19
374 
376  OGGStreamContext *oggstream, int bitexact,
377  AVDictionary **m)
378 {
379  uint8_t *p;
380 
381  if (avctx->extradata_size < OPUS_HEADER_SIZE)
382  return -1;
383 
384  /* first packet: Opus header */
385  p = av_mallocz(avctx->extradata_size);
386  if (!p)
387  return AVERROR(ENOMEM);
388  oggstream->header[0] = p;
389  oggstream->header_len[0] = avctx->extradata_size;
390  bytestream_put_buffer(&p, avctx->extradata, avctx->extradata_size);
391 
392  /* second packet: VorbisComment */
393  p = ogg_write_vorbiscomment(8, bitexact, &oggstream->header_len[1], m, 0);
394  if (!p)
395  return AVERROR(ENOMEM);
396  oggstream->header[1] = p;
397  bytestream_put_buffer(&p, "OpusTags", 8);
398 
399  return 0;
400 }
401 
403 {
404  OGGContext *ogg = s->priv_data;
405  OGGStreamContext *oggstream = NULL;
406  int i, j;
407 
408  if (ogg->pref_size)
409  av_log(s, AV_LOG_WARNING, "The pagesize option is deprecated\n");
410 
411  for (i = 0; i < s->nb_streams; i++) {
412  AVStream *st = s->streams[i];
413  unsigned serial_num = i;
414 
415  if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
416  if (st->codec->codec_id == AV_CODEC_ID_OPUS)
417  /* Opus requires a fixed 48kHz clock */
418  avpriv_set_pts_info(st, 64, 1, 48000);
419  else
420  avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
421  } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
423  if (st->codec->codec_id != AV_CODEC_ID_VORBIS &&
425  st->codec->codec_id != AV_CODEC_ID_SPEEX &&
426  st->codec->codec_id != AV_CODEC_ID_FLAC &&
427  st->codec->codec_id != AV_CODEC_ID_OPUS) {
428  av_log(s, AV_LOG_ERROR, "Unsupported codec id in stream %d\n", i);
429  return -1;
430  }
431 
432  if (!st->codec->extradata || !st->codec->extradata_size) {
433  av_log(s, AV_LOG_ERROR, "No extradata present\n");
434  return -1;
435  }
436  oggstream = av_mallocz(sizeof(*oggstream));
437  oggstream->page.stream_index = i;
438 
439  if (!(st->codec->flags & CODEC_FLAG_BITEXACT))
440  do {
441  serial_num = av_get_random_seed();
442  for (j = 0; j < i; j++) {
443  OGGStreamContext *sc = s->streams[j]->priv_data;
444  if (serial_num == sc->serial_num)
445  break;
446  }
447  } while (j < i);
448  oggstream->serial_num = serial_num;
449 
450  st->priv_data = oggstream;
451  if (st->codec->codec_id == AV_CODEC_ID_FLAC) {
452  int err = ogg_build_flac_headers(st->codec, oggstream,
454  &s->metadata);
455  if (err) {
456  av_log(s, AV_LOG_ERROR, "Error writing FLAC headers\n");
457  av_freep(&st->priv_data);
458  return err;
459  }
460  } else if (st->codec->codec_id == AV_CODEC_ID_SPEEX) {
461  int err = ogg_build_speex_headers(st->codec, oggstream,
463  &s->metadata);
464  if (err) {
465  av_log(s, AV_LOG_ERROR, "Error writing Speex headers\n");
466  av_freep(&st->priv_data);
467  return err;
468  }
469  } else if (st->codec->codec_id == AV_CODEC_ID_OPUS) {
470  int err = ogg_build_opus_headers(st->codec, oggstream,
472  &s->metadata);
473  if (err) {
474  av_log(s, AV_LOG_ERROR, "Error writing Opus headers\n");
475  av_freep(&st->priv_data);
476  return err;
477  }
478  } else {
479  uint8_t *p;
480  const char *cstr = st->codec->codec_id == AV_CODEC_ID_VORBIS ? "vorbis" : "theora";
481  int header_type = st->codec->codec_id == AV_CODEC_ID_VORBIS ? 3 : 0x81;
482  int framing_bit = st->codec->codec_id == AV_CODEC_ID_VORBIS ? 1 : 0;
483 
485  st->codec->codec_id == AV_CODEC_ID_VORBIS ? 30 : 42,
486  oggstream->header, oggstream->header_len) < 0) {
487  av_log(s, AV_LOG_ERROR, "Extradata corrupted\n");
488  av_freep(&st->priv_data);
489  return -1;
490  }
491 
493  &oggstream->header_len[1], &s->metadata,
494  framing_bit);
495  oggstream->header[1] = p;
496  if (!p)
497  return AVERROR(ENOMEM);
498 
499  bytestream_put_byte(&p, header_type);
500  bytestream_put_buffer(&p, cstr, 6);
501 
502  if (st->codec->codec_id == AV_CODEC_ID_THEORA) {
503  /** KFGSHIFT is the width of the less significant section of the granule position
504  The less significant section is the frame count since the last keyframe */
505  oggstream->kfgshift = ((oggstream->header[0][40]&3)<<3)|(oggstream->header[0][41]>>5);
506  oggstream->vrev = oggstream->header[0][9];
507  av_log(s, AV_LOG_DEBUG, "theora kfgshift %d, vrev %d\n",
508  oggstream->kfgshift, oggstream->vrev);
509  }
510  }
511  }
512 
513  for (j = 0; j < s->nb_streams; j++) {
514  OGGStreamContext *oggstream = s->streams[j]->priv_data;
515  ogg_buffer_data(s, s->streams[j], oggstream->header[0],
516  oggstream->header_len[0], 0, 1);
517  oggstream->page.flags |= 2; // bos
518  ogg_buffer_page(s, oggstream);
519  }
520  for (j = 0; j < s->nb_streams; j++) {
521  AVStream *st = s->streams[j];
522  OGGStreamContext *oggstream = st->priv_data;
523  for (i = 1; i < 3; i++) {
524  if (oggstream->header_len[i])
525  ogg_buffer_data(s, st, oggstream->header[i],
526  oggstream->header_len[i], 0, 1);
527  }
528  ogg_buffer_page(s, oggstream);
529  }
530 
531  oggstream->page.start_granule = AV_NOPTS_VALUE;
532 
533  return 0;
534 }
535 
537 {
538  OGGContext *ogg = s->priv_data;
539  OGGPageList *next, *p;
540 
541  if (!ogg->page_list)
542  return;
543 
544  for (p = ogg->page_list; p; ) {
545  OGGStreamContext *oggstream =
547  if (oggstream->page_count < 2 && !flush)
548  break;
549  ogg_write_page(s, &p->page,
550  flush && oggstream->page_count == 1 ? 4 : 0); // eos
551  next = p->next;
552  av_freep(&p);
553  p = next;
554  }
555  ogg->page_list = p;
556 }
557 
559 {
560  AVStream *st = s->streams[pkt->stream_index];
561  OGGStreamContext *oggstream = st->priv_data;
562  int ret;
563  int64_t granule;
564 
565  if (st->codec->codec_id == AV_CODEC_ID_THEORA) {
566  int64_t pts = oggstream->vrev < 1 ? pkt->pts : pkt->pts + pkt->duration;
567  int pframe_count;
568  if (pkt->flags & AV_PKT_FLAG_KEY)
569  oggstream->last_kf_pts = pts;
570  pframe_count = pts - oggstream->last_kf_pts;
571  // prevent frame count from overflow if key frame flag is not set
572  if (pframe_count >= (1<<oggstream->kfgshift)) {
573  oggstream->last_kf_pts += pframe_count;
574  pframe_count = 0;
575  }
576  granule = (oggstream->last_kf_pts<<oggstream->kfgshift) | pframe_count;
577  } else if (st->codec->codec_id == AV_CODEC_ID_OPUS)
578  granule = pkt->pts + pkt->duration + av_rescale_q(st->codec->delay, (AVRational){ 1, st->codec->sample_rate }, st->time_base);
579  else
580  granule = pkt->pts + pkt->duration;
581 
582  if (oggstream->page.start_granule == AV_NOPTS_VALUE)
583  oggstream->page.start_granule = pkt->pts;
584 
585  ret = ogg_buffer_data(s, st, pkt->data, pkt->size, granule, 0);
586  if (ret < 0)
587  return ret;
588 
589  ogg_write_pages(s, 0);
590 
591  oggstream->last_granule = granule;
592 
593  return 0;
594 }
595 
597 {
598  int i;
599 
600  /* flush current page if needed */
601  for (i = 0; i < s->nb_streams; i++) {
602  OGGStreamContext *oggstream = s->streams[i]->priv_data;
603 
604  if (oggstream->page.size > 0)
605  ogg_buffer_page(s, oggstream);
606  }
607 
608  ogg_write_pages(s, 1);
609 
610  for (i = 0; i < s->nb_streams; i++) {
611  AVStream *st = s->streams[i];
612  OGGStreamContext *oggstream = st->priv_data;
613  if (st->codec->codec_id == AV_CODEC_ID_FLAC ||
614  st->codec->codec_id == AV_CODEC_ID_SPEEX ||
615  st->codec->codec_id == AV_CODEC_ID_OPUS) {
616  av_freep(&oggstream->header[0]);
617  }
618  av_freep(&oggstream->header[1]);
619  av_freep(&st->priv_data);
620  }
621  return 0;
622 }
623 
625  .name = "ogg",
626  .long_name = NULL_IF_CONFIG_SMALL("Ogg"),
627  .mime_type = "application/ogg",
628  .extensions = "ogg,ogv,spx,opus",
629  .priv_data_size = sizeof(OGGContext),
630  .audio_codec = AV_CODEC_ID_FLAC,
631  .video_codec = AV_CODEC_ID_THEORA,
635  .priv_class = &ogg_muxer_class,
636 };
int header_len[3]
Definition: oggenc.c:51
static int ogg_write_header(AVFormatContext *s)
Definition: oggenc.c:402
int header
Definition: oggdec.h:78
Definition: start.py:1
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:205
int64_t granule
Definition: oggenc.c:39
int64_t last_granule
last packet granule
Definition: oggenc.c:60
const char * s
Definition: avisynth_c.h:668
int ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string, unsigned *count)
Calculate the length in bytes of a VorbisComment.
Definition: vorbiscomment.c:40
Bytestream IO Context.
Definition: avio.h:68
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:988
AVOption.
Definition: opt.h:251
static int ogg_build_speex_headers(AVCodecContext *avctx, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
Definition: oggenc.c:346
av_default_item_name
unsigned page_count
number of page buffered
Definition: oggenc.c:57
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.
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
static int write_packet(AVFormatContext *s, AVPacket *pkt)
int num
numerator
Definition: rational.h:44
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:199
uint8_t data[MAX_PAGE_SIZE]
Definition: oggenc.c:44
int avpriv_flac_is_extradata_valid(AVCodecContext *avctx, enum FLACExtradataFormat *format, uint8_t **streaminfo_start)
Validate the FLAC extradata.
Definition: flac.c:169
OGGPage page
Definition: oggenc.c:64
void * priv_data
Definition: avformat.h:663
OGGPage page
current page
Definition: oggenc.c:58
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:976
#define OPUS_HEADER_SIZE
Definition: oggenc.c:373
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
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:198
static int ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
Definition: oggenc.c:105
Format I/O context.
Definition: avformat.h:944
static int ogg_build_flac_headers(AVCodecContext *avctx, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
Definition: oggenc.c:306
static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset)
Definition: oggenc.c:96
#define AV_WL32(p, darg)
Definition: intreadwrite.h:282
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:55
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:291
uint8_t
AVOptions.
window constants for m
uint16_t size
Definition: oggenc.c:45
static AVPacket pkt
Definition: demuxing.c:56
#define MAX_PAGE_SIZE
Definition: oggenc.c:35
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint8_t segments_count
Definition: oggenc.c:42
AVStream ** streams
Definition: avformat.h:992
int64_t last_kf_pts
Definition: oggenc.c:54
uint8_t * data
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:248
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:173
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
Definition: avio_internal.h:50
Definition: oggenc.c:37
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static const AVOption options[]
Definition: oggenc.c:78
static const AVClass ogg_muxer_class
Definition: oggenc.c:88
static int write_trailer(AVFormatContext *s)
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:281
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:355
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:130
FLACExtradataFormat
Definition: flac.h:57
unsigned page_counter
Definition: oggenc.c:49
const AVMetadataConv ff_vorbiscomment_metadata_conv[]
VorbisComment metadata conversion mapping.
Definition: vorbiscomment.c:33
AVDictionary * metadata
Definition: avformat.h:1092
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
static int ogg_buffer_data(AVFormatContext *s, AVStream *st, uint8_t *data, unsigned size, int64_t granule, int header)
Definition: oggenc.c:207
FLAC (Free Lossless Audio Codec) decoder/demuxer common functions.
int64_t start_granule
Definition: oggenc.c:38
struct OGGPageList * next
Definition: oggenc.c:65
int pref_size
preferred page size (0 => fill all segments)
Definition: oggenc.c:71
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Spectrum Plot time data
int flags
CODEC_FLAG_*.
int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m, const char *vendor_string, const unsigned count)
Write a VorbisComment into a buffer.
Definition: vorbiscomment.c:56
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
static const uint8_t offset[127][2]
Definition: vf_spp.c:70
uint8_t flags
Definition: oggenc.c:41
uint8_t segments[255]
Definition: oggdec.h:80
static int ogg_reset_cur_page(OGGStreamContext *oggstream)
Definition: oggenc.c:173
static int64_t ogg_granule_to_timestamp(OGGStreamContext *oggstream, int64_t granule)
Definition: oggenc.c:148
int size
int flags
A combination of AV_PKT_FLAG values.
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:991
static int ogg_write_trailer(AVFormatContext *s)
Definition: oggenc.c:596
#define LIBAVFORMAT_IDENT
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:457
struct OGGPageList OGGPageList
int void avio_flush(AVIOContext *s)
Force flushing of buffered data to the output s.
Definition: aviobuf.c:193
#define FFMIN(a, b)
Definition: common.h:58
uint64_t granule
Definition: oggdec.h:70
ret
Definition: avfilter.c:821
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:443
const char * name
Definition: avformat.h:378
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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 format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
static int ogg_compare_granule(AVFormatContext *s, OGGPage *next, OGGPage *page)
Definition: oggenc.c:157
#define FLAC_STREAMINFO_SIZE
Definition: flac.h:33
uint8_t * header[3]
Definition: oggenc.c:50
#define SPEEX_HEADER_SIZE
Definition: oggenc.c:344
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
static void flush(AVCodecContext *avctx)
Stream structure.
Definition: avformat.h:643
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:281
enum AVMediaType codec_type
enum AVCodecID codec_id
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:202
int sample_rate
samples per second
AVIOContext * pb
I/O context.
Definition: avformat.h:977
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:151
main external API structure.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
static int ogg_buffer_page(AVFormatContext *s, OGGStreamContext *oggstream)
Definition: oggenc.c:182
int stream_index
Definition: oggenc.c:40
static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: oggenc.c:558
Describe the class of an AVClass context structure.
Definition: log.h:50
AVOutputFormat ff_ogg_muxer
Definition: oggenc.c:624
synthesis window for stochastic i
rational number numerator/denominator
Definition: rational.h:43
unsigned long ffio_get_checksum(AVIOContext *s)
Definition: aviobuf.c:449
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:59
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
#define PARAM
Definition: oggenc.c:76
OGGPageList * page_list
Definition: oggenc.c:70
static int ogg_build_opus_headers(AVCodecContext *avctx, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
Definition: oggenc.c:375
uint8_t * buf
Definition: oggdec.h:62
Main libavformat public API header.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:162
#define OFFSET(x)
Definition: oggenc.c:75
static int ogg_key_granule(OGGStreamContext *oggstream, int64_t granule)
Definition: oggenc.c:143
int kfgshift
for theora granule
Definition: oggenc.c:53
int den
denominator
Definition: rational.h:45
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:337
Definition: oggdec.h:98
int len
void * priv_data
Format private data.
Definition: avformat.h:964
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:470
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:299
void INT64 INT64 count
Definition: avisynth_c.h:594
uint8_t segments[255]
Definition: oggenc.c:43
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
Definition: random_seed.c:105
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:679
int64_t pref_duration
preferred page duration (0 => fill all segments)
Definition: oggenc.c:72
static void ogg_write_pages(AVFormatContext *s, int flush)
Definition: oggenc.c:536
This structure stores compressed data.
int delay
Codec delay.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:190