[FFmpeg-devel] [PATCH] oggpagesize option added

Baptiste Coudurier baptiste.coudurier
Fri Jan 28 00:34:46 CET 2011


On 01/27/2011 01:31 AM, Andres Gonzalez wrote:
>
> On 26/01/11 21:54, Baptiste Coudurier wrote:
>>
>> You still have to buffer the page at segments_count == 255.
>>
>
> Ok! Here it is.
>
>
> 0001-Added-oggpagesize-option-for-Ogg-encoding.-Allows-se.patch
>
>
>  From fe16ae48a9a2bbb07b3c841d01daf4e506e2e207 Mon Sep 17 00:00:00 2001
> From: Andres Gonzalez<acandido at hi-iberia.es>
> Date: Thu, 27 Jan 2011 10:14:21 +0100
> Subject: [PATCH] Added oggpagesize option for Ogg encoding. Allows setting a preferred page size. When set, if an Ogg stream buffer has enough data, a page is made, instead of filling maximum-size pages.
>
> ---
>   libavformat/oggenc.c |   25 +++++++++++++++++++++++--
>   1 files changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c
> index b72efc8..cf4ff91 100644
> --- a/libavformat/oggenc.c
> +++ b/libavformat/oggenc.c
> @@ -20,6 +20,7 @@
>    */
>
>   #include "libavutil/crc.h"
> +#include "libavutil/opt.h"
>   #include "libavutil/random_seed.h"
>   #include "libavcodec/xiph.h"
>   #include "libavcodec/bytestream.h"
> @@ -61,9 +62,26 @@ typedef struct OGGPageList {
>   } OGGPageList;
>
>   typedef struct {
> +    const AVClass *class;
>       OGGPageList *page_list;
> +    int pref_size; ///<  preferred page size (0 =>  fill all segments)
>   } OGGContext;
>
> +
> +static const AVOption options[] = {
> +    { "oggpagesize", "Set preferred Ogg page size.",
> +      offsetof(OGGContext, pref_size), FF_OPT_TYPE_INT, 0, 0, MAX_PAGE_SIZE, AV_OPT_FLAG_ENCODING_PARAM},
> +    { NULL },
> +};
> +
> +static const AVClass ogg_muxer_class = {
> +    "Ogg muxer",
> +    av_default_item_name,
> +    options,
> +    LIBAVUTIL_VERSION_INT,
> +};
> +
> +
>   static void ogg_update_checksum(AVFormatContext *s, ByteIOContext *pb, int64_t crc_offset)
>   {
>       int64_t pos = url_ftell(pb);
> @@ -173,6 +191,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;
> @@ -208,8 +227,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);
>           }

Here it is, and btw you can tweak this condition to buffer the page on a 
delay basis instead of page size.

-- 
Baptiste COUDURIER
Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
FFmpeg maintainer                                  http://www.ffmpeg.org



More information about the ffmpeg-devel mailing list