Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: realies via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: realies <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PR] avfilter/af_loudnorm: fix limiter buffer over-allocation (PR #21452)
Date: Tue, 13 Jan 2026 17:51:55 -0000
Message-ID: <176832671620.25.15101392399745361618@4457048688e7> (raw)

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

The limiter_buf was being allocated with buf_size (3000ms worth of
samples) instead of limiter_buf_size (210ms worth of samples).

This resulted in allocating approximately 14x more memory than needed
for the limiter buffer.

## Memory profiling results (valgrind massif, 192kHz stereo)

| Version | Peak Heap Allocation |
|---------|---------------------|
| Before  | 87,415,378 bytes (~83.4 MB) |
| After   | 79,075,138 bytes (~75.4 MB) |
| **Saved** | **8,340,240 bytes (~8.0 MB)** |

## Details

At 192kHz stereo:
- buf_size: 1,152,000 samples = 9.2 MB
- limiter_buf_size: 80,640 samples = 0.6 MB
- Wasted per instance: ~8.6 MB

The bug was introduced when the limiter buffer was added but the
wrong size variable was used in av_malloc_array().


>From e413d357c0b8a250ccf4efb4b61fc4fd323db297 Mon Sep 17 00:00:00 2001
From: realies <ffmpeg@reali.es>
Date: Tue, 13 Jan 2026 19:34:00 +0200
Subject: [PATCH] avfilter/af_loudnorm: fix limiter buffer over-allocation

The limiter_buf was being allocated with buf_size (3000ms worth of
samples) instead of limiter_buf_size (210ms worth of samples).

This resulted in allocating approximately 14x more memory than needed
for the limiter buffer. At 192kHz stereo:
- buf_size: 1,152,000 samples = 9.2 MB
- limiter_buf_size: 80,640 samples = 0.6 MB
- Wasted: ~8.2 MB per filter instance

The bug was introduced when the limiter buffer was added but the
wrong size variable was used in av_malloc_array().
---
 libavfilter/af_loudnorm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/af_loudnorm.c b/libavfilter/af_loudnorm.c
index 432b9710a5..00d0a145ae 100644
--- a/libavfilter/af_loudnorm.c
+++ b/libavfilter/af_loudnorm.c
@@ -774,7 +774,7 @@ static int config_input(AVFilterLink *inlink)
         return AVERROR(ENOMEM);
 
     s->limiter_buf_size = frame_size(inlink->sample_rate, 210) * inlink->ch_layout.nb_channels;
-    s->limiter_buf = av_malloc_array(s->buf_size, sizeof(*s->limiter_buf));
+    s->limiter_buf = av_malloc_array(s->limiter_buf_size, sizeof(*s->limiter_buf));
     if (!s->limiter_buf)
         return AVERROR(ENOMEM);
 
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2026-01-13 17:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=176832671620.25.15101392399745361618@4457048688e7 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git