Mathias Kunter
2008-Mar-18 04:11 UTC
[Vorbis-dev] Determining the duration of an ogg vorbis file
Hi all, I've got a question on regarding how to find out the duration of an ogg vorbis file. Sorry if it should already be mentioned somewhere in the docs, but I couldn't find out how to do it the best way. So, I can read the [bitrate_nominal] field from the identification header (if it is set), find out the size of the audio data (by subtracting the size of the three headers from the length of the file stream), and get the duration of the file with duration = audio size / nominal bitrate. However, is this the right way to go? What can I do if the nominal bitrate is unset in the identification header? Any help is highly appreciated. Thank you very much, Mathias K. Lesen Sie Ihre E-Mails jetzt einfach von unterwegs. www.yahoo.de/go
Conrad Parker
2008-Mar-20 01:36 UTC
[Vorbis-dev] Determining the duration of an ogg vorbis file
On 18/03/2008, Mathias Kunter <mathiaskunter@yahoo.de> wrote:> Hi all, > > I've got a question on regarding how to find out the duration of an ogg vorbis file. Sorry if it should already be mentioned somewhere in the docs, but I couldn't find out how to do it the best way. > > So, I can read the [bitrate_nominal] field from the identification header (if it is set), find out the size of the audio data (by subtracting the size of the three headers from the length of the file stream), and get the duration of the file with duration = audio size / nominal bitrate. > > However, is this the right way to go? What can I do if the nominal bitrate is unset in the identification header?The granulpos field of the last page in the vorbis stream should tell you the duration in samples, divide it by the samplerate to get the duration in seconds. cheers, Conrad.
xiphmont@xiph.org
2008-Mar-20 04:51 UTC
[Vorbis-dev] Determining the duration of an ogg vorbis file
On Thu, Mar 20, 2008 at 4:34 AM, Conrad Parker <conrad@metadecks.org> wrote:> The granulpos field of the last page in the vorbis stream should tell > you the duration in samples, divide it by the samplerate to get the > duration in seconds....that tells you the end time. In the event that the beginning time is at a positive offset (like in a typical live stream) you also need to subtract the starting time (granpos on the first audio page) Monty