PR #25658 opened by romainhedouin
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25658
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25658.patch

Only the decoder uses `x_coeff`. The encoder allocated and cleared it for
nothing, about 12 MB at 1080p.

The output is byte identical: encoder and decoder outputs match on 198
cases (11 inputs x 18 option sets, with both compilers). The FATE snow
tests pass with gcc and clang, and the mcdeint tests with clang.

Encoding 13 frames of 1080p video on an Apple M4 (median of 61 runs):

| | RAM before | RAM after | CPU before | CPU after |
|---|---|---|---|---|
| gcc 16.2 | 80.8 MB | 68.7 MB | 445 ms | 441 ms |
| clang 21 | 81.0 MB | 68.8 MB | 409 ms | 407 ms |

The decoder is unchanged.

Noticed during a review sweep of ffmpeg using an LLM.

Signed-off-by: romainhedouin <[email protected]>

<!--
If this PR requires new FATE test samples, attach them to the PR and
list their target paths below (relative to the fate-suite root).

Attached filenames must match the sample's filename:

```fate-samples
# e.g. vorbis/new-sample.ogg
```
-->



>From 97a39fe846866de02a76985e19cc906e51ffa966 Mon Sep 17 00:00:00 2001
From: romainhedouin <[email protected]>
Date: Sun, 1 Nov 2026 15:57:27 +0100
Subject: [PATCH] avcodec/snow: don't allocate x_coeff in the encoder

Only the decoder uses x_coeff. The encoder allocated and cleared it
for nothing, which is about 12 MB at 1080p.

Noticed during a review sweep of ffmpeg using an LLM.

Signed-off-by: romainhedouin <[email protected]>
---
 libavcodec/snow.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/snow.c b/libavcodec/snow.c
index ecacf0a751b..a2f464e8f71 100644
--- a/libavcodec/snow.c
+++ b/libavcodec/snow.c
@@ -587,6 +587,8 @@ int ff_snow_common_init_after_header(AVCodecContext *avctx) 
{
                     b->parent= 
&s->plane[plane_index].band[level-1][orientation];
                 //FIXME avoid this realloc
                 av_freep(&b->x_coeff);
+                if (!av_codec_is_decoder(avctx->codec)) // only snowdec uses 
x_coeff
+                    continue;
                 b->x_coeff = av_calloc((b->width + 1) * b->height + 1,
                                        sizeof(*b->x_coeff));
                 if (!b->x_coeff)
-- 
2.54.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to