Determining The Playtime In Seconds from an OGG Vorbis File

Problem

To determine the runtime in integer seconds (not including a fractional amount) of a given audio file in format OGG-Vorbis.

This value is required, for example, in the EXTM3U syntax.

Solution

1. Install package vorbis-tools

2. Define this shell function:

ogglength() {
    LANG=C ogginfo "$1" | perl -ne '
        BEGIN { $rv = 1; }
        /Playback length:\s(\d+)m:(\d+)\./ && do {
            print $1*60+$2, "\n";
            $rv = 0;
        };
        END { exit($rv); }
    '
}

3. Use the shell function:

 ~$ ogglength "My File.ogg"
153
 ~$