diff mbox series

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

Message ID 20240929180716.21778-1-ramiro.polla@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] avcodec/flashsvenc: add compression_level option | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 fail Make fate failed

Commit Message

Ramiro Polla Sept. 29, 2024, 6:07 p.m. UTC
This allows setting the compression level used by zlib.
---
 libavcodec/flashsvenc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
diff mbox series

Patch

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;
                 ret = compress2(ptr + 2, &zsize, s->tmpblock,
-                                3 * cur_blk_width * cur_blk_height, 9);
+                                3 * cur_blk_width * cur_blk_height,
+                                s->compression_level);
 
                 if (ret != Z_OK)
                     av_log(s->avctx, AV_LOG_ERROR,