[theora] Seek problem 3 - Locating a keyframe

Bo Thorsen bo at thorsen-consulting.dk
Thu Apr 12 02:48:06 PDT 2007


Hi people,

Last problem is a simple API question.

The granulepos in Theora is a combination of keyframe number + frames since 
the last keyframe. This is nice for seeking to the last keyframe. But why 
isn't this available in the public API of libtheora? I had to include 
codec_internal.h (the name does suggest to me that this is bad) and code 
this:

ogg_int64_t framesSinceKeyframe(theora_state *th,ogg_int64_t granulepos) {
	CP_INSTANCE *cpi=(CP_INSTANCE *)(th->internal_encode);
	PB_INSTANCE *pbi=(PB_INSTANCE *)(th->internal_decode);
	if(cpi)
		pbi=&cpi->pb;
	if (granulepos>=0) {
		ogg_int64_t iframe = granulepos >> pbi->keyframe_granule_shift;
		return granulepos - (iframe << pbi->keyframe_granule_shift);
	}
	return(-1);
}

ogg_int64_t keyframeNumber(theora_state *th,ogg_int64_t granulepos) {
	CP_INSTANCE *cpi=(CP_INSTANCE *)(th->internal_encode);
	PB_INSTANCE *pbi=(PB_INSTANCE *)(th->internal_decode);
	if(cpi)
		pbi=&cpi->pb;
	if (granulepos>=0) {
		return granulepos >> pbi->keyframe_granule_shift;
	}
	return(-1);
}

It would have been nice if these were part of the library. Feel free to grab 
the code and include it, if you agree.

Bo Thorsen.

-- 

Thorsen Consulting ApS - Qt consulting services
http://www.thorsen-consulting.dk


More information about the theora mailing list