Normalize the Gain (Playback Volume) of your MP3s September 11, 2006
Posted by Carthik in applications, commands, guides, packages, ubuntu.trackback
I confess to the grave sin of storing part of my music collection in the mp3 format – mostly music I have had around for ages. There, now that that is out of the way, let’s move on to making that collection friendlier.
I have the habit of going to sleep while listening to a little light music. Some of the songs in my collection would sound louder than the others. So when I have a couple of classical music tracks lined up with Paul McCartney and Guns ‘N Roses, I sometimes get jolted awake by the difference in the playback volume. So off I went looking for solutions.
My main concerns when I started my research were:
- My mp3s should not be irretrievably changed into something I end up hating
- I did not want all songs sounding as loud as the loudest song
- The algorithm or method used should be free of the application used for music playback
Then came the choices. In the end it all came down to two apps: Normalize and mp3gain. Now how do I decide which one’s the one for me without learning DSP? Simple, search some more.
Fortunately, besides the websites for the applications, I ran into this thread at jwz’s livejournal. Thank god for geeks-who-start-nightclubs and their friends! I also followed most of the replaygain technical outline, since mp3gain is an implementation of the replaygain idea.
Normalize is simple, perhaps a little too simple.
mp3gain works by figuring out how loud the music actually sounds to the human ear, and then figuring out how much positive or negative gain to apply to the mp3 file to “fix” it. I was happy to note that it does not use the peak volume in a file as a benchmark for normalization. It applies changes by modifying the mp3 file in some fashion, but I read that the change is reversible since mp3gain writes some tags (not ID3 tags) to the mp3s for possible later undoing. This fact also means that one you use mp3gain on a file, if you try doing it again, it takes a lot less time – almost no time. So in the future if I add files to the collection, and I don’t remember what files I added, I can run mp3gain on the entire collection, and it will complete much faster than the first time.
To cut to the chase, I decided to go with mp3gain. I installed the mp3gain package (using $sudo apt-get install mp3gain), and set out to normalize my entire music collection. (For those of you who also have .oggs, check out vorbisgain).
Edit: for an alternative command, with explanation, and a way to use album-gain for songs from albums, visit porges
The following command, executed from the directory where I store my music normalized all the files in my collection:
$find . -type f -iname '*.mp3' -print0 | xargs -0 mp3gain -r -k
What it does is, it finds all files (type -f) in the present directory (.) with a name that ends in “.mp3” and creates a list of the same. The output of this find command is then piped to the mp3gain program. The options that I ended up using for mp3gain, -r and -k dictate that the calculated track gain will be applied automatically to normalize the volume, and that files should be protected against “clipping” by lowering the applied gain if the required gain seems likely to clip the sound. Concoct your own recipe by referring to the man page for mp3gain.
After around 16 hours of processing on my old PIII desktop, my massive 50 GB music collection now agrees on what is an acceptable volume. Needless to say, I sleep in peace.
Normalizar el volumen de tus MP3
Para los que están sobre Linux (especialmente Ubuntu) y tienen una colección de mp3 importante, les dejo una forma sencillisima de *igualar* el volumen de todos los mp3. Via: http://www.kbglob.com/gnulinux/normalizando-el-volumen-de-tus-mp3/
Have you heard about Gnormalize? give it a look, is pretty nice.
Gnormalize converts to WAV and then back to lossy compression. That’s not a very good way to do this.
Cool write up…I fear how long it would take to do this though…I just use amarok’s replaygain plug in…then again im not really sure it does any thing
I converted almos 2900 MP3s at an average of 4 seconds per file.
Using a P4 3.2 1gb ram laptop
[…] Normalize the Gain (Playback Volume) of your MP3s […]
some people do love GUI’s on linux, in this case there is a good addition to mp3gain: http://www.step.polymtl.ca/~guardia/javamp3gain.php
just have any version of sun java installed, 1.4.2-1.5.x
Unless you had only separate tracks and not full albums (which is a bit hard to believe with 50GB collection), that command f****d up your mp3s pretty bad. The flag -r means track gain, so it adjusts the gain for each track separately. So, if an album has tracks with intentionally varying “loudness”, they’ll be adjusted with different gains and the intentional loudness differences disappear.
At least in metal albums there often is a soft intro track, which is meant to be quiet, before going to real heavier stuff. Applying track gain makes that difference go away, and when listening to the album there will be no satisfying “blast” when the intro is over and the killing begins.
For that reason there is album gain (option -a) which adjusts gain for a bunch of tracks together, so the differences between tracks in the same album are preserved.
trewas,
I purposely chose to optimize each song individually, the album gain option applies the same gain adjustment to all songs in the album, but how would that value of gain adjustment be measured? Now, I risk some “intro” songs being a little louder, but I haven’t noticed any perceivable change. More than half my collection is classical music, and after I made the changes, I can listen to each without straining, or squeaming.
I know others may have other preferences, which is why I urged my readers to come up with their own set of parameters.
Thank you for stating what you did – though I wish you’d use swear words more sparingly in normal conversation 🙂
Album gain essentially treats the whole album as one long track when measuring the required gain changes. In my opinion there is no reason not to use album gain instead of track gain (well, unless the files really are from separate sources), but then again, I haven’t used it much with classical music. And everyone is of course free to use it however they want 🙂
And sorry for swearing 😛
And to clarify, when using mp3gain with album gain it must be given a bunch of mp3s at the same time (it does not try to guess what an album is, with mp3gain -a it treats all the given mp3s as one album). Those mp3s are then concidered as one long track and all of their gains are changed by equal amount. Your original command would have to be changed if album gain were to be used, quite trivially if one directory always contains one album, but if not then it will get hairy… But I’m off now 🙂
Now, the subsequent question would be:
if I have tons of mp3, and would like to eliminate clones (identical songs, that can differ from bitrate or name), which tool can I use?
Simone, I wrote about this problem previously in the article below:
https://ubuntu.wordpress.com/2005/10/08/find-duplicate-copies-of-files/
Ah, thanks! Although it do not detect clone mp3 that differ only on bitrate 🙂
Cheers,
You will also be delighted to know, that all your MP3s now probably have an APE tag.
Surprise!
[…] Dando una vuelta por el blog de ubuntu. Veo un interesante manual para normalizar el audio de nuestros mp3. Tan solo nos hace falta el programa mp3gain(disponible en los repositorios de ubuntu). Abrimos una consola, nos dirijimos al directorio donde tengamos los mp3 y ejecutamos $find . -type f -iname ‘*.mp3’ -print0 | xargs -0 mp3gain -r -k […]
[…] home/darkomen y Ubuntu Blog) (¡Gracias Salva!) Enlace Permanente | Enviar por email a un amigo Más anotaciones de: Linux,Multimedia […]
[…] Carthik Sharma from Ubuntu Blog suggests the following method to normalize all the MP3 files in your collection: […]
I found mp3gain crashing intermittently when piping in output from “find”. This disappered when I used the “-n 1” option with xargs. Adding this option calls mp3gain seperately for each file.
e.g.
(find /srv/files/music -type f -iname ‘*.mp3’ -print0 | xargs -0 -n 1 mp3gain -r -k) | tee mp3gain.log
(note the tee command just pipes output to the screen and a log file.
Is there any program that will take a long track ie about 90 min and increase the volume in low areas and decrease the volume in high areas?
Thanks
And What Have I to do if I want to normalize whit mp3gain mp3 files losted en in a 50 different folders?
Quite funny, normally track gaining is inadvisable to do on a collection of classical music more so than any modern album, since classical music have a lot more _planned_ differences between loud and soft tracks, and modern album often is “condensed” to sound as loud as possible, since most people seem to think louder is better.
First time I ever read someone with a metal collection point the fact about track versus album gaining out and a classical music fan telling that person that it doesn’t matter.
Well, since more and more players actually start to support replaygain (that is mp3gaining on the fly), these kind of guides will hopefully be forgotten.
I would like a normalizer for just standard audio output specifically for use with flash technology at http://www.Pandora.com which has streaming output. My operating system is Ubuntu. Any suggestions?
Sonicgrass: I’ve never heard sth to solve your problem. I’m sorry.
Hi. The command doesn’t work with subdirectories or files with capital letters on suffix, right?
tubelius@radiant:/hda1/files/music$ ls -l
total 16
drwxrwxr-x 28 tubelius tubelius 4096 2007-02-10 14:20 albums_(not_full)
drwxrwxr-x 128 tubelius tubelius 4096 2007-02-04 13:46 artists
drwxrwxr-x 26 tubelius tubelius 4096 2006-10-24 14:23 characters
drwxrwxr-x 22 tubelius tubelius 4096 2007-02-11 23:20 soundtracks (incomplete)
tubelius@radiant:/hda1/files/music$ $find . -type f -iname ‘*.mp3’ -print0 | xargs -0 mp3gain -r -k >> ~/normalize
-bash: .: -t: invalid option
.: usage: . filename [arguments]
tubelius@radiant:/hda1/files/music$
okey, it works now..
find /hda1/files/music -type f -iname *.mp3 -print0 | xargs -0 mp3gain -r -k >> ~/mp3gain
how do you ezactly undo it?
Hi, really like your site. Just got a question, does anybody know where I can buy software called Mototools 6 from?
It’s used for unlocking Motorola phones with the IMEI, and I really need it, as I don’t have a cable to link my phone to my PC.
Please help! Thanks in advance for any help.
If you’re an idiot, like me, and wondered why you were getting “-t: invalid option” the answer is (embarrassingly) simple,
WRONG:
$find . -type f -iname ‘*.mp3’ -print0 | xargs -0 mp3gain -r -k
RIGHT:
find . -type f -iname ‘*.mp3’ -print0 | xargs -0 mp3gain -r -k
$ = prompt ….duh….
This is a great use of mp3gain, thanks for making this page. I linked it from my site to help more of those with embarassing volumes at their parties! http://www.users.bigpond.com/telmer
[…] Normalize the Gain (Playback Volume) of your MP3s « Ubuntu Blog mp3gain -r -k […]
To automatically process an mp3 collection, album-by-album:
for foo in */*; do mp3gain -a -k “$foo”/*.mp3 ; done
This assumes that mp3s are in Artist/Album or similar 2-layer directory structure, and also that you’re in your music root dir.
BTW there’s no need for xargs; this’ll do just fine:
find /path/to/mp3s -name “*.mp3” -exec mp3gain -r -k {} \;
🙂
[…] Normalizar el volumen de tu colección de música 8 10 2008 Para equilibrar el volumen de nuestra colección de MP3 podemos usar mp3gain tal y como nos indican en Ubuntu blog: […]
[…] más información, pasarse por el blog que me abrió los ojos a tan maravilloso invento. Tweet This!Share this on FacebookShare this on del.icio.usDigg this!Add this to Google […]
If Platybelodon did engage in this feeding style it could account for the crescent-shaped indentations in its front, lower incisors as well as the sharpness of those teeth. Just because the lower-jaw of Platybelodon looked shovel-like does not mean it used it like a shovel.
dude, what?
[…] ubuntu — proletaryo @ 11:26 pm I stumbled on this tool, mp3gain, last week from this blog site. I tried it out back then and forgot about […]
thanks for making this page.
There’s a GTK frontend for mp3gain, aacgain and vorbisgain called easyMP3gain. (I found it on the Ubuntu repositories.) Too bad it doesn’t work with FLAC.
Have you heard about Gnormalize? give it a look, is pretty nice.
how do you ezactly undo it?
Ah, thanks! Although it do not detect clone mp3 that differ only on bitrate
Now, the subsequent question would be:
if I have tons of mp3, and would like to eliminate clones (identical songs, that can differ from bitrate or name), which tool can I use?
wow! thats exactly I was searching for.
Thanks!!
Harry
flac is KING!
Dude. Thanks!
And I love Ubuntu.
antalya ev ilaçlama
To normalize a music collection by album, try this:
$ find . -type d -print0 | while read -d $” dirname; do mp3gain -a -k “${dirname}”/*.mp3; done
It works regardless of directory structure and won’t break when it encounters whitespace, special characters, or non-standard character encodings like some of the previous suggestions. Run it from the base directory of the collection or replace the “.” with the path to it.
Neat, it wrecked the command. That should be “… read -d [dollarsign][singlequote][backslash][zero][singlequote] dirname …”