Adding Volume Leveling to MP3Tag


I frequently listen to shuffled music and find the volume difference between songs to be somewhat annoying. Fixing this issue is primarily a tagging exercise. I use MP3Tag for all tagging, so I wanted the capability to adjust playback volume from within MP3Tag.

I decided to use mp3gain.exe for this because:

  1. it uses ReplayGain (IMO, a better implementation than peak leveling, e.g. the method used by Apple's Soundcheck),

  2. it has a good command line interface,

  3. it supports ID3 tags (Version 1.5.2), and

  4. it has an "Undo" function


I used MP3Tag's Export tool to build 7 Export Configurations (similar to the way ReplayGain is integrated into Foobar2000):

RG1 - Analyze selection as individual tracks:
$loop(%_filename_ext%)c:\Utils\MP3Gain\mp3gain /s i "%_folderpath%%_filename_ext%"

RG2 - Analyze selection as a single album:
c:\Utils\MP3Gain\mp3gain /s i $loop(%_filename_ext%)"%_folderpath%%_filename_ext%" $loopend()

RG3 - Analyze selection as albums (by folder):
$loop(%_folderpath%)c:\Utils\MP3Gain\mp3gain /s i %_folderpath%*.mp3"$loop(%_filename_ext%%)$loopend()

RG4 - Apply Track RG to selected MP3 files:
$loop(%_filename_ext%)c:\Utils\MP3Gain\mp3gain /s i /k /r "%_folderpath%%_filename_ext%"

RG5 - Apply Album RG to selected MP3 files
$loop(%_filename_ext%)c:\Utils\MP3Gain\mp3gain /s i /k /a "%_folderpath%%_filename_ext%"

RG6 - Undo RG for selected tracks:
$loop(%_filename_ext%)c:\Utils\MP3Gain\mp3gain /s i /u "%_folderpath%%_filename_ext%"

RG7 - Remove RG tags (can't Undo):
$loop(%_filename_ext%)c:\Utils\MP3Gain\mp3gain /s i /s d "%_folderpath%%_filename_ext%"


It certainly is possible to add more functionality with more complex Export Configurations. For example, I have one (RGX) that combines RG4 and RG5. I tag each track (take a field that you don't use, e.g. %encodersettings%) with mp3gain.exe parameters. Instead of explicitly containing the "/a" (album) or "/r" (track) parameter, RGX uses %encodersettings% to add the "/a" or "/r" into the export file. If I wanted to bump up the volume a little bit for a particular track, I put "/r /m 3" in the %encodersettings% field.


I'd be interested in help with improvements, including, but not limited to!:

  1. Adding ReplayGain, as a context menu item (like Export, Converter, Tools, etc.), and having these 7 functions and/or others available in the submenu.

  2. Suppressing the dialog box that confirms that you want to open the export file.

I respect your achievements on connecting the MP3Gain commandline tool with Mp3tag.
But ... for some people it looks rather complicated ... and I always do not recommend MP3Gain, because it works with the mp3 files on a destructive base by modifying the mp3 data stream, that means the MD5AUDIO checksum will be changed.

I use Mp3tag tools to apply non destructive Replay Gain this way ...
Use foobar tools within Mp3tag?
... and doing so I have instantly all Replay Gain options at hand, which are provided by foobar, since version 1.1.6 with precise quality, following the EBU R 128 standard for loudness normalisation.


I did a quick test using mp3gain.exe version 1.5.2 with one mp3 file ... and sorry, I have to correct:
The MD5AUDIO hash seems not to be touched when applying "mp3gain.exe /k /s i" against the mp3 file.
But the CRC32 hash and the overall MD5 hash has been changed ...
... surely due to the inserted tag-field "MP3GAIN_MINMAX".


I used to use Foobar, but your link didn't seem to lead me anywhere relevant...

  1. As far as I can determine, the changes to the data stream (modifications to the Global Gain Fields) can be undone, returning the file to the exact state it was before you applied the change. There are some very rare circumstances where this may not work, and for that reason, I back up my music before changing it.

  2. This method allows the volume leveled versions to play across all platforms, regardless of whether or not the player support reading ReplayGain tags.

  3. I don't know about the checksum - I haven't run into a situation where the adjusted mp3s don't work.

I believe Mp3Gain, by default, is non-destructive and doesn't alter the data, just adds tags. If not by default, command line options can tell it to behave this way.

I was playing with v1.5.2 today, and while I'd rather have the RG info in ID3v2 tags than APE tags, it appears that mp3gain.exe either converts an existing ID3v2.3 tag to ID3v2.4, or else it adds an ID3v2.4 tag to the existing tags in the Mp3 file. I need to investigate this more. Either way, it's highly undesirable behavior.

Can foobar2000 be run non-interactively from the command-line to add RG to Mp3s? A tool that launches a GUI is pretty close to useless, IMO.

I looked at it a little bit. Mp3gain uses id3v2.3 TXXX fields to store it's proprietary undo type information, but stores Track_Gain and Album_Gain in a ID3v2.4 field called RVA2. I'm guessing that is the new standard, which will make it easier for players to decode...

Under the given link above ...
... try out the Mp3tag tool definition for "foobar2000 Prepare for ReplayGain"
(for only preparing the foobar2000 playlist, there is no need to have the "foo_runcmd" component installed).
You will find the ReplayGain functions in foobar2000 in the context menu of the file list.
To apply foobar ReplayGain against a file or file list in Mp3tag there is only necessary to do three mouse clicks resp. to press three keys - much less effort than preparing a bunch of special export scripts and executing the scripts via the Mp3tag export feature.
In this way filenames with unicode characters are fully supported.

Yes you are right ... there may be coming up circumstances which make a backup needed.

Hm ... from time to time there are Mp3tag forum users, who report about media files, which they got from other persons or which they have mistreated by themselves by cutting off all tag-fields, that those files have cut off about 50 percent (-6 dB) of the audio volume.
Because the destructive ReplayGain method in the first step is to diminish the audio output level to give headroom for the replay levelling, a player, which does not support the ReplayGain method, does not play the file in its orginal loudness as it has been delivered from the original manufacturer.


That's not what I found. Mind you, I'm only interested in having the files tagged with REPLAYGAIN data, not actually altering the data to effect volume normalization.

When using '/s a' (the default) to write APE tags, mp3gain writes the following fields and leaves the ID3v2.3 tag intact:


It's the REPLAYGAIN fields that I'm interested in, as I use Mp3s only on my portable players running Rockbox and those are the fields that it recognizes. These are somewhat of a standard.

But when using '/s i' to write ID3v2 tags, mp3gain changes the ID3v2.3 tag to an ID3v2.4 tag and writes only these fields:


I think the only way I could use it would be to allow it to write APE tags and then use some other app to read the RG fields and transfer the data to the ID3v2.3 tag, then delete the APE tag.

Me too.

Note the peculiarity: mp3gain saves the ID3v2.4 tag with UTF-16 character encoding instead of UTF-8.

The Mp3tag community is searching for that special tool since years. :wink:


One day after the Mayan calendar catastrophe: I am a survivor.

My description applies when you use mp3gain's "/s i" parameter.

It also puts the Peak and Gain values listed above into "RVA2" fields(s).

If you were to apply the RG, mp3gain would also add an MP3GAIN_UNDO tag.


I'm with you now re: the tools.ini/foobar approach. If I were to use Foobar's "Apply Track ReplayGain to MP3 data" function, would it automatically reduce the Track_Gain applied, according to the Track_Peak, in order to avoid clipping?

As I said ... never I do apply the ReplayGain method the hard way against mp3 files by manipulating the mp3 volume frames.
There is the saying "You never know until you try" resp. in german "Versuch macht klug" (an attempt makes wise).
Please try it out and tell us what you have find out.


you can either write replaygain values into the meta, or--in case of some formats such as MP3--you can modify the audio directly by changing the frame headers. both ways are reversible for all practical purposes. (strictly speaking, it is possible to have rounding errors when using the latter method.) modifying the gain values directly in the audio has a few disadvantages, so i would recommend writing to the meta instead--if your audio players support reading replaygain from the meta.

actually, replaygain isn't quite the state-of-the-art anymore. i'm not an expert but it is my subjective experience that ebu r128 does a better job. foobar2000 switched from replaygain to ebu r128 some time ago.

fb2k is also the software i recommend using to compute and apply the gains. (but alternatives, including CLI-based ones, exist for both replaygain as well as ebu r128.)

EDIT: i guess detlev already explained some of this stuff, should've read the full thread first :astonished:

I believe that mp3gain (and FB2K) use a different approach to figuring out the "peak". Mp3gain's methodology uses another peak measure, mp3gain_minmax, referring to the Global Gain Field (GGF) values it has found inside the mp3 frames. I'm guessing that Foobar does a similar thing. These tools then adjust the volume in the mp3 frames, by adjusting the GGFs. Then, in order to maintain compatibility with ReplayGain compliant players, they adjust the REPLAYGAIN_TRACK_GAIN and REPLAYGAIN_TRACK_PEAK to reflect the volume changes made to the mp3 data.