slhck / ffmpeg-normalize

Audio Normalization for Python/ffmpeg
MIT License
1.25k stars 117 forks source link

questions regarding options #164

Closed atomGit closed 2 years ago

atomGit commented 2 years ago

i'm not fully understanding how to go about normalizing multimedia files (mp4, avi, mkv)

Q1:

in addition to changing the gain so that, for example, all files reach 0db, i also need to compress (if that's the correct word) the audio in order to narrow the range that the volume can traverse - in other words, make the quiet parts louder

i'm assuming this is where the LOUDNESS_RANGE_TARGET option comes into play, but i'm not positive i understand how a value of 1.0 - 20.0 correlates with volume/gain - does a smaller value mean that the volume won't drift/change as much?

if the audio ranged from 0 to -20 db for example, and i set LOUDNESS_RANGE_TARGET to 1, would the audio then range from roughly 0 to -1 db (all sounds would be of approx. equal loudness)?

Q2:

ideally i'd like to copy the audio using the same bit/sample rates and avoid re-sampling and re-encoding (similar to applying ReplayGain to an audio file) - a) is this possible and b), would this introduce compression artifacts?

RE: MP3Gain - this util is mentioned in the readme.md - in my opinion no one should be using it - if someone, for whatever reason, wants to mess with the dying MP3 format, loudgain is far superior to MP3Gain - it also handles many more formats, including mp4 - unfortunately i'm not sure any video players support reading RG info

slhck commented 2 years ago

in addition to changing the gain so that, for example, all files reach 0db, i also need to compress (if that's the correct word) the audio in order to narrow the range that the volume can traverse - in other words, make the quiet parts louder

That would be called compression indeed. There are various compression options in ffmpeg, including the dynaudnorm filter. Examples here: https://github.com/slhck/ffmpeg-normalize/wiki/examples#filters

I am not sure how musical dynaudnorm is. You can also use the acompressor filter, which acts like a normal compressor that you'd find in audio mixing software. These can be inserted as pre-filters before the loudness normalization kicks in, so you essentially compress the audio signal before you change the overall target volume.

i'm assuming this is where the LOUDNESS_RANGE_TARGET option comes into play, but i'm not positive i understand how a value of 1.0 - 20.0 correlates with volume/gain - does a smaller value mean that the volume won't drift/change as much?

Yes.

if the audio ranged from 0 to -20 db for example, and i set LOUDNESS_RANGE_TARGET to 1, would the audio then range from roughly 0 to -1 db (all sounds would be of approx. equal loudness)?

I believe so, although I haven't fully verified all the options. Normalizing the same input file with the default options vs choosing LRT of 1 gives me the following:

out-original

out-lrt1

You'll notice, especially at the end of the song, where it gets quieter, that the loudness range indeed is lower; everything is more squeezed.

That said, choosing a lower LRT seems to have introduced some overall volume shifts at the beginning of the song. This is a known issue with the underlying loudnorm filter that I haven't yet fully understood.


ideally i'd like to copy the audio using the same bit/sample rates and avoid re-sampling and re-encoding (similar to applying ReplayGain to an audio file) - a) is this possible and b), would this introduce compression artifacts?

Just using the same bitrate and sample rate is not enough if you use a lossy audio encoder like AAC. The default for this tool is to use PCM audio, which is uncompressed. If you are going to pick a lossy codec, you probably want a higher output bitrate than your input.

RE: MP3Gain - this util is mentioned in the readme.md - in my opinion no one should be using it - if someone, for whatever reason, wants to mess with the dying MP3 format, loudgain is far superior to MP3Gain - it also handles many more formats, including mp4 - unfortunately i'm not sure any video players support reading RG info

Interesting tool! It would kind of solve all these problems, but if there's no universal support for reading it, that's a bit of a bummer.

slhck commented 2 years ago

Did my answer help?

atomGit commented 2 years ago

yes, sorry, i should've closed this issue prior - thanks