[Vorbis-dev] How can I get the precise play time of the ogg vorbis file?

ogg.k.ogg.k at googlemail.com ogg.k.ogg.k at googlemail.com
Wed Apr 8 03:00:12 PDT 2009


> bitrate. Now, I want to get the play time of the file, so I use the file
> length to divide the nominal bitrate, and get the play time, but it is
> always shorter than the real time. So I want to know how to get the precise

Since the data is compressed, there will be less bits than for a raw
PCM stream with which such a method would work. There's the Ogg
encapsulation that you'd need to remove too anyway.
If you use libvorbisfile, there's an API to get the exact length.
If not, you need to get the granpos of the first packet, and that of
the last one, and substract, then scale by the sampling rate (not
the bitrate). I believe you'd have to add the number of samples
in the very first packet too, but I recall someone saying no, though
I did not understand the reason.

> By the way, why many files don't set the maximum bitrate and minimum
> bitrate?

I believe these are only set for managed mode, but I may be wrong.
In any case, those values are only indicative AFAIK.


More information about the Vorbis-dev mailing list