Help - Search - Members - Calendar
Full Version: Ogg vorbis length
Hydrogenaudio Forums > Lossy Audio Compression > Ogg Vorbis > Ogg Vorbis - Tech
stigc
How do i get the length of an Ogg vorbis file when loaded from http? I see that VLC does it.
HotshotGG
QUOTE
How do I get the length of an Ogg vorbis file when loaded from http? I see that VLC does it.


That depends if it's a realtime stream from a server it might not be possible. If there are seperate files on a server, then if you click on properties like with FB2K it will show you the length in bytes.
stigc
It is a physical file on the server. I want to determine the play length in seconds. VLC player does this as soon as it starts playing.
kjoonlee
I think the most sensible thing to do would be to look at how VLC does it by looking at the source, or asking on the VLC mailing lists or the vorbis-dev@xiph.org mailing list.
[JAZ]
QUOTE(kjoonlee @ Feb 5 2006, 12:52 PM)
I think the most sensible thing to do would be to look at how VLC does it by looking at the source, or asking on the VLC mailing lists or the vorbis-dev@xiph.org mailing list.
*



I assume (since it is what winamp does for mp3's at least), that it is just asking the server the filesize. This can be done, because the protocol used is http, and just like you see the size when downloading a file from internet, a player can do so aswell.

Then, assuming you can get the info from the header of the file that tells its bitrate, you can do simple maths to get it (i'm not sure, but i believe that the average bitrate (for VBR files) is also present in ogg files)
kjoonlee
You need to know both the filesize and the average bitrate to calculate playtime.

edit: Oops. Never mind.
stigc
Yes i found out. I did my own implementation which uses the file size (http content length) and nominal bitrate. This is not very precis, but i get the same results as VLC.

Odd that the Ogg headers doesnt provide the actual bitrate. The only way to get this is to seek through the whole file. Maybe I'm missing something?
SebastianG
QUOTE(stigc @ Feb 5 2006, 04:11 PM)
Odd that the Ogg headers doesnt provide the actual bitrate.
*


Actually this is intentional.
QUOTE(stigc @ Feb 5 2006, 04:11 PM)
The only way to get this is to seek through the whole file. Maybe I'm missing something?
*


No, you just have to load the final Ogg page and look for the "granule position" entry. It tells you exactly the length in samples of the stream.

Sebi
stigc
Hi SebastianG

Always nice to get help from you. I took a look at granule position which is pretty fast. Now i can determine the correct length of the songs even over a http request. I guess that there does not exists the same thing for the actual bitrate? Here i have to seek through all pages or what?

I'm thinking about making a guess, based on the file length together with the play length and an Ogg overhead factor. How does this sound?

I'm using Java so a fast algorithm is very important.

http://www-user.tu-chemnitz.de/~noe/Video-...e_overhead.html
SebastianG
Hi stigc!
QUOTE(stigc @ Feb 6 2006, 03:29 PM)
[...] Now i can determine the correct length of the songs even over a http request. I guess that there does not exists the same thing for the actual bitrate? Here i have to seek through all pages or what? [...]
*


duration in seconds * bits per second = filesize in bits
simply solve for "bits per second"

QUOTE(stigc @ Feb 6 2006, 03:29 PM)
[...] I'm thinking about making a guess, based on the file length together with the play length and an Ogg overhead factor. How does this sound? [...]
*


It depends on what bitrate you want to calculate. Either including the ogg container or only the raw Vorbis stream data. Commonly nobody cares about the bitrate of the raw Vorbis stream. The bitrate tells you how many bits (average) are needed to represent a signal. Since Vorbis is usually encapsulated in an ogg container (You can't decode a raw Vorbis stream like mp3 because Vorbis itself doesn't use any frame syncing) I'd be more interested in the overall bitrate (including ogg container). If you stream an ogg file over http the whole file is transmitted -- not just the raw Vorbis stream.

Sebi
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.