summaryrefslogtreecommitdiff
path: root/libavformat/oggenc.c
diff options
context:
space:
mode:
authorAndres Gonzalez <acandido@hi-iberia.es>2011-01-27 10:14:21 +0100
committerJustin Ruggles <justin.ruggles@gmail.com>2012-03-30 16:32:03 -0400
commited3e1b485acfba72ac9741407836c6125559d567 (patch)
treed8be69a00709c4892d6dab7e78bac72bf1e55e86 /libavformat/oggenc.c
parent67aec401d86c3b7c55ce6f97ea753dcb1ca04c95 (diff)
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 <justin.ruggles@gmail.com>
Diffstat (limited to 'libavformat/oggenc.c')
-rw-r--r--libavformat/oggenc.c27
1 files 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,
};