[Vorbis-dev] copying an ogg stream

Ralph Giles giles at xiph.org
Wed Sep 22 09:18:16 PDT 2004


On Wed, Sep 22, 2004 at 05:41:56PM +0200, Christoph Rupp wrote:

> reading the ogg file is ok (ogg_sync_pageout, ogg_stream_pagein, 
> ogg_stream_packetout). but writing the file doesn't work - the 
> granulepos and page structures don't match with the original file.

That's because you're changing them. :)

> then i write all pages but the last one to the output file (because, as 
> i understand it, only the last packet has the correct granulepos; all 
> other packets have a granulepos of -1).

This is incorrect. Only the header packets have a granulepos of -1, and 
pages that no packet ends on. That's at least part of the problem. I'm 
not sure what's up with the ordering issues.

>   foreach packet in list[:-1]:   # does NOT include the last packet!
>     packet.granulepos=-1
>     packet.packetno=global_packetno++
>     write_packet(packet)

Note that do to this correctly, you need to infer the granulepos of each 
packet and set that, so repagination is still accurate. The Ogg stream 
only stores the granulepos once per page, but you can always count up 
from the previous page by parsing enough of the packets to get their 
decoded length. This is the only way to accurately adjust the 
granulepos.

Note that Arc wrote a serial number changer in python. I expect it's in 
svn somewhere; check google for references. That only does half of want 
you want though, but it's much simpler since you can just copy pages.

Hope that helps some,
 -r



More information about the Vorbis-dev mailing list