[ogg-dev] Finding out the duration of an Ogg stream

Ralph Giles giles at xiph.org
Fri Jun 6 14:28:03 PDT 2008

\On 6-Jun-08, at 1:21 PM, Jon Kristensen wrote:

> Do you know a way that I could get around this somehow? Maybe some  
> header data that I have missed?

No, you didn't miss anything. Ogg is designed to always be  
streamable, so the only way to get the duration is to look at the end  
of the stream.

> If not, what is the easiest way to check the numbers of samples?

It's a bit tedious. If you know it's a static (or at least fixed  
length) file you're pulling, e.g. from the Content-Length header, you  
can do a Range request for the last 4k or so, try to parse it for the  
timestemp (and keep backing up if you don't find it). If the serialno  
fields match, you're done, just subtract the timestamp of the first  
packet from that of the last. If not, the file is several different  
stream concatenated together, so you have to bisection search for  
where the serial numbers change and add up the individual durations.

Might help to look at the code in vorbisfile.c and liboggz for this.

Annodex folks, is a Content-Duration something we should define in  


More information about the ogg-dev mailing list