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

Reimar Döffinger Reimar.Doeffinger
Sun Oct 7 11:30:07 CEST 2007


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
-------------- next part --------------
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;
 }



More information about the ffmpeg-devel mailing list