[Vorbis-dev] Determining the duration of an ogg vorbis file

Conrad Parker conrad at metadecks.org
Thu Mar 20 01:34:38 PDT 2008


On 18/03/2008, Mathias Kunter <mathiaskunter at yahoo.de> wrote:
> Hi all,
>
>  I've got a question on regarding how to find out the duration of an ogg vorbis file. Sorry if it should already be mentioned somewhere in the docs, but I couldn't find out how to do it the best way.
>
>  So, I can read the [bitrate_nominal] field from the identification header (if it is set), find out the size of the audio data (by subtracting the size of the three headers from the length of the file stream), and get the duration of the file with duration = audio size / nominal bitrate.
>
>  However, is this the right way to go? What can I do if the nominal bitrate is unset in the identification header?

The granulpos field of the last page in the vorbis stream should tell
you the duration in samples, divide it by the samplerate to get the
duration in seconds.

cheers,

Conrad.


More information about the Vorbis-dev mailing list