Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
C++
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;
hr=pVideo->get_AvgTimePerFrame(&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
Updated 15-Mar-13 4:00am
v5
Comments
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

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

C++
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
                _pin->QueryDirection(&_direction);
                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
                        FreeMediaType(mt);
                    }
                }
                // Release pin
                _pin->Release();
            }
            // Release enum
            _enum->Release();
        }
    }
    return _fps;
}

Maxim.
 
Share this answer
 
Comments
J.Surjith Kumar 15-Mar-13 8:34am    
Thank You Maxim I got the value:)
Vahagn Gevorgyan 17-Aug-17 10:01am    
Sometimes this method provides wrong FPS. Is there another way to get it?
Maxim Kartavenkov 17-Aug-17 11:32am    
From application you can use IQualProp Interface and get_AvgFrameRate method query this interface from video renderer
https://msdn.microsoft.com/en-us/library/windows/desktop/dd376916(v=vs.85).aspx

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900