check duration of audio files on the command-line

后端 未结 14 912
没有蜡笔的小新
没有蜡笔的小新 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:46

    A solution based on mplayer from commandlinefu by syssyphus that works with both audio and video files:

    sudo apt-get install mplayer
    find -type f -name "*.mp3" -print0 | xargs -0 mplayer -vo dummy -ao dummy -identify 2>/dev/null | perl -nle '/ID_LENGTH=([0-9\.]+)/ && ($t +=$1) && printf "%02d:%02d:%02d\n",$t/3600,$t/60%60,$t%60' | tail -n 1
    

    Get the total length of all video / audio in the current dir (and below) in H:m:s

    Change the *.mp3 to whatever you want to match (e.g., *.avi, *.wav), you can remove it altogether if you want to check all files.

    Example of output: 00:00:37

提交回复
热议问题