[FFmpeg-devel] [PATCH v2 1/2] avcodec/flashsvenc: add compression_level option

Ramiro Polla ramiro.polla at gmail.com
Mon Sep 30 02:21:30 EEST 2024


On Mon, Sep 30, 2024 at 12:01 AM James Almer <jamrial at gmail.com> wrote:
> On 9/29/2024 3:36 PM, Ramiro Polla wrote:
> > This allows setting the compression level used by zlib.
> > ---
> >   libavcodec/flashsvenc.c              | 10 ++++++++--
> >   tests/ref/vsynth/vsynth1-flashsv     |  2 +-
> >   tests/ref/vsynth/vsynth2-flashsv     |  4 ++--
> >   tests/ref/vsynth/vsynth3-flashsv     |  2 +-
> >   tests/ref/vsynth/vsynth_lena-flashsv |  2 +-
> >   5 files changed, 13 insertions(+), 7 deletions(-)
> >
> > diff --git a/libavcodec/flashsvenc.c b/libavcodec/flashsvenc.c
> > index 5cf0602f5d..f650e517d0 100644
> > --- a/libavcodec/flashsvenc.c
> > +++ b/libavcodec/flashsvenc.c
> > @@ -67,6 +67,7 @@ typedef struct FlashSVContext {
> >       unsigned        packet_size;
> >       int64_t         last_key_frame;
> >       uint8_t         tmpblock[3 * 256 * 256];
> > +    int             compression_level;
> >   } FlashSVContext;
> >
> >   static int copy_region_enc(const uint8_t *sptr, uint8_t *dptr, int dx, int dy,
> > @@ -121,6 +122,10 @@ static av_cold int flashsv_encode_init(AVCodecContext *avctx)
> >       nb_blocks = h_blocks * v_blocks;
> >       s->packet_size = 4 + nb_blocks * (2 + 3 * BLOCK_WIDTH * BLOCK_HEIGHT);
> >
> > +    s->compression_level = avctx->compression_level == FF_COMPRESSION_DEFAULT
> > +                         ? Z_DEFAULT_COMPRESSION
> > +                         : av_clip(avctx->compression_level, 0, 9);
> > +
> >       return 0;
> >   }
> >
> > @@ -170,9 +175,10 @@ static int encode_bitstream(FlashSVContext *s, const AVFrame *p, uint8_t *buf,
> >                                     p->linesize[0], previous_frame);
> >
> >               if (res || *I_frame) {
> > -                unsigned long zsize = 3 * block_width * block_height;
> > +                unsigned long zsize = 3 * block_width * block_height + 12;
>
> Why the 12?

This is to account for the deflate overhead. I found this information here:
https://refspecs.linuxbase.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/zlib-compress2-1.html
"The application should ensure that this value be at least (sourceLen
* 1.001) + 12."

I've updated the commit message with this information.

> Also, while at it, you could change that 3 to 3UL, since block_* are ints.

Updated patch attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v3-0001-avcodec-flashsvenc-add-compression_level-option.patch
Type: text/x-patch
Size: 4776 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20240930/437ad71e/attachment.bin>


More information about the ffmpeg-devel mailing list