[Vorbis] How do I seek to seek to specific samples using libvorbis?

Madison Link ducks at ducksnm.com
Tue May 19 09:00:23 PDT 2015


Right, but do I start from the beginning of the page?  Do I start from the
end of the previous page?  Is there some way to reliably start at a packet
immediately before the one I want (and to know which sample I'm starting at
once I get sound out.)

 

Here's my goal, setup, and the problems I'm having.

 

I want to grab the audio and video out of a file in bite-sized chunks I'm
calling "frames."  If a file has video, one audio frame should be the audio
that goes with one video frame.  Otherwise, each audio frame is 1/25th of a
second.  I want to be able to seek into the middle of a file and return the
Nth frame of audio and video.  Specifically, If I grab the audio frames in a
random order, I want to be able to assemble them into the correct and
complete audio, so the start of each frame has to be exact.

 

When opening the file, I read though the packets, getting their block sizes,
translating that to samples (including the fact that I don't get any samples
on the first packet, and that after that the samples returned seem to be the
average of the packet size and the packet before it) and creating an index
point every 1/10th of a second.  The index contains the file position of the
page the packet is on, the number of the packet on the page that contains
the indexed sample, and the sample count up to the beginning of the packet.
When I want to seek to a frame, I get the index point before it, reset the
decoder, and read off packets, using the block size to calculate my way
forward until I'm at packet that begins the frame.  I store a few packets at
a time so that I can decode the two packets prior to the frame before
beginning the frame.

 

In practice, though, sometimes I'll get "OV not audio" when I put in an
audio packet that is in the middle of an audio page, or I'll put in a packet
that was originally sized as 2048 floats and I'll get back information that
its 256 floats.  This throws off my calculations and I'll end up in the
middle of a frame instead of at the beginning.  I'm willing to believe that
there's a bug in the way I'm grabbing packets, except for the fact that when
I decode straight through, every thing works.  Also, my code never
misidentifies packets after I start decoding, only when I'm reading and
bypassing.

 

Other times, the "frame" I get out after seeking bears no relationship to
the one I get when I make a straight-through decode.  I've compared files
created by reading straight through an ogg file vs. seeking every frame, and
compared them with a hex editor.  In some places, the pcm samples match
perfectly, and are in the same position.  In other places, the pcm samples
match, but are offset, and in other places the pcm samples from the seek
file simply don't match those from the read file.  I've spent a couple of
weeks now on this specific part of the problem, and would like some
official, "here's how you do it."  Quite frankly, I'm surprised that this
aspect of vorbis decoding (seeking to a specific point in the file) is not
explained anywhere in the xiph documentation.  Maybe I missed it?

 

Again, some help would be appreciated.

 

Thanks, 

 

Madison

 

 

 

  _____  

From: Sergei Steshenko [mailto:sergstesh at yahoo.com] 
Sent: Monday, May 18, 2015 8:57 PM
To: Madison Link; vorbis at xiph.org
Subject: Re: [Vorbis] How do I seek to seek to specific samples using
libvorbis?

 

I am no Vorbis developer, and I have never looked into the details of
Ogg-Vorbis implementation, but since Ogg-Vorbis is a lossy format, there is
no one to one correspondence of PCM samples and bytes in the stream.
Ogg-Vorbis is also a variable bitrate format.







I mean that first the stream has to be reconstituted into uncompressed PCM
samples, and only then you can get to the desired sample.

 

Regards,

  Sergei.

 


  _____  


From: Madison Link <ducks at ducksnm.com>
To: vorbis at xiph.org 
Sent: Tuesday, May 19, 2015 3:38 AM
Subject: [Vorbis] How do I seek to seek to specific samples using libvorbis?

 

What is the best practice for seeking to a specific (arbitrary) PCM sample
in an Ogg file that contains vorbis, using libvorbis?


_______________________________________________
Vorbis mailing list
Vorbis at xiph.org
http://lists.xiph.org/mailman/listinfo/vorbis



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/vorbis/attachments/20150519/fe7c6a58/attachment-0001.htm 


More information about the Vorbis mailing list