views:

58

answers:

3

Hello

I have an instance of IFilterGraph - my own graph with video filters (source, transofrm and renderer). How can I obtain the current fps (video frame rate) of running graph?

Regards Dominik

+1  A: 

Probably the easiest way is to create a SampleGrabber filter with a custom callback, and calculate it yourself.

See:

ISampleGrabber

ISampleGrabber::SetCallback

ISampleGrabberCB

Each time your callback function is called, you have received a new frame. You probably should put this just before the renderer.

Also, depending on your graph, some filter could have information about frame rate, but the SampleGrabber method would work with any graph.

Jaime Pardos
+1  A: 

Not every video has a constant FPS, so using sample grabber is the most accurate method although not the easiest. If you know format of your video and you are sure it's one having constant FPS, you can get your transform or renderer filter, get one of its pins, call IPin::ConnectionMediaType, look at media type's format type whether it's FORMAT_VideoInfo or FORMAT_VideoInfo2, cast format pointer to VIDEOINFOHEADER or VIDEOINFOHEADER2 accordingly and look at AvgTimePerFrame field.

Dee Mon
A: 

I hope this helps. It's a routine I wrote many moons ago to get the FPS of the video I was streaming. Works for various media types, but you should be able to figure out how to support further media types with this if you need to. See the MSDN page on AM_MEDIA_TYPE for more information.

inline static void GetVideoFramesPerSecond( const AM_MEDIA_TYPE * pVT, long *plFramesPerSecond )
{
long nTenMillion    = 10000000;
long lAvgFrameDuration  = 0;

if( pVT->formattype == FORMAT_VideoInfo || pVT->formattype == FORMAT_MPEGVideo )    
    lAvgFrameDuration = (LONG) ((VIDEOINFOHEADER *)(pVT->pbFormat))->AvgTimePerFrame;

else if( pVT->formattype == FORMAT_VideoInfo2 || pVT->formattype == FORMAT_MPEG2_VIDEO )    
    lAvgFrameDuration = (LONG) ((VIDEOINFOHEADER2 *)(pVT->pbFormat))->AvgTimePerFrame;

*plFramesPerSecond = ( lAvgFrameDuration != 0 ) ? ((long)( nTenMillion / lAvgFrameDuration )) : 0;
}
freefallr