[vorbis] Copy a part of an Ogg/Vorbis file

Frank Heckenbach frank at g-n-u.de
Sat Mar 17 18:21:32 PST 2001



Michael Smith wrote:

> At 05:59 PM 3/17/01 +0100, you wrote:
> >What I'd like to do is to copy a part of an Ogg/Vorbis file to a new
> >file, without decoding and re-encoding (say I've got several songs
> >in one long file, and I want to split them into separate files).
> >Sample granularity is not required, packet granularity should do.
> >
> >I'm reading the Ogg documentation. I think I could write some code
> >based on ogg_stream_packet{out,in}. Is this the way to go, or are
> >there easier ways? Or is there perhaps already existing code for
> >this purpose so I don't need to reinvent the wheel?
> >
> 
> I have almost-complete code for doing this at sample granularity.

That's possible without re-encoding? Or do you have to re-encode the
remaining parts of the packets that are cut?

> There are a couple of small bugs remaining, though. I should get
> back to it some time soon - haven't touched it for a couple of
> weeks. So, you could wait for that.
> 
> Alternatively, if you want to do it now, with only packet 
> granularity, then this is the basic approach (it's not quite as
> easy as it looks at first):
>   extract ogg pages from input file
>   extract ogg packets from page
>   write packets to first file until you reach the split-point
>   now, start the second file
>   write the last packet from the first file into the second file
>     (this is needed because of the overlap-add that happens - each
>      sample needs data from two packets).
>   write the rest of the packets to the second file, being sure to
>     calculate a correct granulepos for each packet (this is the
>     deceptively hard bit)

Oh yeah, I see the problem -- hadn't thought of it...

> If you don't really care about adding a few extra samples at the
> start and end of the output files, you can skip most of the 
> difficult bits and just give it close-enough info, but that's not 
> recommended.

I don't care much about adding a few extra samples, but I wouldn't
like to write (even slightly) incorrect header information.

Since it's not so urgent to me, I think I'll wait for your code.
Could you please drop me a note when it's ready (unless you'll
announce it on this list, anyway)?

Thanks,
Frank


-- 
Frank Heckenbach, frank at g-n-u.de
http://fjf.gnu.de/
PGP and GPG keys: http://fjf.gnu.de/plan

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.




More information about the Vorbis mailing list