jump to navigation

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:

  1. My mp3s should not be irretrievably changed into something I end up hating
  2. I did not want all songs sounding as loud as the loudest song
  3. 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.

Comments»

1. meneame.net - September 11, 2006

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/

2. Comment - September 12, 2006

Have you heard about Gnormalize? give it a look, is pretty nice.

3. AK - September 12, 2006

Gnormalize converts to WAV and then back to lossy compression. That’s not a very good way to do this.

4. Rob - September 12, 2006

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

5. Beuno - September 12, 2006

I converted almos 2900 MP3s at an average of 4 seconds per file.
Using a P4 3.2 1gb ram laptop

6. HOWTO: Normalize the Gain of your MP3s « Alt-Ctrl-Del - September 12, 2006

[…] Normalize the Gain (Playback Volume) of your MP3s […]

7. oleg - September 12, 2006

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

8. trewas - September 13, 2006

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.

9. ubuntonista - September 13, 2006

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 🙂

10. trewas - September 13, 2006

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 😛

11. trewas - September 13, 2006

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 🙂

12. Simone Brunozzi - September 14, 2006

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?

13. ubuntonista - September 14, 2006

Simone, I wrote about this problem previously in the article below:
https://ubuntu.wordpress.com/2005/10/08/find-duplicate-copies-of-files/

14. Simone Brunozzi - September 14, 2006

Ah, thanks! Although it do not detect clone mp3 that differ only on bitrate 🙂

Cheers,

15. A nonny mouse - September 16, 2006

You will also be delighted to know, that all your MP3s now probably have an APE tag.

Surprise!

16. Normalizar el audio de los mp3 « /home/darkomen - September 18, 2006

[…] 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 […]

17. Bitelia » Normalizar audio MP3 - September 18, 2006

[…] home/darkomen y Ubuntu Blog) (¡Gracias Salva!) Enlace Permanente | Enviar por email a un amigo Más anotaciones de: Linux,Multimedia […]

18. porges » Blog Archive » Normalizing your MP3 collection with mp3gain - September 19, 2006

[…] Carthik Sharma from Ubuntu Blog suggests the following method to normalize all the MP3 files in your collection: […]

19. Parwinder Sekhon - September 24, 2006

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.

20. Philip - September 25, 2006

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

21. Dani - December 5, 2006

And What Have I to do if I want to normalize whit mp3gain mp3 files losted en in a 50 different folders?

22. Blippe - December 19, 2006

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.

23. Sonicgrass - February 8, 2007

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?

24. cank - February 22, 2007

Sonicgrass: I’ve never heard sth to solve your problem. I’m sorry.

25. tubelius - March 4, 2007

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$

26. tubelius - March 7, 2007

okey, it works now..

find /hda1/files/music -type f -iname *.mp3 -print0 | xargs -0 mp3gain -r -k >> ~/mp3gain

27. rob - March 31, 2007

how do you ezactly undo it?

28. chumbawumba - May 11, 2007

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.

29. Refah - September 9, 2007

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….

30. Mr.mepis - December 31, 2007

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

31. Moewes.com » links for 2008-01-07 - January 7, 2008

[…] Normalize the Gain (Playback Volume) of your MP3s « Ubuntu Blog mp3gain -r -k […]

32. Carl van Tonder - January 21, 2008

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.

33. NavahoGL - February 16, 2008

BTW there’s no need for xargs; this’ll do just fine:

find /path/to/mp3s -name “*.mp3” -exec mp3gain -r -k {} \;

🙂

34. Normalizar el volumen de tu colección de música « Jorge Díaz Bes - October 8, 2008

[…] 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: […]

35. Normalizar el volumen de los mp3 » The Chux Norrix blog - July 16, 2009

[…] 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 […]

36. sikiş - July 16, 2009

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.

a - January 22, 2011

dude, what?

37. How-To: Normalize the volume of your MP3s in Ubuntu 9.10 + mp3gain « mundane idiosyncrasies - December 5, 2009

[…] 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 […]

38. sikiş - February 12, 2010

thanks for making this page.

39. Carlos Vieira - May 23, 2010

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.

40. sikiş izle - September 26, 2010

Have you heard about Gnormalize? give it a look, is pretty nice.

41. antalya ilaçlama - September 27, 2010

how do you ezactly undo it?

42. porno sikiş - September 27, 2010

Ah, thanks! Although it do not detect clone mp3 that differ only on bitrate

43. sex sikiş - September 28, 2010

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?

44. Harry - December 23, 2010

wow! thats exactly I was searching for.
Thanks!!

Harry

45. jonny rocket - December 30, 2010

flac is KING!

46. gust0pher - June 15, 2011

Dude. Thanks!

And I love Ubuntu.

47. antalya böcek ilaçlama - August 7, 2011

antalya ev ilaçlama

48. hillry - May 16, 2012

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.

49. hillry - May 16, 2012

Neat, it wrecked the command. That should be “… read -d [dollarsign][singlequote][backslash][zero][singlequote] dirname …”


Leave a Reply to ubuntonista Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: