[theora-dev] Theora packets with granulepos of -1
r.siegemund at digitalpublishing.de
Mon Feb 23 02:35:15 PST 2009
thanks for your reply. Well, I haven't take a look into your code yet because my algorithm to seek to a target frame works very similar and I'm also not so good at reading foreign code... at least I get a headache most times. ;)
I just want to understand every piece of code I need to do a seeking operation and if I read your method I see that I understand it right... but ok, I haven't verified the first frame if it's starting at 0 or 1, I thought this is specified exactly.
But also this time I'm confused again. In my current code I use the keyframe offset in the theora header to do some calculations related to the offsets of the keyframes or just for debugging. This offset does always work on all of my ogg theora files which are up to 90 seconds in length so there you get a keframe every 64th frame.
Recently I encoded another theora stream which has a length of about 4 minutes. And here I don't get a keyframe every 64th frame even if I name it in the ffmpeg2theora command line parameters. The keyframe distance varies as the oggzdump output shows:
00:00:31.333: serialno 0000005187, granulepos 430|40, packetno 472
00:00:31.400: serialno 0000005187, calc. gpos 471|0, packetno 473
00:00:34.266: serialno 0000005187, granulepos 471|43, packetno 516
00:00:34.333: serialno 0000005187, granulepos 515|0, packetno 517
It's very confusing to see that no one of my >100 older theora files have varying keyframe offsets but this one. (?)
So, uhm... another of my assumptions from earlier theora based development failed. This happened quite often last days so seeking seems to be THE way to really understand (or at least experience) what is really going on under the hood.
You were asking about seeking,
Seeking in ogg is not easy. Here is the method I devised, which seems
the most efficient:
1) Parse stream headers to get data. Some files have a first keyframe
of 0, others have a first keyframe of 1.
2) Begin reading pages until we get at least one packet. Then check
the granulepos to find the first keyframe number (0 or 1). Store this
as e.g. keyframe_offset.
3) To get a target frame, first search through the file to find the
largest granulepos<=target, taking into account the keyframe_offset.
More information about the theora-dev