有没有适用于 Linux 的节拍检测软件?

kol*_*pto 32 linux mp3 music bpm beat-detection

Amarok 2 可以使用 ID3v2 标签的“bpm”字段搜索音乐收藏。重新标记整个音乐收藏会非常好,这样我就可以找到我喜欢的曲目的“情绪”。

但是,我没有找到任何可以帮助我的节拍检测软件。你用过吗?CLI,最好。我也很感兴趣,是否有类似的东西可以用相同的“bpm”字段标记 FLAC。

谢谢!:)

PS 我知道有一个不错的心情栏功能,但是它对搜索没有用。

kol*_*pto 19

在站点 DaveParillo 建议我找到了BpmDj项目。它有一个bpmcount可以很好地计算 bpm的可执行文件:它可以处理 mp3 和 flac:

161.135 Metallica/2008 - Death Magnetic/01-That Was Just Your Life.flac
63.5645 Doom3.mp3
Run Code Online (Sandbox Code Playgroud)

唯一剩下的就是重新标记集合。每当我成功时,我都会更新这个答案。谢谢!:)


第1步

bpmcount针对整个集合运行并将结果存储到文本文件中。问题是它会bpmcount时不时地崩溃并在处理多个文件时尝试占用多达 2GB 的内存,因此我们应该将文件名一一提供给它。像这样:

musicdir='/home/ootync/music'
find "$musicdir" -iregex ".*\.\(mp3\|ogg\|flac\|ape\)" -exec bpmcount {} \; \
    | fgrep "$musicdir" > "$musicdir/BPMs.txt"
Run Code Online (Sandbox Code Playgroud)

第2步

我们需要一些额外的包:apt-get install vorbis-tools flac python-mutagen. 现在看看如何添加“bpm”标签:

mid3v2 --TBPM 100 doom3.mp3
vorbiscomment -a -t "BPM=100" mother.ogg
metaflac --set-tag="BPM=100" metallica.flac
Run Code Online (Sandbox Code Playgroud)

唉,我没有 *.ape 曲目

现在我们有了 BPM,应该重新标记整个集合。这是脚本:

cat "$musicdir/BPMs.txt" | while read bpm file ; do
    bpm=`printf "%.0f" "$bpm"` ;
    case "$file" in 
        *.mp3) mid3v2 --TBPM "$bpm" "$file" > /dev/null ;; 
        *.ogg) vorbiscomment -a -t "BPM=$bpm" "$file" ;; 
        *.flac) metaflac --set-tag="BPM=$bpm" "$file" ;; 
        esac
    done
Run Code Online (Sandbox Code Playgroud)

步骤 2.1 重新访问 这里有一个脚本,可以将 BPM 标签添加到您的集合中。

它为每个 CPU 内核运行一个进程以加快进程。此外,它不使用临时文件,并且能够检测文件是否已被标记。

此外,我发现 FLAC 有时同时包含 ID3 和 VorbisComment。此脚本更新两者。

#!/bin/bash

function display_help() {
    cat <<-HELP
            Recursive BPM-writer for multicore CPUs.
            It analyzes BPMs of every media file and writes a correct tag there.
            Usage: $(basename "$0") path [...]
            HELP
    exit 0
    }

[ $# -lt 1 ] && display_help

#=== Requirements
requires="bpmcount mid3v2 vorbiscomment metaflac"
which $requires > /dev/null || { echo "E: These binaries are required: $requires" >&2 ; exit 1; }

#=== Functions

function bpm_read(){
    local file="$1"
    local ext="${file##*.}"
    declare -l ext
    # Detect
    { case "$ext" in
        'mp3')  mid3v2 -l "$file" ;;
        'ogg')  vorbiscomment -l "$file" ;;
        'flac') metaflac --export-tags-to=- "$file" ;;
        esac ; } | fgrep 'BPM=' | cut -d'=' -f2
    }
function bpm_write(){
    local file="$1"
    local bpm="${2%%.*}"
    local ext="${file##*.}"
    declare -l ext
    echo "BPM=$bpm @$file"
    # Write
    case "$ext" in
        'mp3')  mid3v2 --TBPM "$bpm" "$file" ;;
        'ogg')  vorbiscomment -a -t "BPM=$bpm" "$file" ;;
        'flac') metaflac --set-tag="BPM=$bpm" "$file"
                mid3v2 --TBPM "$bpm" "$file" # Need to store to ID3 as well :(
                ;;
        esac
    }

#=== Process
function oneThread(){
    local file="$1"
    #=== Check whether there's an existing BPM
        local bpm=$(bpm_read "$file")
        [ "$bpm" != '' ] && return 0 # there's a nonempty BPM tag
    #=== Detect a new BPM
    # Detect a new bpm
    local bpm=$(bpmcount "$file" | grep '^[0-9]' | cut -f1)
    [ "$bpm" == '' ] && { echo "W: Invalid BPM '$bpm' detected @ $file" >&2 ; return 0 ; } # problems
    # Write it
    bpm_write "$file" "${bpm%%.*}" >/dev/null
    }

NUMCPU="$(grep ^processor /proc/cpuinfo | wc -l)"
find $@ -type f -regextype posix-awk -iregex '.*\.(mp3|ogg|flac)' \
    | while read file ; do
        [ `jobs -p | wc -l` -ge $NUMCPU ] && wait
        echo "$file"
        oneThread "$file" &
        done
Run Code Online (Sandbox Code Playgroud)

享受!:)


小智 9

这是一个用于检测 BPM 并将其放入 FLAC 文件标签的命令行工具:

http://www.pogo.org.uk/~mark/bpm-tools/


mer*_*ius 6

我使用了 kolypto 的原始脚本 usingbpmcount并将其重写为bpm-tag(utility of bpm-tools),我在安装时有更好的运气。我自己也做了一些改进。

您可以在 GitHub https://github.com/meridius/bpmwrap上找到它