[FFmpeg-devel] [PATCH] allow setting png compression level

Michael Niedermayer michaelni
Tue Oct 9 15:33:09 CEST 2007


Hi

On Sun, Oct 07, 2007 at 11:30:07AM +0200, Reimar D?ffinger wrote:
> Hello,
> On Sun, Oct 07, 2007 at 10:17:18AM +0100, M?ns Rullg?rd wrote:
> > > Index: libavcodec/pngenc.c
> > > ===================================================================
> > > --- libavcodec/pngenc.c	(revision 10668)
> > > +++ libavcodec/pngenc.c	(working copy)
> > > @@ -187,7 +187,7 @@
> > >      s->zstream.zalloc = ff_png_zalloc;
> > >      s->zstream.zfree = ff_png_zfree;
> > >      s->zstream.opaque = NULL;
> > > -    ret = deflateInit2(&s->zstream, Z_DEFAULT_COMPRESSION,
> > > +    ret = deflateInit2(&s->zstream, avctx->compression_level,
> > >                         Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
> > >      if (ret != Z_OK)
> > >          return -1;
> > 
> > This will work, but only because FF_COMPRESSION_DEFAULT happens to be
> > equal to Z_DEFAULT_STRATEGY.  I'd prefer explicitly setting this in
> > the init function.  Some range checking probably wouldn't hurt either.
> 
> You mean like attached?
> Not doing range checking actually was intentional because I thought
> deflateInit2 was supposed to handle any number.
> Attached patch instead clips avctx->compression_level, does that seem
> like a sane way to do it to you?
> 
> Greetings,
> Reimar D?ffinger

> Index: libavcodec/pngenc.c
> ===================================================================
> --- libavcodec/pngenc.c	(revision 10668)
> +++ libavcodec/pngenc.c	(working copy)
> @@ -187,7 +187,8 @@
>      s->zstream.zalloc = ff_png_zalloc;
>      s->zstream.zfree = ff_png_zfree;
>      s->zstream.opaque = NULL;
> -    ret = deflateInit2(&s->zstream, Z_DEFAULT_COMPRESSION,
> +    avctx->compression_level = av_clip(avctx->compression_level, 0, 9);
> +    ret = deflateInit2(&s->zstream, avctx->compression_level,
>                         Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
>      if (ret != Z_OK)
>          return -1;
> @@ -314,6 +315,7 @@
>  
>      avcodec_get_frame_defaults((AVFrame*)&s->picture);
>      avctx->coded_frame= (AVFrame*)&s->picture;
> +    avctx->compression_level= Z_DEFAULT_COMPRESSION;
>  
>      return 0;
>  }

    /**
     * - encoding: Set by user.
                   ^^^^^^^^^^^^
     * - decoding: unused
     */
    int compression_level;
#define FF_COMPRESSION_DEFAULT -1

an encoder has no business setting compression_level to some custom
default

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

When you are offended at any man's fault, turn to yourself and study your
own failings. Then you will forget your anger. -- Epictetus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20071009/99dccd25/attachment.pgp>



More information about the ffmpeg-devel mailing list