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