desbma / r128gain

Fast audio loudness scanner & tagger (ReplayGain v2 / R128)
GNU Lesser General Public License v2.1
170 stars 9 forks source link

Different loudness for OPUS and MP3 files encoded from the same FLAC file. #25

Closed kartikynwa closed 3 years ago

kartikynwa commented 3 years ago

Hello. First of all thanks for making this software. I use it a lot and love it. :)

I am not sure if this is worth reporting but thought I'd ask anyway. This is the first time I have noticed something like this.

I am using this small script:

#!/usr/bin/env sh

ffmpeg -i ./electric_feel.flac -b:a 320k ./electric_feel.opus
ffmpeg -i ./electric_feel.flac -b:a 0 ./electric_feel.mp3
r128gain ./electric_feel.opus ./electric_feel.mp3

The resultant files are recognised to have different loudnesses.

Analyzing loudness of file './electric_feel.opus'...
Analyzing loudness of file './electric_feel.mp3'...
File './electric_feel.opus': loudness = -7.4 LUFS, sample peak = -
File './electric_feel.mp3': loudness = -7.8 LUFS, sample peak = 0.0 dBFS
Tagging file './electric_feel.opus'
Tagging file './electric_feel.mp3'

I think the difference is miniscule but on mpd I have set the preamp for replaygain tagged files to +8 because of which the OPUS file has noticeable distortion but the MP3 file seems fine.

I can provide electric_feel.flac if needed. Please feel free to close if this is a non-issue.

Thanks again.

desbma commented 3 years ago

I'm not 100% sure, but I'd say since lossy codecs alter the audio signal, they can introduce differences in the computed loudness.

I'm interested in looking at that file to satisfy my curiosity.

kartikynwa commented 3 years ago

@desbma http://ksynwa.xyz/electric_feel.zip

desbma commented 3 years ago

I think your file is loud, and has many peaks creating clipping when decoding.

Lossy codecs change the amplitude of the peaks, which changes the average loudness because there are many of them. Vorbis and AAC also change the loudness to -7.4 or -7.5 depending on the bitrate.

I think the difference is miniscule but on mpd I have set the preamp for replaygain tagged files to +8 because of which the OPUS file has noticeable distortion but the MP3 file seems fine.

Maybe for some reason, the R128_TRACK_GAIN tag is ignored, which effectively adds 8dB to an already clipping track, and makes it even more distorted.

kartikynwa commented 3 years ago

Thank you for the great insight. I will close the issue since it seems unrelated to r128gain.

Edit: You were 100% right and I should have experimented more before opening the issue. I have chosen album to be the default replaygain setting and I was under the impression that mpd would select TRACK replaygain if ALBUM was missing but isn't and is applying the replaygain preamp on top of that (I think). I'll go bother the mpd dev instead of you now.