[theora-dev] further debugging of my ogg/theora decoder

Conrad Parker conrad at metadecks.org
Thu Nov 13 02:37:19 PST 2008

2008/11/13 salsaman <salsaman at gmail.com>:
> Actually I have now realised it`s not that complicated, as you say, just
> counting frames and not caring about keyframes at all is the way to go.
> My search runs in 2 passes:
> pass 1, find largest gpos <= target - this gives us keyframe for target
> (note that a granulepos with k<= target, f>=target is also acceptable)
> pass 2, calculate gpos from kframe, search for largest gpos < this
> then starting from that page:
>  - ignore any packets on that page
>  - count frames starting from the following page

To clarify what you mean by "ignore" and "frames starting from the
following page":

If you are always feeding these pages into ogg_stream_pagein(), and
always running ogg_stream_packetout() on them, then this should be
correct. In this case, "ignoring any packets on that page" means that
you retrieve all of the completed packets from that page with
ogg_stream_packetout(), but discard them. You then load the next page
with ogg_stream_pagein(). "Count frames starting from the following
page" means that you start counting from the next packet that is
returned by ogg_stream_packetout().

>  - when we reach a page which produces (target -1), we know that is where
> kframe starts, so store that page offset (this is useful for playing
> backwards...)

probably, but not guaranteed. As you're pulling packets out of the
stream anyway then you might as well just call
theora_packet_iskeyframe() which is cheap and will definitely give you
the correct info.

> - decode the next packet : this is our target frame
> Does that look correct ?

Yes, as long as you are pushing all those pages into ogg_stream_pagein().


More information about the theora-dev mailing list