check duration of audio files on the command-line

后端 未结 14 916
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 00:13

I need to check the duration of a group of audio files. Is there a simple way to do this on the unix command-line?

> duration *

I have the a

14条回答
  •  盖世英雄少女心
    2021-02-05 00:47

    In addition to cdosborn's answer, to calculate the length of all .mp3 files recursively in subfolders of current directory and show the total sum result in days:hours:minutes:seconds format:

    In zsh:

    afinfo **/*.mp3 | awk '/estimated duration/ { print $3 }' | paste -sd+ - | bc | awk '{printf("%d:%02d:%02d:%02d\n",($1/60/60/24),($1/60/60%24),($1/60%60),($1%60))}'
    

    In bash or sh:

    find . -name "*.mp3" -exec afinfo {} \; | awk '/estimated duration/ { print $3 }' | paste -sd+ - | bc | awk '{printf("%d:%02d:%02d:%02d\n",($1/60/60/24),($1/60/60%24),($1/60%60),($1%60))}'
    

    The result is like this (7 days, 5 hours, 6 minutes, 58 seconds):

    $ afinfo **/*.mp3 | awk '/estimated duration/ { print $3 }' | paste -sd+ - | bc | awk '{printf("%d:%02d:%02d:%02d\n",($1/60/60/24),($1/60/60%24),($1/60%60),($1%60))}'
    7:05:06:58
    $
    

提交回复
热议问题