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 "libavutil/crc.h"
23 #include "libavutil/mathematics.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/random_seed.h"
26 #include "libavcodec/xiph.h"
27 #include "libavcodec/bytestream.h"
28 #include "libavcodec/flac.h"
29 #include "avformat.h"
30 #include "avio_internal.h"
31 #include "internal.h"
32 #include "vorbiscomment.h"
33 
34 #define MAX_PAGE_SIZE 65025
35 
36 typedef struct {
37  int64_t granule;
43  uint16_t size;
44 } OGGPage;
45 
46 typedef struct {
47  unsigned page_counter;
48  uint8_t *header[3];
49  int header_len[3];
51  int kfgshift;
52  int64_t last_kf_pts;
53  int vrev;
54  int eos;
55  unsigned page_count;
57  unsigned serial_num;
58  int64_t last_granule;
60 
61 typedef struct OGGPageList {
63  struct OGGPageList *next;
64 } OGGPageList;
65 
66 typedef struct {
67  const AVClass *class;
69  int pref_size;
70 } OGGContext;
71 
72 #define OFFSET(x) offsetof(OGGContext, x)
73 #define PARAM AV_OPT_FLAG_ENCODING_PARAM
74 
75 static const AVOption options[] = {
76  { "pagesize", "preferred page size in bytes",
77  OFFSET(pref_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MAX_PAGE_SIZE, PARAM },
78  { NULL },
79 };
80 
81 static const AVClass ogg_muxer_class = {
82  .class_name = "Ogg muxer",
83  .item_name = av_default_item_name,
84  .option = options,
85  .version = LIBAVUTIL_VERSION_INT,
86 };
87 
88 
89 static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset)
90 {
91  int64_t pos = avio_tell(pb);
92  uint32_t checksum = ffio_get_checksum(pb);
93  avio_seek(pb, crc_offset, SEEK_SET);
94  avio_wb32(pb, checksum);
95  avio_seek(pb, pos, SEEK_SET);
96 }
97 
98 static int ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
99 {
100  OGGStreamContext *oggstream = s->streams[page->stream_index]->priv_data;
101  AVIOContext *pb;
102  int64_t crc_offset;
103  int ret, size;
104  uint8_t *buf;
105 
106  ret = avio_open_dyn_buf(&pb);
107  if (ret < 0)
108  return ret;
110  ffio_wfourcc(pb, "OggS");
111  avio_w8(pb, 0);
112  avio_w8(pb, page->flags | extra_flags);
113  avio_wl64(pb, page->granule);
114  avio_wl32(pb, oggstream->serial_num);
115  avio_wl32(pb, oggstream->page_counter++);
116  crc_offset = avio_tell(pb);
117  avio_wl32(pb, 0); // crc
118  avio_w8(pb, page->segments_count);
119  avio_write(pb, page->segments, page->segments_count);
120  avio_write(pb, page->data, page->size);
121 
122  ogg_update_checksum(s, pb, crc_offset);
123  avio_flush(pb);
124 
125  size = avio_close_dyn_buf(pb, &buf);
126  if (size < 0)
127  return size;
128 
129  avio_write(s->pb, buf, size);
130  avio_flush(s->pb);
131  av_free(buf);
132  oggstream->page_count--;
133  return 0;
134 }
135 
136 static int64_t ogg_granule_to_timestamp(OGGStreamContext *oggstream, int64_t granule)
137 {
138  if (oggstream->kfgshift)
139  return (granule>>oggstream->kfgshift) +
140  (granule & ((1<<oggstream->kfgshift)-1));
141  else
142  return granule;
143 }
144 
146 {
147  AVStream *st2 = s->streams[next->stream_index];
148  AVStream *st = s->streams[page->stream_index];
149  int64_t next_granule, cur_granule;
150 
151  if (next->granule == -1 || page->granule == -1)
152  return 0;
153 
154  next_granule = av_rescale_q(ogg_granule_to_timestamp(st2->priv_data, next->granule),
155  st2->time_base, AV_TIME_BASE_Q);
156  cur_granule = av_rescale_q(ogg_granule_to_timestamp(st->priv_data, page->granule),
157  st ->time_base, AV_TIME_BASE_Q);
158  return next_granule > cur_granule;
159 }
160 
161 static int ogg_reset_cur_page(OGGStreamContext *oggstream)
162 {
163  oggstream->page.granule = -1;
164  oggstream->page.flags = 0;
165  oggstream->page.segments_count = 0;
166  oggstream->page.size = 0;
167  return 0;
168 }
169 
171 {
172  OGGContext *ogg = s->priv_data;
173  OGGPageList **p = &ogg->page_list;
174  OGGPageList *l = av_mallocz(sizeof(*l));
175 
176  if (!l)
177  return AVERROR(ENOMEM);
178  l->page = oggstream->page;
179 
180  oggstream->page_count++;
181  ogg_reset_cur_page(oggstream);
182 
183  while (*p) {
184  if (ogg_compare_granule(s, &(*p)->page, &l->page))
185  break;
186  p = &(*p)->next;
187  }
188  l->next = *p;
189  *p = l;
190 
191  return 0;
192 }
193 
195  uint8_t *data, unsigned size, int64_t granule,
196  int header)
197 {
198  OGGStreamContext *oggstream = st->priv_data;
199  OGGContext *ogg = s->priv_data;
200  int total_segments = size / 255 + 1;
201  uint8_t *p = data;
202  int i, segments, len, flush = 0;
203 
204  // Handles VFR by flushing page because this frame needs to have a timestamp
205  if (st->codec->codec_id == AV_CODEC_ID_THEORA && !header &&
206  ogg_granule_to_timestamp(oggstream, granule) >
207  ogg_granule_to_timestamp(oggstream, oggstream->last_granule) + 1) {
208  if (oggstream->page.granule != -1)
209  ogg_buffer_page(s, oggstream);
210  flush = 1;
211  }
212 
213  for (i = 0; i < total_segments; ) {
214  OGGPage *page = &oggstream->page;
215 
216  segments = FFMIN(total_segments - i, 255 - page->segments_count);
217 
218  if (i && !page->segments_count)
219  page->flags |= 1; // continued packet
220 
221  memset(page->segments+page->segments_count, 255, segments - 1);
222  page->segments_count += segments - 1;
223 
224  len = FFMIN(size, segments*255);
225  page->segments[page->segments_count++] = len - (segments-1)*255;
226  memcpy(page->data+page->size, p, len);
227  p += len;
228  size -= len;
229  i += segments;
230  page->size += len;
231 
232  if (i == total_segments)
233  page->granule = granule;
234 
235  if (!header && (page->segments_count == 255 ||
236  (ogg->pref_size > 0 && page->size >= ogg->pref_size))) {
237  ogg_buffer_page(s, oggstream);
238  }
239  }
240 
241  if (flush && oggstream->page.granule != -1)
242  ogg_buffer_page(s, oggstream);
243 
244  return 0;
245 }
246 
247 static uint8_t *ogg_write_vorbiscomment(int offset, int bitexact,
248  int *header_len, AVDictionary **m, int framing_bit)
249 {
250  const char *vendor = bitexact ? "Libav" : LIBAVFORMAT_IDENT;
251  int size;
252  uint8_t *p, *p0;
253  unsigned int count;
254 
256 
257  size = offset + ff_vorbiscomment_length(*m, vendor, &count) + framing_bit;
258  p = av_mallocz(size);
259  if (!p)
260  return NULL;
261  p0 = p;
262 
263  p += offset;
264  ff_vorbiscomment_write(&p, m, vendor, count);
265  if (framing_bit)
266  bytestream_put_byte(&p, 1);
267 
268  *header_len = size;
269  return p0;
270 }
271 
273  OGGStreamContext *oggstream, int bitexact,
274  AVDictionary **m)
275 {
276  enum FLACExtradataFormat format;
277  uint8_t *streaminfo;
278  uint8_t *p;
279 
280  if (!avpriv_flac_is_extradata_valid(avctx, &format, &streaminfo))
281  return -1;
282 
283  // first packet: STREAMINFO
284  oggstream->header_len[0] = 51;
285  oggstream->header[0] = av_mallocz(51); // per ogg flac specs
286  p = oggstream->header[0];
287  if (!p)
288  return AVERROR(ENOMEM);
289  bytestream_put_byte(&p, 0x7F);
290  bytestream_put_buffer(&p, "FLAC", 4);
291  bytestream_put_byte(&p, 1); // major version
292  bytestream_put_byte(&p, 0); // minor version
293  bytestream_put_be16(&p, 1); // headers packets without this one
294  bytestream_put_buffer(&p, "fLaC", 4);
295  bytestream_put_byte(&p, 0x00); // streaminfo
296  bytestream_put_be24(&p, 34);
298 
299  // second packet: VorbisComment
300  p = ogg_write_vorbiscomment(4, bitexact, &oggstream->header_len[1], m, 0);
301  if (!p)
302  return AVERROR(ENOMEM);
303  oggstream->header[1] = p;
304  bytestream_put_byte(&p, 0x84); // last metadata block and vorbis comment
305  bytestream_put_be24(&p, oggstream->header_len[1] - 4);
306 
307  return 0;
308 }
309 
310 #define SPEEX_HEADER_SIZE 80
311 
313  OGGStreamContext *oggstream, int bitexact,
314  AVDictionary **m)
315 {
316  uint8_t *p;
317 
318  if (avctx->extradata_size < SPEEX_HEADER_SIZE)
319  return -1;
320 
321  // first packet: Speex header
323  if (!p)
324  return AVERROR(ENOMEM);
325  oggstream->header[0] = p;
326  oggstream->header_len[0] = SPEEX_HEADER_SIZE;
328  AV_WL32(&oggstream->header[0][68], 0); // set extra_headers to 0
329 
330  // second packet: VorbisComment
331  p = ogg_write_vorbiscomment(0, bitexact, &oggstream->header_len[1], m, 0);
332  if (!p)
333  return AVERROR(ENOMEM);
334  oggstream->header[1] = p;
335 
336  return 0;
337 }
338 
339 #define OPUS_HEADER_SIZE 19
340 
342  OGGStreamContext *oggstream, int bitexact,
343  AVDictionary **m)
344 {
345  uint8_t *p;
346 
347  if (avctx->extradata_size < OPUS_HEADER_SIZE)
348  return -1;
349 
350  /* first packet: Opus header */
351  p = av_mallocz(avctx->extradata_size);
352  if (!p)
353  return AVERROR(ENOMEM);
354  oggstream->header[0] = p;
355  oggstream->header_len[0] = avctx->extradata_size;
356  bytestream_put_buffer(&p, avctx->extradata, avctx->extradata_size);
357 
358  /* second packet: VorbisComment */
359  p = ogg_write_vorbiscomment(8, bitexact, &oggstream->header_len[1], m, 0);
360  if (!p)
361  return AVERROR(ENOMEM);
362  oggstream->header[1] = p;
363  bytestream_put_buffer(&p, "OpusTags", 8);
364 
365  return 0;
366 }
367 
369 {
370  OGGStreamContext *oggstream;
371  int i, j;
372 
373  for (i = 0; i < s->nb_streams; i++) {
374  AVStream *st = s->streams[i];
375  unsigned serial_num = i;
376 
377  if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
378  if (st->codec->codec_id == AV_CODEC_ID_OPUS)
379  /* Opus requires a fixed 48kHz clock */
380  avpriv_set_pts_info(st, 64, 1, 48000);
381  else
382  avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
383  else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
385  if (st->codec->codec_id != AV_CODEC_ID_VORBIS &&
387  st->codec->codec_id != AV_CODEC_ID_SPEEX &&
388  st->codec->codec_id != AV_CODEC_ID_FLAC &&
389  st->codec->codec_id != AV_CODEC_ID_OPUS) {
390  av_log(s, AV_LOG_ERROR, "Unsupported codec id in stream %d\n", i);
391  return -1;
392  }
393 
394  if (!st->codec->extradata || !st->codec->extradata_size) {
395  av_log(s, AV_LOG_ERROR, "No extradata present\n");
396  return -1;
397  }
398  oggstream = av_mallocz(sizeof(*oggstream));
399  oggstream->page.stream_index = i;
400 
401  if (!(st->codec->flags & CODEC_FLAG_BITEXACT))
402  do {
403  serial_num = av_get_random_seed();
404  for (j = 0; j < i; j++) {
405  OGGStreamContext *sc = s->streams[j]->priv_data;
406  if (serial_num == sc->serial_num)
407  break;
408  }
409  } while (j < i);
410  oggstream->serial_num = serial_num;
411 
412  st->priv_data = oggstream;
413  if (st->codec->codec_id == AV_CODEC_ID_FLAC) {
414  int err = ogg_build_flac_headers(st->codec, oggstream,
416  &s->metadata);
417  if (err) {
418  av_log(s, AV_LOG_ERROR, "Error writing FLAC headers\n");
419  av_freep(&st->priv_data);
420  return err;
421  }
422  } else if (st->codec->codec_id == AV_CODEC_ID_SPEEX) {
423  int err = ogg_build_speex_headers(st->codec, oggstream,
425  &s->metadata);
426  if (err) {
427  av_log(s, AV_LOG_ERROR, "Error writing Speex headers\n");
428  av_freep(&st->priv_data);
429  return err;
430  }
431  } else if (st->codec->codec_id == AV_CODEC_ID_OPUS) {
432  int err = ogg_build_opus_headers(st->codec, oggstream,
434  &s->metadata);
435  if (err) {
436  av_log(s, AV_LOG_ERROR, "Error writing Opus headers\n");
437  av_freep(&st->priv_data);
438  return err;
439  }
440  } else {
441  uint8_t *p;
442  const char *cstr = st->codec->codec_id == AV_CODEC_ID_VORBIS ? "vorbis" : "theora";
443  int header_type = st->codec->codec_id == AV_CODEC_ID_VORBIS ? 3 : 0x81;
444  int framing_bit = st->codec->codec_id == AV_CODEC_ID_VORBIS ? 1 : 0;
445 
447  st->codec->codec_id == AV_CODEC_ID_VORBIS ? 30 : 42,
448  oggstream->header, oggstream->header_len) < 0) {
449  av_log(s, AV_LOG_ERROR, "Extradata corrupted\n");
450  av_freep(&st->priv_data);
451  return -1;
452  }
453 
455  &oggstream->header_len[1], &s->metadata,
456  framing_bit);
457  oggstream->header[1] = p;
458  if (!p)
459  return AVERROR(ENOMEM);
460 
461  bytestream_put_byte(&p, header_type);
462  bytestream_put_buffer(&p, cstr, 6);
463 
464  if (st->codec->codec_id == AV_CODEC_ID_THEORA) {
467  oggstream->kfgshift = ((oggstream->header[0][40]&3)<<3)|(oggstream->header[0][41]>>5);
468  oggstream->vrev = oggstream->header[0][9];
469  av_log(s, AV_LOG_DEBUG, "theora kfgshift %d, vrev %d\n",
470  oggstream->kfgshift, oggstream->vrev);
471  }
472  }
473  }
474 
475  for (j = 0; j < s->nb_streams; j++) {
476  OGGStreamContext *oggstream = s->streams[j]->priv_data;
477  ogg_buffer_data(s, s->streams[j], oggstream->header[0],
478  oggstream->header_len[0], 0, 1);
479  oggstream->page.flags |= 2; // bos
480  ogg_buffer_page(s, oggstream);
481  }
482  for (j = 0; j < s->nb_streams; j++) {
483  AVStream *st = s->streams[j];
484  OGGStreamContext *oggstream = st->priv_data;
485  for (i = 1; i < 3; i++) {
486  if (oggstream && oggstream->header_len[i])
487  ogg_buffer_data(s, st, oggstream->header[i],
488  oggstream->header_len[i], 0, 1);
489  }
490  ogg_buffer_page(s, oggstream);
491  }
492  return 0;
493 }
494 
496 {
497  OGGContext *ogg = s->priv_data;
498  OGGPageList *next, *p;
499 
500  if (!ogg->page_list)
501  return;
502 
503  for (p = ogg->page_list; p; ) {
504  OGGStreamContext *oggstream =
506  if (oggstream->page_count < 2 && !flush)
507  break;
508  ogg_write_page(s, &p->page,
509  flush && oggstream->page_count == 1 ? 4 : 0); // eos
510  next = p->next;
511  av_freep(&p);
512  p = next;
513  }
514  ogg->page_list = p;
515 }
516 
518 {
519  AVStream *st = s->streams[pkt->stream_index];
520  OGGStreamContext *oggstream = st->priv_data;
521  int ret;
522  int64_t granule;
523 
524  if (st->codec->codec_id == AV_CODEC_ID_THEORA) {
525  int64_t pts = oggstream->vrev < 1 ? pkt->pts : pkt->pts + pkt->duration;
526  int pframe_count;
527  if (pkt->flags & AV_PKT_FLAG_KEY)
528  oggstream->last_kf_pts = pts;
529  pframe_count = pts - oggstream->last_kf_pts;
530  // prevent frame count from overflow if key frame flag is not set
531  if (pframe_count >= (1<<oggstream->kfgshift)) {
532  oggstream->last_kf_pts += pframe_count;
533  pframe_count = 0;
534  }
535  granule = (oggstream->last_kf_pts<<oggstream->kfgshift) | pframe_count;
536  } else if (st->codec->codec_id == AV_CODEC_ID_OPUS)
537  granule = pkt->pts + pkt->duration + av_rescale_q(st->codec->delay, (AVRational){ 1, st->codec->sample_rate }, st->time_base);
538  else
539  granule = pkt->pts + pkt->duration;
540 
541  ret = ogg_buffer_data(s, st, pkt->data, pkt->size, granule, 0);
542  if (ret < 0)
543  return ret;
544 
545  ogg_write_pages(s, 0);
546 
547  oggstream->last_granule = granule;
548 
549  return 0;
550 }
551 
553 {
554  int i;
555 
556  /* flush current page */
557  for (i = 0; i < s->nb_streams; i++)
558  ogg_buffer_page(s, s->streams[i]->priv_data);
559 
560  ogg_write_pages(s, 1);
561 
562  for (i = 0; i < s->nb_streams; i++) {
563  AVStream *st = s->streams[i];
564  OGGStreamContext *oggstream = st->priv_data;
565  if (st->codec->codec_id == AV_CODEC_ID_FLAC ||
566  st->codec->codec_id == AV_CODEC_ID_SPEEX ||
567  st->codec->codec_id == AV_CODEC_ID_OPUS) {
568  av_free(oggstream->header[0]);
569  }
570  av_freep(&oggstream->header[1]);
571  av_freep(&st->priv_data);
572  }
573  return 0;
574 }
575 
577  .name = "ogg",
578  .long_name = NULL_IF_CONFIG_SMALL("Ogg"),
579  .mime_type = "application/ogg",
580  .extensions = "ogg,ogv,spx,opus",
581  .priv_data_size = sizeof(OGGContext),
582  .audio_codec = AV_CODEC_ID_FLAC,
583  .video_codec = AV_CODEC_ID_THEORA,
587  .priv_class = &ogg_muxer_class,
588 };
int header_len[3]
Definition: oggenc.c:49
static int ogg_write_header(AVFormatContext *s)
Definition: oggenc.c:368
int64_t granule
Definition: oggenc.c:37
int64_t last_granule
last packet granule
Definition: oggenc.c:58
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 size
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:945
AVOption.
Definition: opt.h:233
static int ogg_build_speex_headers(AVCodecContext *avctx, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
Definition: oggenc.c:312
unsigned page_count
number of page buffered
Definition: oggenc.c:55
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:3283
static int write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: assenc.c:58
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:186
uint8_t data[MAX_PAGE_SIZE]
Definition: oggenc.c:42
int avpriv_flac_is_extradata_valid(AVCodecContext *avctx, enum FLACExtradataFormat *format, uint8_t **streaminfo_start)
Validate the FLAC extradata.
Definition: flac.c:167
OGGPage page
Definition: oggenc.c:62
void * priv_data
Definition: avformat.h:653
OGGPage page
current page
Definition: oggenc.c:56
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:933
#define OPUS_HEADER_SIZE
Definition: oggenc.c:339
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1465
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:151
static int ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags)
Definition: oggenc.c:98
Format I/O context.
Definition: avformat.h:828
static int ogg_build_flac_headers(AVCodecContext *avctx, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
Definition: oggenc.c:272
static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset)
Definition: oggenc.c:89
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:38
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:260
uint8_t
AVOptions.
uint16_t size
Definition: oggenc.c:43
#define AV_WL32(p, d)
Definition: intreadwrite.h:255
#define MAX_PAGE_SIZE
Definition: oggenc.c:34
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1454
uint8_t segments_count
Definition: oggenc.c:40
AVStream ** streams
Definition: avformat.h:876
int64_t last_kf_pts
Definition: oggenc.c:52
const char data[16]
Definition: mxf.c:66
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:219
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:165
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
Definition: avio_internal.h:50
Definition: oggenc.c:36
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:937
static const AVOption options[]
Definition: oggenc.c:75
static const AVClass ogg_muxer_class
Definition: oggenc.c:81
static int write_trailer(AVFormatContext *s)
Definition: assenc.c:67
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:324
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:122
FLACExtradataFormat
Definition: flac.h:57
unsigned page_counter
Definition: oggenc.c:47
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:26
const AVMetadataConv ff_vorbiscomment_metadata_conv[]
VorbisComment metadata conversion mapping.
Definition: vorbiscomment.c:33
AVDictionary * metadata
Definition: avformat.h:972
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:139
static int ogg_buffer_data(AVFormatContext *s, AVStream *st, uint8_t *data, unsigned size, int64_t granule, int header)
Definition: oggenc.c:194
FLAC (Free Lossless Audio Codec) decoder/demuxer common functions.
struct OGGPageList * next
Definition: oggenc.c:63
int pref_size
preferred page size (0 => fill all segments)
Definition: oggenc.c:69
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1434
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:146
uint8_t flags
Definition: oggenc.c:39
uint8_t segments[255]
Definition: oggdec.h:80
static int ogg_reset_cur_page(OGGStreamContext *oggstream)
Definition: oggenc.c:161
static int64_t ogg_granule_to_timestamp(OGGStreamContext *oggstream, int64_t granule)
Definition: oggenc.c:136
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:921
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:641
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:875
static int ogg_write_trailer(AVFormatContext *s)
Definition: oggenc.c:552
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:425
struct OGGPageList OGGPageList
int void avio_flush(AVIOContext *s)
Definition: aviobuf.c:180
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:411
const char * name
Definition: avformat.h:376
static int ogg_compare_granule(AVFormatContext *s, OGGPage *next, OGGPage *page)
Definition: oggenc.c:145
#define FLAC_STREAMINFO_SIZE
Definition: flac.h:33
uint8_t * header[3]
Definition: oggenc.c:48
#define SPEEX_HEADER_SIZE
Definition: oggenc.c:310
LIBAVUTIL_VERSION_INT
Definition: eval.c:52
Stream structure.
Definition: avformat.h:622
NULL
Definition: eval.c:52
static uint8_t * ogg_write_vorbiscomment(int offset, int bitexact, int *header_len, AVDictionary **m, int framing_bit)
Definition: oggenc.c:247
enum AVMediaType codec_type
Definition: avcodec.h:1347
enum AVCodecID codec_id
Definition: avcodec.h:1350
int sample_rate
samples per second
Definition: avcodec.h:2104
AVIOContext * pb
I/O context.
Definition: avformat.h:861
av_default_item_name
Definition: dnxhdenc.c:43
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:144
main external API structure.
Definition: avcodec.h:1339
static int ogg_buffer_page(AVFormatContext *s, OGGStreamContext *oggstream)
Definition: oggenc.c:170
int stream_index
Definition: oggenc.c:38
int extradata_size
Definition: avcodec.h:1455
static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: oggenc.c:517
Describe the class of an AVClass context structure.
Definition: log.h:33
AVOutputFormat ff_ogg_muxer
Definition: oggenc.c:576
rational number numerator/denominator
Definition: rational.h:43
unsigned long ffio_get_checksum(AVIOContext *s)
Definition: aviobuf.c:417
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:57
#define PARAM
Definition: oggenc.c:73
OGGPageList * page_list
Definition: oggenc.c:68
static int ogg_build_opus_headers(AVCodecContext *avctx, OGGStreamContext *oggstream, int bitexact, AVDictionary **m)
Definition: oggenc.c:341
Main libavformat public API header.
#define OFFSET(x)
Definition: oggenc.c:72
static av_cold void flush(AVCodecContext *avctx)
Flush (reset) the frame ID after seeking.
Definition: alsdec.c:1772
int kfgshift
for theora granule
Definition: oggenc.c:51
int den
denominator
Definition: rational.h:45
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:327
Definition: oggdec.h:96
int len
void * priv_data
Format private data.
Definition: avformat.h:848
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:380
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:268
uint8_t segments[255]
Definition: oggenc.c:41
uint32_t av_get_random_seed(void)
Get random data.
Definition: random_seed.c:85
int stream_index
Definition: avcodec.h:917
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:669
static void ogg_write_pages(AVFormatContext *s, int flush)
Definition: oggenc.c:495
This structure stores compressed data.
Definition: avcodec.h:898
int delay
Codec delay.
Definition: avcodec.h:1497
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:158
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:908