slhck / ffmpeg-normalize

Audio Normalization for Python/ffmpeg
MIT License
1.28k stars 118 forks source link

Larger loudness range than target #181

Closed manus693 closed 2 years ago

manus693 commented 2 years ago

Probably not an issue, but I'm having a hard time understanding this warning.

WARNING: Input file had loudness range of 15.0, which is larger than the loudness range target (7.0). Normalization will revert to dynamic mode. Choose a higher target loudness range if you want linear normalization. WARNING: In dynamic mode, the sample rate will automatically be set to 192 kHz by the loudnorm filter. Specify -ar/--sample-rate to override it.

What does it mean that it reverts to dynamic mode? Should I set the range to same as input? Why doesn't it do it automatically? I'm using this for videofiles, not music, just home video.

slhck commented 2 years ago

Linear normalization is recommended (even wanted by most folks), so I added the warning to indicate when the filter falls back to the dynamic mode. See https://github.com/slhck/ffmpeg-normalize/issues/176.

The setting could be done automatically to enable linear mode again, but it would also change the default settings for the loudness range target, which may be unwanted by others. So I decided to not change the defaults unless explictly set by the user — hence the warning.

Your options are:

  1. Keep processing as-is, if it sounds good, nothing to worry about.
  2. Specify -lrt 15, and the warning should hopefully disappear.
slhck commented 2 years ago

Closed for now, please reopen if you have any further questions.

sdfg2 commented 2 years ago

I've got a few, thought it was better to ask here than opening a new issue.

I had to do a lot of research about current normalization techniques to use this, and I see that you have stuck with the EBU official settings as default. Does using -lrt change these settings?

When settings -lrt, does the value matter? The file I just tried had a value of 19.8, should I set it to 19.8?

Is it better to set -lrt, or let it do dynamic but set -ar?

slhck commented 2 years ago

I am actually just revisiting this (as I am putting music files on my kid's music box), and it seems like it would be a good option to set the loudness range target to be the same as the input, to prevent dynamic normalization from happening, which I believe causes noticeable loudness variations and artifacts.

I will change that warning and at least provide the user an option to re-use the input's loudness range. I am not inclined to mess too much with the input compared to what the original filter does, that's why I think a dedicated option (like --keep-loudness-range) would be more suitable.

manus693 commented 2 years ago

Great. That something I wanted also.

slhck commented 2 years ago

This is added now in the newest version. Let me know if it works for you!

(I notice that I had better success with lower loudness targets in general … setting the target too high results in weird compression artifacts no matter if using dynamic or linear mode.)

sdfg2 commented 2 years ago

Just out of curiosity, what do you consider 'too high'?

I'm still figuring out how this all works, apologies.

slhck commented 2 years ago

Anything louder than -14 LUFS … at least from the bunch of files that I've tried.

sdfg2 commented 2 years ago

Oh right I think I'm getting confused. LUFS is the calculated perceived loudness? And loudness range I guess is to do with the peaks? I'm just trying to reconcile how loudness targets work when the warning talks about loudness range. Like, if -14 is 'too high' my brain is going 'so 19.3 is way too high'.

slhck commented 2 years ago

Yes, I was talking about the general loudness target (which is in LUFS for loudnorm). The range itself, to be honest, I haven't tested it much and left the setting as-is most of the time. It does not directly relate to the peak level — it's a measure of range, which could be the same even if the peak is lower.

I only learned about the fact that it reverts to dynamic normalization when the range isn't properly set (based on the ffmpeg documentation changing), so that's why I added some options to change it. I guess I'd have to do some listening tests and manual inspection to find out how much of a difference setting the range actually makes.

sdfg2 commented 2 years ago

It's still switching to dynamic on 67b1c48

Ignore me. I forgot about the new flag to set!

sdfg2 commented 2 years ago

Ok, I think this is related?

[loudnorm @ 0x558c8b90a880] Value 22.700000 for parameter 'lra' out of range [1 - 20]
Last message repeated 1 times
[loudnorm @ 0x558c8b90a880] Error setting option lra to value 22.7.
[Parsed_loudnorm_0 @ 0x558c8b90a780] Error applying options to the filter.
[AVFilterGraph @ 0x558c8b908b00] Error initializing filter 'loudnorm' with args 'i=-23.0:lra=22.7:tp=-2.0:offset=-0.33:measured_i=-14.29:measured_lra=22.7:measured_tp=-0.89:measured_thresh=-26.96:linear=true:print_format=json'
Error initializing complex filters.
Numerical result out of range
slhck commented 2 years ago

Yes, I guess the new loudness range target (taken from the input file) should be capped to the allowable range? Even more messing with defaults … hm.

sdfg2 commented 2 years ago

Damnit, I'm trying to work out doing album-level adjustments, and just found out my reference album is suffering from this. Is there anyway to manually set the lra just so I can continue testing? It looks like it's a parameter of the loudnorm filter that I can't do anything with?

slhck commented 2 years ago

You can use -lrt to set the target range manually.

sdfg2 commented 2 years ago

Ahhhhhhh just read the loudnorm docs and realise my mistake.

I thought lrt was the target, and lra was something else entirely. lrt is just what it's called in ffmpeg-normalize and lra is what it's called in loudnorm, right?

EDIT: ok, just a wee thing. I left --keep-loudness-range-target on by mistake, which overrides -ltr. Maybe set them as mutually exclusive or something?

slhck commented 2 years ago

I thought lrt was the target, and lra was something else entirely. lrt is just what it's called in ffmpeg-normalize and lra is what it's called in loudnorm, right?

Yes, that was an unfortunate choice I made when originally writing this program as a script.

EDIT: ok, just a wee thing. I left --keep-loudness-range-target on by mistake, which overrides -ltr. Maybe set them as mutually exclusive or something?

Good suggestion, done in e5aff714e055c0f87e82b0be95a661b1deb95ade.

sdfg2 commented 2 years ago

Just noticed something else: in the docs it says the range for lrt is "Range is 1.0 - 50.0." Isn't the highest 20 for loudnorm?

sdfg2 commented 2 years ago

Aha! I totally hijacked a reddit thread where someone was asking lra questions: https://www.reddit.com/r/ffmpeg/comments/wuj2i5/comment/ilbtx69/?utm_source=share&utm_medium=web2x&context=3

Basically, ffmpeg recently raised the limit from 20 to 50. I guess that's where the 50 range came from in the docs!

Edit: what do you know - my ffmpeg was a week out of date. Updated and it works!