Adding ReplayGain tags

There are command line tools for calculating ReplayGain values and adding ReplayGain tags. To install the tools for mp3, ogg and FLAC do the following:

sudo apt-get install mp3gain vorbisgain flac

Then to add ReplayGain tags to an album that consists of all files in a directory do the following for mp3:

mp3gain -a *.mp3

For the same task when the album is in ogg vorbis do the following:

vorbisgain -a *.ogg

For the same task when the album is in FLAC files do the following:

metaflac --add-replay-gain *.flac

If you want to add ReplayGain tags to files that are not albums instead use the -r option for mp3gain and vorbisgain (there is no corresponding option for metaflac):

mp3gain -r *.mp3
vorbisgain -r *.ogg

All tools can also be used to remove ReplayGain tags.

As always, make sure you have backups before proceed with any file modification. I have never had problems with these tools but I cannot guarantee they are failsafe (also, your computer could crash or you might have a power outage halfway through the process).


Instead of being "a bit scared" or following unrelated links, why not simply read the manual?

From man mp3gain:

   mp3gain optionally writes gain adjustments directly into the encoded data.  In  this
   case,  the  adjustment works with all mp3 players, i.e. no support for a special tag
   is required.  This mode is activated by any of the options -r, -a, -g, or -l.

   If none of the above options are given, the recommended gain change is instead writ‐
   ten  to  a special tag in the mp3 file. In this case, the adjustment only works with
   mp3 players that support this tag.  Some mp3 players refer to  this  as  ReplayGain.
   The  tag is written either in APEv2 format (default) or in ID3v2 format (with -s i).
   If you only want to print the recommended gain change (and not modify  the  file  at
   all) you may use the -s s (skip tag) option.

So it only modifies the audio stream if you tell it to, otherwise it writes to tags only.

Side note: many of the URLs posted in comments are not related to current mp3gain found in Ubuntu: they are either terribly outdated or they refer to the windows version.

Whenever in doubt as how a given command works, always try man first. If that is not enough (or no man page available), use the correct upstream website, which can be checked in Ubuntu's package page.


I got part of the way through (okay most of the way through :( ) writing a wrapper script for the answer supplied by "N.N." when I discovered rgain. The answers recommending mp3gain wouldn't work for me as my library is mostly flac. rgain (listed in package repositories as python-rgain) is a library for interacting with replay gain tags of various file types, but it also comes with some wrapper scripts for it's most apparent uses. I'm currently running it, it seems like it will take a long time, and we shall see how it performs in time...

sudo apt-get install -y python-rgain
collectiongain ~/Music

https://bitbucket.org/fk/rgain/

Edit: I have been using it for some time now and while it's not perfect, it has been a huge improvement to listening to music. I'd say I have to adjust the volume maybe 10-15% as much as I used to. It did take three or four days on my crappy old computer to analyze my whole library. I'm about to start it on some new stuff I've downloaded.

Also, when I was running it the first time, it got interrupted a few times, and didn't explain why. I just ran it again, and it picked up analyzing where it left off, having successfully saved the tags it had done so far. What I mean is, it scans much faster than it analyzes so if it stops just restart it.