This forum has been archived. All content is frozen. Please use KDE Discuss instead.

BPM Detection Shell Script

Tags: None
(comma "," separated)
aroedl
Registered Member
Posts
2
Karma
0

BPM Detection Shell Script

Sat Aug 05, 2006 2:35 am
This is a quick and dirty shell script to automatically add BPM values to your music collection. I wrote it in a couple of minutes, but it works great.

Have fun.

Code: Select all
#!/bin/bash
#
# Amarok BPM (quick and dirty)
#
# Andreas Roedl <andreas.roedl@googlemail.com>
#
# 1. Make sure you have SoundTouch installed:  http://www.surina.net/soundtouch/
#    The Gentoo package is called libsoundtouch
#
# 2. Start Amarok and load a few tracks or even your whole collection into the playlist
#
# 3. Add the BPM column to your playlist view (right mouse click on listview title row)
#
# 4. tmpDir* should point to your /tmp directory. For maximum speed, point it to a tmpfs mount.
#    Example:  mkdir /mnt/tmpfs ; mount none -t tmpfs /mnt/tmpfs
#
# 5. Start playing the first track in the playlist
#
# 6. Start this script in a shell console
#
# Keep in mind: BPM detection is never absolutely accurate, but it is good enough and better
# than nothing. Don't worry if it can't find a value for every track.

# *Configure this (/tmp or your tmpfs mount):
tmpDir=/tmp

totalTrackCount=`dcop amarok playlist getTotalTrackCount`

for ((I=1; $I <= $totalTrackCount; I++))
do
  amarokpath=`dcop amarok player path`
  mpg123 -w $tmpDir/amaroktmp.wav "$amarokpath"
  dcop amarok player setBpm `soundstretch $tmpDir/amaroktmp.wav -bpm | awk '/Detected/ {printf "%d", $4}'`
  rm $tmpDir/amaroktmp.wav
  dcop amarok player next
done

Last edited by aroedl on Fri Sep 01, 2006 8:15 pm, edited 1 time in total.
DjDarkman
Registered Member
Posts
53
Karma
0

Re: BPM Detection Shell Script

Fri Aug 18, 2006 5:46 am
A plugin for this would be nice.I don`t like the taught that I would need to run a bash script everytime I add something to my collection.But nice work.
iqon
Registered Member
Posts
1
Karma
0

Re: BPM Detection Shell Script

Fri Sep 01, 2006 7:24 pm
Modified script to do BPM for AAC (for those of use that moved from itunes).

Code: Select all
tmpDir=/tmp

totalTrackCount=`dcop amarok playlist getTotalTrackCount`

for ((I=1; $I <= $totalTrackCount; I++))
do
  amarokpath=`dcop amarok player path`
  filename=`basename "$amarokpath"`
  if [ "`basename \"$filename\" \".m4a\"`" = "$filename" ]; then
    mpg123 -w $tmpDir/amaroktmp.wav "$amarokpath"
  else
    faad -o $tmpDir/amaroktmp.wav "$amarokpath"
  fi
  echo "soundstretch $tmpDir/amaroktmp.wav -bpm | awk '/Detected/ {printf \"%d\", $4}'"
  soundstretch $tmpDir/amaroktmp.wav -bpm
  dcop amarok player setBpm `soundstretch $tmpDir/amaroktmp.wav -bpm | awk '/Detected/ {printf "%d", $4}'`
  rm $tmpDir/amaroktmp.wav
  dcop amarok player next
done

Last edited by iqon on Fri Sep 01, 2006 7:33 pm, edited 1 time in total.
Matt
Registered Member
Posts
1
Karma
0

Re: BPM Detection Shell Script

Tue Feb 27, 2007 10:11 am
A plugin for Amarok would probably be the best way to do this - you don't necessarily need to calculate BPMs for your whole collection, but to select a bunch of tracks and have Amarok go off and work through them is fine.

I don't have soundstretch installed, but I do have bpmdetect (RPM from PackMan), which has the advantage that it can work directly from MP3s, and therefore the decoding step can be skipped (sorry, don't know if it'll work with AAC).

A couple of other things - I added a "test && exit" to the script in case the script gets called while the player is on a track other than the first one. This way it'll stop once the player runs out of tracks to play. However, the counter is still needed, in case the user has "repeat" enabled. (And if the user has "repeat track" enabled, the script will probably loop on that - this really isn't a perfect solution!)

Also, I ran into problems with cross-fading, which I normally have activated. Amarok would end up crashing because it was being asked to cross-fade too often. So disable that.

Code: Select all
#!/bin/bash
#
# Amarok BPM (quick and dirty)
#
# Andreas Roedl <andreas.roedl@googlemail.com>
#
# Modified, Matt Tovey, to use bpmdetect. No need for conversion to WAV...
#
# 1. Make sure you have bpmdetect installed.
#
# Name        : bpmdetect                    Relocations: (not relocatable)
# Version     : 0.4                               Vendor: Packman
# Release     : 0.pm.1                        Build Date: Sat 24 Feb 2007 06:56:38 PM CET
# Install date: Mon 26 Feb 2007 11:54:16 PM CET      Build Host: oc2pus
# Group       : Productivity/Multimedia/Sound/Utilities   Source RPM: bpmdetect-0.4-0.pm.1.src.rpm
# Size        : 160761                           License: GPL
# Signature   : DSA/SHA1, Sat 24 Feb 2007 06:56:41 PM CET, Key ID fa6d29cc1dfa8f0c
# Packager    : Toni Graffy <toni@links2linux.de>
# URL         : http://sourceforge.net/projects/bpmdetect
# Summary     : Simple BPM (beats per minute) detection utility
# Description :
# Simple BPM (beats per minute) detection utility.
#
# 2. Start Amarok and load a few tracks or even your whole collection into the playlist
#
# 3. Add the BPM column to your playlist view (right mouse click on listview title row)
#
# 4. Temporarily disable cross-fading while the scan is running
#
# 5. Start playing the first track in the playlist
#
# 6. Start this script in a shell console
#
# Keep in mind: BPM detection is never absolutely accurate, but it is good enough and better
# than nothing. Don't worry if it can't find a value for every track.

totalTrackCount=`dcop amarok playlist getTotalTrackCount`

for ((I=1; $I <= $totalTrackCount; I++))
do
  amarokpath=`dcop amarok player path`
  [ -z "$amarokpath" ] && exit
  BPM=`/opt/kde3/bin/bpmdetect -f -s -c "$amarokpath" | awk '/BPM found/ {print $1}'`
  if [ -n "$BPM" ]
  then
    dcop amarok player setBpm $BPM
    echo "$BPM  $amarokpath"
  else
    echo "X     $amarokpath"
  fi
  dcop amarok player next
done


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]