Click here to Skip to main content
11,923,046 members (62,748 online)
Rate this:
Please Sign up or sign in to vote.
I am trying to get the Average time per frame of the video using DirectShow in vc++.
And am using the IBasicVideo interface to get that value,it is having the get_AvgTimePerFrame function. But am not getting any value from it.
hr = pGraph->QueryInterface(IID_IBasicVideo,(void **)&pVideo);
hr = InitWindowlessVMR(AfxGetMainWnd()->m_hWnd, pGraph, &pWc);
// Build the graph. 
hr = pGraph->RenderFile(L"Video.mp4", NULL);
double df;
If i call the get_AvgTimePerFrame function after the pGraph->RenderFile("video.mp4",NULL) function am getting the value. If i specify the filter formation am getting the return value as E_NOINTERFACE.
What i need to do to get the value of the average time per frame?

Thaking you in advance.
Posted 14-Mar-13 20:46pm
Edited 15-Mar-13 5:00am
J.Surjith Kumar 15-Mar-13 4:30am
I am explicitly configure the VMR for the windowless mode so am not getting the Average time per frame. How to solve this?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You should get connected media type of your renderer and get information from VIDEOINFOHEADER structure.

double GetFPS(IBaseFilter * _filter)
    double _fps = 0;
    if (_filter) // Check if the filter passed
        IEnumPins * _enum;
        // Query Enum pins
        if (S_OK == _filter->EnumPins(&_enum))
            IPin * _pin;
            // While we have pins or fps not setted yet
            while (_fps == 0 && _enum->Next(1,&_pin,NULL) == S_OK)
                PIN_DIRECTION _direction;
                // Here we check for pin direction
                // Assume that we pass the renderer filter as argument
                // But checking direction not mandatory
                if (_direction == PINDIR_INPUT)
                    AM_MEDIA_TYPE mt;
                    // We try to retrieve connection media type
                    // In case if connected it returns type and S_OK result
                    if (S_OK == _pin->ConnectionMediaType(&mt))
                        // We have video type and have format
                        // At least format shoudl be size of VIDEOINFOHEADER structure
                        // As all other well known format structures are higher size
                        if (mt.majortype == MEDIATYPE_Video 
                            && mt.pbFormat 
                            && mt.cbFormat >= sizeof(VIDEOINFOHEADER))
                            // We cast directly here without checking format type
                            // This possible because we had check the size and we need
                            // only "AvgTimePerFrame" field
                            // NOTE: do not do this for bmiHeader field
                            REFERENCE_TIME _time = ((VIDEOINFOHEADER*)mt.pbFormat)->AvgTimePerFrame;
                            if (_time > 0)
                                // Calculate fps = second / time per frame
                                _fps = ((double)UNITS / (double)(_time));
                        // Free format block
                // Release pin
            // Release enum
    return _fps;
J.Surjith Kumar 15-Mar-13 8:34am
Thank You Maxim I got the value:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151125.3 | Last Updated 15 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100