[Vorbis-dev] Total uncompressed size
Christopher Egner
disciplezero-nl at syrrax.com
Thu Sep 1 09:17:27 PDT 2005
Michael Smith wrote:
>However, to figure out the total length you certainly don't need to
>decode the entire file. You need to read the vorbis headers, and then
>seek to the end of the file (if it's a single chain; if you have
>multiple logical streams chained together, it's a little more complex
>- see the ogg docs if my terminology here is confusing). The
>granulepos value of the final ogg page of the stream will give you the
>total number of samples in the file, you can then multiply that by the
>number of channels (which you got from the header), and by the sample
>size you're decoding to (which is your choice, typically you'd pick 16
>bit data, which is 2 bytes per channel per sample).
>
>
For a single ogg file, wouldn't you store the length, for playlist
loading, so you don't have to do things like this to determine the
length. I guess even the length is an approximation though (since it
would be specified in terms of minutes and seconds generally), but you
could take that, multiply the total number of seconds by the sample
rate, by the number of channels, by the width of each sample. So for my
applications, most things are 44.1 kHz, 16 bit samples, 2 channels. So a
3 minute song is 180 seconds * 44100 samples/second * 2 channels * 2
bytes/sample = 31752000 bytes or just over 30 megs. Again, let me
emphasize, this is only an approximation (if ogg or vorbis even have a
comment/meta field storing this information). Also the savings are
probably negligable for a small app with small files. If the files are
large however, and static, the savings may be worthwhile. If you've got
a chained file, as before, this mess gets more complicated. Also note,
that if you're trying to compute how much space you need to store a wave
or something similar, you almost always need a header.
Christopher
More information about the Vorbis-dev
mailing list