Sorting music by BPM count

Sorting music by BPM count can be useful to build a collection of a specific tempo. Linux has a few tools that can count the beat per minute of a song, and while their accuracy is far from 100%, they can help built a playlist that can then be filtered manually.

Soundstretch

Soundstretch is one of those tools, available in Debian Jessie in the eponymous package. It works on WAV files, not MP3 or OGG, so conversion is needed prior to using it, which can easily be done by ffmpeg/avconv.

The script below takes a file path as input, converts it to wav, prints out its BPM and filename, then removes the wav file.

#!/usr/bin/env bash
input="$1"
wav="${input/mp3/wav}"
avconv -loglevel quiet -i "$input" "${wav}"
[ $? -gt 0 ] && exit 1
bpm="$(soundstretch "$wav" -bpm 2>&1 | grep 'Detected BPM rate' | awk '{print $4}')"
echo $bpm $input
rm "$wav"

It can be run as follows:

$ ./bpmcount.sh Albums/Electro/Laurent\ Garnier\ -\ Sonar\ 2013.mp3 
129.0 Albums/Electro/Laurent Garnier - Sonar 2013.mp3

Indicating that the average BPM for this song is 129 beats per minute.

The script can be run on an entire directory structure by simply using `find`:

find /path/to/music -name *.mp3 -exec ./bpmcount.sh {} \;

Redirect the output to a file, and you get a list of song with their associated BPM.

60.0 ./Albums/Drum-n-Bass/Justice/2007 - Cross/08 Tthhee Ppaarrttyy.mp3
115.0 ./Albums/Drum-n-Bass/Justice/2007 - Cross/04 Newjack.mp3
112.9 ./Albums/Drum-n-Bass/Justice/2007 - Cross/03 DANCE.mp3
117.5 ./Albums/Drum-n-Bass/Justice/2007 - Cross/05 Phantom.mp3
45.5 ./Albums/Drum-n-Bass/Interlope/ - Track11.mp3
140.0 ./Albums/Drum-n-Bass/Interlope/ - Track19.mp3

Accuracy is about 50%, it would seem, so you definitely need to re-filter the files manually afterward, and check the tempo with something like http://www.all8.com/tools/bpm.htm

MixMeister

MixMeister is a windows application that can load a bunch of MP3s at once and calculate their BPM. It runs in wine on Linux and seems to have about the same accuracy as soundstretch. You can download the EXE installer from CNET's website at http://download.cnet.com/MixMeister-BPM-Analyzer/3001-2169_4-10290906.html

en/ressources/astuces/soundstretch.txt · Last modified: 2017/05/29 19:01 by julien
CC Attribution-Noncommercial-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0