[FFmpeg-devel] [PATCH] lavfilter/af_loudnorm: fix loudnorm limiter invalid at final frame
shu coon
xxk101010 at gmail.com
Sun Nov 19 08:18:30 EET 2023
Signed-off-by: 萧辰琨 <xiaochenkun at xiaohongshu.com>
---
libavfilter/af_loudnorm.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
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++) {
--
2.39.2 (Apple Git-143)
The issue will cause a large amount of clipping in the last 3 seconds of audio data. Causing this issue is due to s->limiter_buf_index and s->env_index being misaligned;
Following steps can be used to reproduce the issue:
1.Download the file from https://streams.videolan.org/ffmpeg/incoming/keyboard.mp4.
2.Run the following command.
ffmpeg -i 'keyboard.mp4' -af loudnorm=I=-12:TP=-1.0:LRA=7:measured_I=-44.37:measured_LRA=20.10:measured_thresh=-55.61:offset=4.18:linear=true:dual_mono=true:print_format=summary -ar 48000 'output.mp4'
More information about the ffmpeg-devel
mailing list