check duration of audio files on the command-line

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

    mediainfo will return to you the milliseconds of an audio file. Assuming the current directory only has audio files, the following

    mediainfo --Inform="Audio;%Duration%" "Miley Cyrus - Wrecking Ball.mp3"
    

    To calculate the duration of all audio in the local directory, this gist will help:

    shopt -s nullglob
    let playlist_duration_ms=0
    for song_file in *.{mp3,ogg,m4a,flac,wav}; do
      playlist_duration_ms=$(expr $playlist_duration_ms + $(mediainfo --Inform="Audio;%Duration%" "$song_file"))
    done
    shopt -u nullglob
    
    let playlist_duration_secs=$(expr $playlist_duration_ms / 1000)
    let playlist_duration_mins=$(expr $playlist_duration_ms / 60000)
    let playlist_duration_remaining_secs=$(expr $playlist_duration_secs - $(expr $playlist_duration_mins \* 60))
    
    echo $playlist_duration_mins minutes, $playlist_duration_remaining_secs seconds
    
    0 讨论(0)
  • 2021-02-05 01:01
    soxi -D filename
    soxi -D *
    

    Soxi queries metadata of audio files; D is the duration option. It supports globbing. Soxi's big brother sox does command-line audio processing.

    0 讨论(0)
提交回复
热议问题