diff mbox series

[FFmpeg-devel] lavfilter/af_loudnorm: fix loudnorm limiter invalid at final frame

Message ID 74FC0A56-1A79-48BD-B146-516990C54944@gmail.com
State New
Headers show
Series [FFmpeg-devel] lavfilter/af_loudnorm: fix loudnorm limiter invalid at final frame | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch
andriy/configure_x86 warning Failed to apply patch

Commit Message

shu coon Nov. 19, 2023, 6:18 a.m. UTC
Signed-off-by: 萧辰琨 <xiaochenkun@xiaohongshu.com>
---
libavfilter/af_loudnorm.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Paul B Mahol Nov. 19, 2023, 11:39 a.m. UTC | #1
There are much more serious issues with this filter. That why my approach
and fix is to completely rewrite it.
diff mbox series

Patch

diff --git a/libavfilter/af_loudnorm.c b/libavfilter/af_loudnorm.c
index d83398ae2a..b8c10285ca 100644
--- a/libavfilter/af_loudnorm.c
+++ b/libavfilter/af_loudnorm.c
@@ -570,10 +570,10 @@  static int filter_frame(AVFilterLink *inlink, AVFrame *in)

    case FINAL_FRAME:
        gain = gaussian_filter(s, s->index + 10 < 30 ? s->index + 10 : s->index + 10 - 30);
-        s->limiter_buf_index = 0;
        src_index = 0;

-        for (n = 0; n < s->limiter_buf_size / inlink->ch_layout.nb_channels; n++) {
+        subframe_length = frame_size(inlink->sample_rate, 100);
+        for (n = 0; n < subframe_length; n++) {
            for (c = 0; c < inlink->ch_layout.nb_channels; c++) {
                s->limiter_buf[s->limiter_buf_index + c] = src[src_index + c] * gain * s->offset;
            }
@@ -658,6 +658,7 @@  static int flush_frame(AVFilterLink *outlink)
        offset  = ((s->limiter_buf_size / inlink->ch_layout.nb_channels) - s->prev_nb_samples) * inlink->ch_layout.nb_channels;
        offset -= (frame_size(inlink->sample_rate, 100) - s->prev_nb_samples) * inlink->ch_layout.nb_channels;
        s->buf_index = s->buf_index - offset < 0 ? s->buf_index - offset + s->buf_size : s->buf_index - offset;
+        s->limiter_buf_index = s->limiter_buf_index - offset < 0 ? s->limiter_buf_index - offset + s->limiter_buf_size : s->limiter_buf_index - offset;

        for (n = 0; n < nb_samples; n++) {
            for (c = 0; c < inlink->ch_layout.nb_channels; c++) {