[Vorbis] splitting Ogg Vorbis file

Timur Elzhov elzhov at gmail.com
Tue Jun 23 13:13:33 PDT 2009


Hi there,

in fact, my purpose is to write tool which will allow one to split ogg
file with vorbis audio *and* theora video codecs, but at first I'd
like to understand how the splitting of Ogg Vorbis stream works. So I
looked at existing tools that split Ogg Vorbis audio files, i.e.
`vcut' utility in vorbis-tools package, and Ogg plugin from
`libmp3splt', but I found that engine code is pretty the same. The one
of the core functions of `vcut' source starts with the comment:

/* Write the first stream to output file until we get to the appropriate
 * cut point.
 *
 * We need to do the following:
 *   - Adjust the end of the stream to note the new end of stream.
 *   - Change the final granulepos to be the cutpoint value, so that we don't
 *     decode the extra data past this.
 *   - Save the final two packets in the stream to temporary buffers.
 *     These two packets then become the first two packets in the 2nd stream
 *     (we need two packets because of the overlap-add nature of vorbis).
      ...
 */

So my questions are: what does "overlap-add nature of vorbis" means?
Why should I copy even two last packets from first fragment of Vorbis
file to the second one? Why I can't finish first fragment with n-th
packet, and just start next fragment with new (n + 1)th packet? Say, I
don't want to break any vorbis packet,  don't want to cut vorbis file
at *exactly* e.g. 5000 samples, and breaking stream at nearest
packet's boundary is okay for me.

Much thanks in advance!

--
WBR,
Timur


More information about the Vorbis mailing list