Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC directshow VC++
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;
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 14-Mar-13 20:46pm
Edited 15-Mar-13 5:00am
v5
Comments
J.Surjith Kumar at 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
good
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
                _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.
  Permalink  
Comments
J.Surjith Kumar at 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
0 OriginalGriff 436
1 Maciej Los 249
2 BillWoodruff 199
3 /\jmot 180
4 Suraj Sahoo | Coding Passion 170
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 15 Mar 2013
Copyright © CodeProject, 1999-2014
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