导出文件夹中mp3文件的总长度?

Ana*_*sia 2 audio mp3 music audiobook music-management

我有很多 mp3 文件的文件夹,我想列出每个文件夹中所有 mp3 的组合持续时间。这将是理想的解决方案,但某些附加单个 mp3 持续时间的目录打印方法也很好。任何帮助将非常感激。我运行的是 Windows 7 Home Premium,但可以访问许多其他 Windows/Mac OS。

编辑 - 我实际上使用免费软件程序 Tagscanner 中的导出功能找到了一个解决方案。

slh*_*hck 5

如果你在 Mac OS 或任何 Unix 系统上工作,你可以安装ffmpeg并使用以下命令来提取单个文件的持续时间:

ffmpeg -i filename.mp3 2>&1 | egrep "Duration" | cut -d ' ' -f 4 | sed s/,//
Run Code Online (Sandbox Code Playgroud)

例如,这将返回“00:08:17.4”。

当然,您可以在 shell 脚本中使用它,例如,这将列出文件夹中的所有 mp3 文件及其右侧的持续时间。

#!/bin/bash
# call me with mp3length.sh directory
# e.g. ./mp3length . 
# or ./mp3length my-mp3-collection

for file in $1/*.mp3
do
    echo -ne $file "\t"
    ffmpeg -i "$file" 2>&1 | egrep "Duration"| cut -d ' ' -f 4 | sed s/,//
done
Run Code Online (Sandbox Code Playgroud)

以下脚本以小时为单位返回持续时间:

#!/bin/bash
# call me with mp3length.sh directory
# e.g. ./mp3length .
# or ./mp3length my-mp3-collection


list-individual-times() {
    for file in $1/*.mp3
    do
        echo -ne $file "\t"
        ffmpeg -i "$file" 2>&1 | egrep "Duration"| cut -d ' ' -f 4 | sed s/,//
    done
}

TOTAL_HOURS=$(list-individual-times $1 | cut -f2 | xargs -I hhmmss date -u -d "jan 1 1970 hhmmss" +%s | awk '{s+=$1}END{print s/3600}')
echo "Total hours: ${TOTAL_HOURS}"
Run Code Online (Sandbox Code Playgroud)