[theora] Seek problem 1 - can't find frame number
Bo Thorsen
bo at thorsen-consulting.dk
Tue Apr 3 04:33:59 PDT 2007
Hi people,
I'm writing a decoder that uses libtheora on Windows and Linux. Decoding works
well by now.
I have a couple of problems with it, that I just can't seem to figure out.
I'll write each of them in a single mail, so it's easier to answer individual
problems.
The first problem I have is seeking, when it's playing files. I have
implemented a weighted binary jump algorithm, that searches for a frame just
before the one we want to hit. Then it figures out the keyframe before this
one, and jumps back to somewhere just before this keyframe.
The jumping algorithm works quite well. It usually takes only about 4 jumps to
find a frame that is acceptable (which means it's before the wanted frame,
but not too much). But unfortunately I have have a lot of problems figuring
out the frame number after each jump.
When the decoder is correctly initialized, I can get the frame number by
calling theora_granule_frame(theora_state *,ogg_int64_t). But what do I have
to do while doing the jumps to find this?
This is what the code currently does just after seeking to a new place in the
file:
// Clear the current ogg buffers, find a new page, and fill the buffers again
int result;
ogg_sync_reset(&sync);
while ((result = ogg_sync_pageseek(&sync, &page)) <= 0)
if (result == 0)
bufferData();
// Find the next theora page
while ((result = ogg_sync_pageout(&sync, &page)) == 0)
bufferData();
while (ogg_page_serialno(&page) != tstream.serialno)
if (ogg_sync_pageout(&sync, &page) <= 0)
bufferData();
const ogg_int64_t actualFrame =
theora_granule_frame(&decoder, ogg_page_granulepos(&page));
With some files, this code works fine. But with others, the framenumbers I get
at the end have absolutely no resemblance to actual framenumbers. Sometimes
they are even an order of magnitude off.
Do I have to reinitialize the decode after each jump, just to be able to find
the frame number? Or should I instead read the bytes in the file and find the
granulepos this way?
Most of the example files I use are those creative commons files that can be
found on xiph.org.
Any help would be really appreciated.
Sincerely,
Bo Thorsen.
--
Thorsen Consulting ApS - Qt consulting services
http://www.thorsen-consulting.dk
More information about the theora
mailing list