[FFmpeg-cvslog] oggenc: add pagesize option to set preferred page size

Andres Gonzalez git at videolan.org
Sun Apr 1 00:58:07 CEST 2012


ffmpeg | branch: master | Andres Gonzalez <acandido at hi-iberia.es> | Thu Jan 27 10:14:21 2011 +0100| [ed3e1b485acfba72ac9741407836c6125559d567] | committer: Justin Ruggles

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 at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ed3e1b485acfba72ac9741407836c6125559d567
---

 libavformat/oggenc.c |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c
index f947269..1c040a7 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,
 };



More information about the ffmpeg-cvslog mailing list