Convert to mp3 Using FFMPEG

In this example we will convert m4a audio files to mp3. But you can convert virtually any audio format.

$ mkdir converted
$ for f in *.m4a; do ffmpeg -i "$f" -codec:v copy -codec:a libmp3lame -q:a 2 converted/"${f%.m4a}.mp3"; done;
  • -q:a 2 means LAME’s option -V 2, which gives us a VBR MP3 audio stream with an average stereo bitrate of 170-210 kBit/s. See https://trac.ffmpeg.org/wiki/Encode/MP3 for more options.
  • make sure you convert to equal or lower quality (it would not make much sense to convert to better quality than the source)

ReplayGain your music using mp3gain

ReplayGain is the name of a technique invented to achieve the same perceived playback loudness of audio files. Read more on Hydrogenaudio.

Set all files to 92db – this is the most used loudness now-a-days (it’s recommended also in Serato DJ software and most streaming platforms seems to use same value). You might want to use 89db if you are listening on a Hi-Fi system – in this case just ignore the -d 3 option.

The suggested loudness is ~89, so we add 3.

mp3gain -d 3 -c -p -r *.mp3

or

mp3gain -s r -d 3 -c -p -r *.mp3

-s r this will ignore the replaygain information already stored in the file

-c will ignore clipping warning, use -k to lower the gain to not clip

-p preserve original timestamp of files

-r gain per track (as opposed to per album), it’s good for collections, best of, etc.

recursively apply gain to all your mp3 files

  • it works also for file names with spaces
find . -iname '*.mp3' -print0 | xargs -0 mp3gain -d 3 -c -p -r