[theora-dev] How to get the duration of a file or track?
Ralph Giles
giles at xiph.org
Mon Aug 27 11:05:30 PDT 2007
On Thu, Aug 23, 2007 at 07:13:17AM -0400, Ken Larson wrote:
> I'm starting with the theora player_example.c. I want to be able to
> determine the duration of the audio/video ahead of time, to be able to
> display it somewhere.
>
> I can't see anything obvious in ogg.h, theora.h, or vorbis.h for this.
It's a little complicated. First you bisection-search based on the ogg
page serial numbers to find all the chain segments. Then you read the
bos pages for each chain segment to identify the codecs and get their
granulepos mappings. Then you read the first and last data packets for
each stream in each chain segment and use those to calculate the
duration of each segment. The length of the ogg stream is the sum of the
durations of each segment.
> Can anyone help me with the right place to look to do this?
You might take a look at liboggplay; it's a convenience library that
does this for general streams, as well as general playback marshalling.
http://svn.annodex.net/liboggplay/trunk/include/oggplay/oggplay.h
HTH,
-r
More information about the theora-dev
mailing list