[ogg-dev] Decoding setup header

Conrad Parker conrad at metadecks.org
Fri Jul 17 18:23:21 PDT 2009


2009/7/18 Adam Rosi-Kessel <adam at rosi-kessel.org>:
> On Fri, Jul 17, 2009 at 12:48:27PM -0700, Ralph Giles wrote:
>> > In my ongoing quest to restore corrupted ogg files, I'm trying to find
>> > an easy way to identify the setup header without having to actually
>> > decode it. I understand that it starts with [packet_type] = 5 and then
>> > the string 'vorbis', but is there some way to figure out where it
>> > terminates without actually decoding the bits?
>> No. The first header is fixed length the second two are variable. It
>> should be immediately followed by a new page header though; if there's
>> no corruption you could try that.
>
> In other words, everything in between ^Evorbis and OggS is the setup
> header?

no, you can't just rip the bytes out because the setup header may be
split across two pages.

eg. looking at the start of the stream with "hogg pagedump":

conrad at chichai:~/share/484$ hogg pagedump unfixed_corrupted.ogg |head -n 12
0x00000000: Vorbis serialno 1225743615, granulepos 0|0 *** bos: 58 bytes
        [30] 00:00:00.000

0x0000003a: Vorbis serialno 1225743615, granulepos 0|0 (incplt): 53525 bytes
        [49719,3570] 00:00:00.000

0x0000d1c0: Vorbis serialno 1225743615, granulepos 0|0 (cont): 1421 bytes
        [1388] 00:00:00.000

0x0000d74d: Vorbis serialno 1225743615, granulepos 21056|0 (incplt): 4261 bytes
        [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,448,517,534,536,543,546,548,510]
00:00:00.477


Here:

1. the first page contains only the BOS packet of 30 bytes.

2. The second page (at 0x3a) contains two segments:
    * one complete page of 49719 bytes (the vorbiscomments, including
coverart hence the large size).
    * 3570 bytes of the start of the setup header.
This page is marked (incplt) here because the last segment is
incomplete, ie. not a complete packet.

3. The third page is marked (cont) because it contains data that
continues a previous packet.
Specifically it contains only one segment, the last 1388 bytes of the
setup header.

So to extract the setup header you need to get the two segments of
3570 and 1388 bytes. If you're looking at the raw bytestream, there is
an OggS page header in between those two segments.

If you replace the setup header you need to rewrite the second page as
its checksum will change.

Conrad.


More information about the ogg-dev mailing list