VorbisStreamLength

From XiphWiki
Revision as of 08:24, 27 February 2007 by Saoshyant (talk | contribs) (this page just got rescued from web.archive, please format it)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Notes on finding the total time of a vorbis stream:

  • Sum of the lengths of the logical bitstreams in the file
  • Individual logical stream length is given by:

(double) ((vf->pcmlengths[i * 2 + 1]) / vf->vi[i].rate)

(from vorbisfile.c, ov_time_total(), line 938)

     where:
 
     vf 	OggVorbis_File
     vi 	array of vorbis_info with one per logical stream
     i 	logical stream number
     pcmlengths 	array containing beginning and end pcm length for the logical stream
     vorbis_info::rate 	sample rate in Hz


  • The PCM value for a Vorbis packet in an Ogg stream is given by the "Absolute Granule Position" in the Ogg page header. See the Vorbis standard section A.2 on embedding a Vorbis stream in an Ogg stream for more.
  • As such the total time for a physical stream may be found by determining the number of logical streams in the physical stream and computing the length for each and summing these. To do so first checking for the presense of a single logical stream is possible(+) by examining the first and last Ogg page of the physical stream.

After determining the number of streams each stream's length may be determined by reading the absolute granule position from the Ogg page header for the first and last Ogg page in the logical stream, taking the difference and dividing by the audio sample rate as read from the Vorbis identification header (located in the first Ogg page of the logical stream).

(+) This assumes a "degenerate" or non-multiplexed vorbis stream.