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

Conrad Parker conrad at metadecks.org
Wed Sep 26 06:03:33 PDT 2007

On 26/09/2007, Robin Siegemund <r.siegemund at digitalpublishing.de> wrote:
> Hello,
> > (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

Yes these steps are annoying. Worse, they are inexact as the
granulepos of the first data page in each bitstream refers to the
ending time of the last packet on that page. To get an exact duration,
the duration of these first packets needs to be calculated by
examining the data and added to the figure obtained in step 5 above.

Alternatively, the starting granulepos for each track is given in the
"basegranule" fields of Ogg Skeleton.

> because all ogg pages have to be parsed through the whole file (if I got it right?).

Not all pages need to be parsed; only the BOS and EOS pages need to be
found for each chain, and these can be found by binary search.

> 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.

Yes, or a Content-Duration header in Ogg Skeleton, similar to what
oggz-info prints out (or similar to these HTTP headers:
http://trac.annodex.net/wiki/HttpHeaders )



More information about the theora-dev mailing list