Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a simple normalization mode using loudnorm stats and the audio volume filter #274

Open
ahmetsait opened this issue Dec 10, 2024 · 1 comment
Labels

Comments

@ahmetsait
Copy link
Contributor

I've been trying to make ffmpeg's loudnorm filter fit into my music processing pipeline via ffmpeg-normalize (like many people did, as evident by the various issues) but it seems that loudnorm is not designed for music, where preserving the dynamic range / linearity is more important than achieving the desired loudness metrics. (podcasts, realtime audio, etc.)

I have created a yet another option for making loudnorm behave linearly in #273 but this is more of a band-aid fix than a true solution, made necessary by loudnorm not allowing true peaks to be higher than 0 for some stupid reason.

What I propose instead is a very straightforward feature where we get loudness stats from the first loudnorm pass and just do a linear volume adjustment using ffmpeg's volume filter.

How does this work?
First of, I'm far from anything close to being an audio expert, but what I've gathered from my web research is that LUFS and dB are closely related metrics such that e.g. a -4dB change in volume will result in -4 LUFS change (approx).
Please inform me if my understanding is incorrect.

So the code is basically this:

  1. Get input_i from first pass.
  2. Calculate necessary volume change: vol_change = target_level - input_i.
  3. Generate the filter: f"volume={vol_change}dB"

@slhck Let me know what do you think about the feature request and whether you are willing to work on this. I might get to it myself (or not depending on how life goes).

@slhck
Copy link
Owner

slhck commented Dec 11, 2024

made necessary by loudnorm not allowing true peaks to be higher than 0 for some stupid reason

If you had a true peak higher than 0 dBFS/LUFS, it would clip the signal, so it's not desirable to have that, and you must compress/limit the signal to avoid this. It is my understanding that loudnorm will use dynamic normalization in such cases, and linear normalization only when it can change the signal without clipping.

Using the volume filter without taking care of those peaks could result in clipping too — and linear normalization is essentially the same as just applying a constant (positive or negative) gain to reach a certain target, except it's done in the LU domain where the perceived volume is measured slightly differently rather than just using RMS. I am not sure if you can safely apply volume filter dB changes based on the readings you got from loudnorm's first pass.

If you just want to process with a simple volume filter you can revert to RMS-based normalization in ffmpeg-normalize which uses the volumedetect filter in the first pass, and a volume filter in the second pass.

@slhck slhck added the question label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants