[Vorbis-dev] Finding the size of a vorbis stream

Ralph Giles giles at xiph.org
Thu Mar 22 23:10:06 PDT 2007


On Thu, Mar 22, 2007 at 08:18:41PM -0600, Trent Gamblin wrote:

> [...] So my question is, is there any way to find the
> size of the resulting PCM data before decoding all of it?

If you're using libvorbisfile (or a java equivalent, I guess) you can 
just call ov_pcm_total and multiply by the number of channels and the
number of bytes per channel (2 and 2 for most files)
 
http://xiph.org/vorbis/doc/vorbisfile/ov_pcm_total.html

If not, you can try and port the code. In rough, you read the granulepos 
of the first and last pages. Subtract the two and that's the number of 
samples (modulo chaining, holes, and files with lead-in).

HTH,
 -r



More information about the Vorbis-dev mailing list