# Ogg stream length

## Recommended Posts

I've got a ogg/vorbis stream, i need to know how long it is (pcm duration). Does anyone know if this possible? I'm not opening a file, it's streaming from the internet, so I can't use the ov_* functions (unless I'm wrong), and I can't find anything in the headers that store this information. I guessed this would be something that is done frequently, but can't find any reference to this sort of stuff on the web. Cheers Rab

##### Share on other sites
You can determine the length of a track going by the data length, frequency and the format. I wrote these functions a while ago to find the length of a track.

ALuint oalGetSampleSize(ALenum format){  //defaults to 1, even if the format is invalid  ALuint sampleSize = 1;  switch (format){    case AL_FORMAT_STEREO16:      sampleSize *= 2;    case AL_FORMAT_MONO16:    case AL_FORMAT_STEREO8:      sampleSize *= 2;      break;  }  return sampleSize;}ALfloat oalGetTrackLength(ALuint dataLength,ALuint freq,ALenum format){  ALfloat trackLength = 0.0f;  if (freq != 0.0f){//avoid divide by zero    trackLength = dataLength / (ALfloat)(freq * oalGetSampleSize(format));  }  return trackLength;}

##### Share on other sites
Thanks for your reply Gorax - that's the best option i could think of, but I don't have the uncompressed data length - it's streaming from the internet and I'm not guaranteed that all the data is down yet :/

I was wanting to know if this information was available in the headers. I thought it might be simply because windows media player knows what length an mp3 is when it is being streamed - so i guess mp3 has it - just don't know if it exists in ogg, or where to get it from if it does.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627636
• Total Posts
2978319

• 10
• 12
• 22
• 13
• 33