AW: [Vorbis] Howto get playtime

Thomas Kuglitsch tkuglits at edu.uni-klu.ac.at
Thu May 11 01:07:17 PDT 2006


OK. I've found how to get the playtime when I use ogg and 
vorbis resp. ogg and theora in the same c-file (like in 
exampleplayer of libtheora).
I have the problem that I am developing in a project, where 
demuxing of logical streams of an ogg container happens in 
another c++ object than decoding.
but at the time of demuxing i have to know the playback time. 
the demuxed streams will be decoded later on, so the 
dsp-state is not available at the time of demuxing.

I don't get vorbis & theora synchronized :( somehow my 
playtime calculations go wrong.

for vorbis i use:
if(ogg_packet->granulepos >= 0)
{
	playtime = ogg_packet->granulepos / vorbis_info->rate;
	oldplaytime = playtime;
}
else
	playtime = oldplaytime;

for theora i use (parts taken from libtheora):
if(ogg_packet->granulepos >= 0)
{
	shift = theora_granule_shift(theora_info);
	iframe = ogg_packet->granulepos >> shift;
	pframe = ogg_packet->granulepos - (iframe << shift);
	frameno = iframe + pframe;
	playtime = frameno / (fps_numerator/fps_denominator);
	oldplaytime = playtime;
}
else
	playtime = oldplaytime

what am I doing wrong? it SHOULD be nearly synchronized.
 

> -----Ursprüngliche Nachricht-----
> Von: Ralph Giles [mailto:giles at xiph.org] 
> Gesendet: Donnerstag, 04. Mai 2006 17:41
> An: Thomas Kuglitsch
> Cc: vorbis at xiph.org
> Betreff: Re: [Vorbis] Howto get playtime
> 
> On Thu, May 04, 2006 at 03:29:04PM +0200, Thomas Kuglitsch wrote:
> 
> > Searched in Google, browsed xiph vorbis sites but found no good 
> > information about how to get the current playtime out of the 
> > granuleposition of the ogg_packet.
> 
> If you have a configured vorbis_dsp_state for the packet you can use
> vorbis_granule_time() declared in vorbis/codec.h.
> 
> You can also get an approximate value by just dividing by the 
> sample rate given in the info header; but this will not be 
> exact for some streams. Also keep in mind that streams can 
> have holes in them, especially at the beginning, so you may 
> want to take that into account if you're displaying this to a user.
> 
> > Anyone knows if there is any 'Programming with libvorbis' 
> > documentation out there, cause on xiph's site 
> > (http://www.xiph.org/vorbis/doc/) there's nothing :(
> 
> Yes, this is a very unfortunate ommission. :(
> 
>  -r
> 



More information about the Vorbis mailing list