How to set frame rate in webcam using direct show

שאלה How to set frame rate in webcam using direct show

  • Samstag, 3. März 2012 13:15
     
     

    Hi,

    I am using direct show for getting stream from webcam connected to my system.

    My camera supports 2048*1536 resolution at 12.5 fps.

    All I want is to change the streaming frame rate from 12.5 to 5 to fulfilling some desired behavior.

    Can any one help me out to achieve this using direct show code?

    Any help will be appreciated.

    Thanks in advance,

    Sanket Mehta

Alle Antworten

  • Samstag, 3. März 2012 19:43
     
     
    Sanket Mehta wrote:
    >
    >I am using direct show for getting stream from webcam connected to my system.
    >
    >My camera supports 2048*1536 resolution at 12.5 fps.
    >
    >All I want is to change the streaming frame rate from 12.5 to 5 to
    >fulfilling some desired behavior.
     
    Note that your camera is not required to support arbitrary frame rates. You
    can ASK for this, but you might not get it.
     
    >Can any one help me out to achieve this using direct show code?
     
    You do it the same way that you change the frame size.  Here I use the
    ICaptureGraphBuilder2 to fetch the capture pin from the capture filter.  If
    you already have the IPin, you can ask it for the IAMStreamConfig directly.
     
        CComPtr<IAMStreamConfig> pisc;
        m_CapGraph->FindInterface(
            &PIN_CATEGORY_CAPTURE,
            &MEDIATYPE_Video,
            m_CaptureFilter,
            IID_IAMStreamConfig,
            (void**)pisc
        );
     
        AM_MEDIA_TYPE* pmt;
        pisc->GetFormat( &pmt );
        VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)pmt->pbFormat;
     
        // Set new frame rate.
     
        vih->AvgTimePerFrame = 10000000 / 5;   // 5 frames per second
        pisc->SetFormat( pisc );
     
        DeleteMediaType(pmt);
     
        pisc.Release();
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.
     

    Tim Roberts, VC++ MVP Providenza & Boekelheide, Inc.