From ed3e1b485acfba72ac9741407836c6125559d567 Mon Sep 17 00:00:00 2001 From: Andres Gonzalez Date: Thu, 27 Jan 2011 10:14:21 +0100 Subject: [PATCH] oggenc: add pagesize option to set preferred page size When set, if an Ogg stream buffer has enough data, a page is made instead of filling maximum-size pages. Using smaller pages results smaller seek intervals at the expense of higher container overhead. Signed-off-by: Justin Ruggles --- libavformat/oggenc.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c index f9472693f0..1c040a7d3e 100644 --- a/libavformat/oggenc.c +++ b/libavformat/oggenc.c @@ -21,6 +21,7 @@ #include "libavutil/crc.h" #include "libavutil/mathematics.h" +#include "libavutil/opt.h" #include "libavutil/random_seed.h" #include "libavcodec/xiph.h" #include "libavcodec/bytestream.h" @@ -63,9 +64,28 @@ typedef struct OGGPageList { } OGGPageList; typedef struct { + const AVClass *class; OGGPageList *page_list; + int pref_size; ///< preferred page size (0 => fill all segments) } OGGContext; +#define OFFSET(x) offsetof(OGGContext, x) +#define PARAM AV_OPT_FLAG_ENCODING_PARAM + +static const AVOption options[] = { + { "pagesize", "preferred page size in bytes", + OFFSET(pref_size), AV_OPT_TYPE_INT, { 0 }, 0, MAX_PAGE_SIZE, PARAM }, + { NULL }, +}; + +static const AVClass ogg_muxer_class = { + .class_name = "Ogg muxer", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + + static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset) { int64_t pos = avio_tell(pb); @@ -175,6 +195,7 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st, uint8_t *data, unsigned size, int64_t granule) { OGGStreamContext *oggstream = st->priv_data; + OGGContext *ogg = s->priv_data; int total_segments = size / 255 + 1; uint8_t *p = data; int i, segments, len, flush = 0; @@ -210,8 +231,9 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st, if (i == total_segments) page->granule = granule; - if (page->segments_count == 255) { - ogg_buffer_page(s, oggstream); + if (page->segments_count == 255 || + (ogg->pref_size > 0 && page->size >= ogg->pref_size)) { + ogg_buffer_page(s, oggstream); } } @@ -515,4 +537,5 @@ AVOutputFormat ff_ogg_muxer = { .write_header = ogg_write_header, .write_packet = ogg_write_packet, .write_trailer = ogg_write_trailer, + .priv_class = &ogg_muxer_class, };