Annotating MP3 files with BPM #

I wanted to tag my music library with the BPM of each song. There are commercial products for doing this through iTunes, but I wanted to do it from the command line, because I also use my music library outside of iTunes, and I don't want to be tied to iTunes anyway.

The bpm-tools package can calculate bpm for a song. On Mac, it's easy to install with Homebrew. The base package only includes the analyzer; I wanted something to tag my MP3 files too, so I used the =-with-bpm-tag= option. It ends up installing dependencies: mad, sox, id3lib, id3v2, flac, libogg, libvorbis, libao, vorbis-tools.

brew install bpm --bpm-tag
cd Music/iTunes\ Music/
find . -name \*.mp3 -exec bpm-tag '{}' ';'

However, the id3v2 command (on Mac/Homebrew, anyway) doesn't work the way bpm-tag wants, and for some reason sed wasn't cooperating with me, so I changed one line of /usr/local/bin/bpm-tag from

BPM=`id3v2 -l "$FILE" | sed -n 's/^TBPM.*: \([0-9\.]\+\)/\1/p'`


BPM=`id3v2 -l "$FILE" | sed -n 's/^TBPM.*: //p'`

This made it skip files that already had a BPM tag.

It took a while to run, but now all my MP3 files have a BPM, and iTunes picks that up too. Yay!

Labels: ,