xiph / opus-tools

A set of tools to encode, inspect, and decode audio in the Opus format.
https://opus-codec.org/
Other
224 stars 79 forks source link

ReplayGain calculation #2

Open xtemp09 opened 9 years ago

xtemp09 commented 9 years ago

Could you add ReplayGain calculation?

rillian commented 9 years ago

NB opusenc will convert ReplayGain tags attached to input flac files.

xtemp09 commented 9 years ago

If input file doesn't contain ReplayGain information in metadata, the encoder won't add it. =(

MisterZeus commented 8 years ago

I would have thought ReplayGain should be independent of audio encoding, as it can be done either before encoding (on the input .flac or .wav file) or after it (on the output .opus). I usually use foobar2000 to calc ReplayGain on the resulting Opus files.

Saying that, an optional(?) --add-replay-gain [album|track] switch on the encoder side would be a "nice bonus", conducive to Opus adoption on the net :-)

(or we could be super pro-active and make the encoder always add ReplayGain if it's missing, unless --no-replay-gain is used?)

rsmaior commented 7 years ago

@MisterZeus, as I know it ReplayGain is always used as a tag, it never clips the audio directly.

From my research, I could find that the wiki lists that as a To Do (https://wiki.xiph.org/OpusTodo): "EBU R128/Replaygain (half done— needs a gain tool)"

There is already initial work on this repo https://github.com/kepstin/opusgain, maybe someone could pick it again?

rsmaior commented 6 years ago

While the official support is not here, I just found two nice third-party that can do the job (both using R128_TRACK_GAIN of course).

https://github.com/kepstin/regainer and https://github.com/desbma/r128gain (this one besides the name has nothing to do with the old R128GAIN that now is called BS1770GAIN).

rsmaior commented 6 years ago

@rillian you said "NB opusenc will convert ReplayGain tags attached to input flac files" but I read here that the Opus RFC itself recommends avoid this. Is that correct?

rillian commented 6 years ago

The Opus RFC distinguishes between replaygain the feature, and REPLAY_GAIN the tag format. It says to implement the replaygain feature using tags with the EBU R128 normalization standard which is better defined and more professional.

The RFC says that tools shouldn't write tags using the REPLAY_GAIN normalization in opus files, the way loudness-scanner is reported to do in that thread.

What opusenc does instead is to convert REPLAY_GAIN tags in an input flac file to the R128 normalization scheme and write overall and R128_TRACK_GAIN annotations representing the same levels. So that's ok by the spec. What it's trying to avoid is just copying the REPLAY_GAIN tags without any conversion to the Opus standard.

Does that make sense?

vlakoff commented 6 years ago

Refs the related #39 :)

bertogg commented 1 year ago

Hello,

I'm not sure if this is the correct issue but I'm having a problem with how the Opus tools handle some ReplayGain tags.

Here are the steps to reproduce the problem:

  1. Start with a FLAC file. I'll use a public one for reference, the first track of this album: https://archive.org/details/nineinchnails_ghosts_I_IV
  2. Run loudgain -a -k -s e 01_Ghosts_I.flac (I'm using loudgain 0.6.8)
  3. This adds the following tags to the flac file:
    REPLAYGAIN_ALBUM_GAIN=-2.97 dB
    REPLAYGAIN_ALBUM_PEAK=0.956751
    REPLAYGAIN_ALBUM_RANGE=6.32 dB
    REPLAYGAIN_REFERENCE_LOUDNESS=-18.00 LUFS
    REPLAYGAIN_TRACK_GAIN=-2.97 dB
    REPLAYGAIN_TRACK_PEAK=0.956751
    REPLAYGAIN_TRACK_RANGE=6.32 dB
  4. Check how the flac file can still be played and decoded normally.
  5. Run opusenc --bitrate 128 01_Ghosts_I.flac 01_Ghosts_I.opus
  6. Run opusinfo 01_Ghosts_I.opus and notice the 'Playback gain' value:
    REPLAYGAIN_ALBUM_RANGE=6.32 dB
    REPLAYGAIN_TRACK_RANGE=6.32 dB
    R128_TRACK_GAIN=0
    Playback gain: 99.0312 dB

The Opus file is unplayable now, very loud and distorted. If you use opusdec you'll get a completely clipped signal.