AW: [theora-dev] How to get the duration of a file or track?

Robin Siegemund r.siegemund at
Wed Sep 26 03:57:49 PDT 2007


> (1) Split the content into chain segments 
> (2) extract the first and last data packet from each segment, for all tracks
> (3) recover / calculate the granulepos values for the first and last data packets (*)
> (4) convert the granulepos values from the first and last data packets into time values 
> (5) take the largest difference between start and end time as the total chain segment time
> (6) sum the chain segment times to create the total content length

those steps to determine the duration of ogg/theora streams are really annoying because all ogg pages have to be parsed through the whole file (if I got it right?).
This takes an extra amount of time but there are applications where you simply can't afford any further delays so the the video/audio has to start immediately. Not to mention playback from CD-ROM in combination with seeking abilities.

Why there's no simple duration entry in the bos page of every stream set by the ogg encoder specified? Ok, in case of a real streams which doesn't have a defined length (live recording) the entry is just left empty. But in all the other cases you convert an already existing file container (like AVI or MOV where the length is known) to ogg.

Currently I would tend to write an ogg/theora encoder which adds an duration value to the comment block so its easy ascertainable by the decoder.


More information about the theora-dev mailing list