ofVideoPlayer getCurrentFrame

I’m trying to access the current frame number from a playing movie. I want to set an object position on the screen according to the frame number. I am using the quicktime API.
So far I have this :

void CMApp::update()  
	// We get the current frame  
	Media movieMedia = NULL;   
	Track videoTrack = GetMovieIndTrackType(  
				m_Movie.moviePtr, 1, 'vfrr',   
				movieTrackCharacteristic | movieTrackEnabledOnly);   
	if (videoTrack != NULL)  
		movieMedia = GetTrackMedia(videoTrack);   
		printf("error: failed to get media track");   
	long sampleNum;  
	TimeValue time;  
	MediaTimeToSampleNum(  	movieMedia,  
				GetMovieTime(m_Movie.moviePtr, nil),  
	// We update the object position according to the frame number  
	// ...  

This code doesn’t work for all my movie files. When it’s not working, MediaTimeToSampleNum always return 1. My .mov files are PCM encoded.

Perhaps there a better way to do this. I notice there will be a getCurrentFrame method in OpenFrameworks release 006. Is it possible to see how it’s gone work ?



yes you can totally check it out in the svn, either by checking out

svn co http://svn.openframeworks.cc/openFramew-…-rameworks/

or by browser:

looking in the code, I see we do it pretty simply:

int frame = 0;  
// zach I think this may fail on variable length frames...  
float pos = getPosition();  
float  framePosInFloat = (getTotalNumFrames() * getPosition());  
int    framePosInInt = (int)framePosInFloat;  
float  floatRemainder = (framePosInFloat - framePosInInt);  
if (floatRemainder > 0.5f) framePosInInt = framePosInInt + 1;  
//frame = (int)ceil((getTotalNumFrames() * getPosition()));  
frame = framePosInInt;  
return frame;  

maybe this helps?

take care!

Thank you for the quick reply!
This code is working well for a movie with a constant frame lenght.

frame = (int)ceil((getTotalNumFrames() * getPosition()));   
return frame;