开发者

Direct Show graph - how to get the current fps?

I have an instance of IFilterGraph - my own graph with video filters (source, transofrm and renderer). How can I obtain the current fps开发者_如何学Python (video frame rate) of running graph?

Regards Dominik


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.


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;
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜