IAMStreamConfig 设置问题/设置分辨率/准确获取filter

        IAMStreamConfig *pConfig = NULL;
        hr = g_pCapture->FindInterface(
            &LOOK_DOWNSTREAM_ONLY,// Preview pin.
            0,// Any media type.
            pSrcFilter,
            IID_IAMStreamConfig,(void**)&pConfig);

        if (FAILED(hr)) {
            Msg(TEXT("Couldn't get the IAMStreamConfig!  hr=0x%x"), hr);
            return hr;
        }

 

//上面这段代码老是不能准确获得我所要的filter然后进行配置,即使获得了,也是枚举不出我想要的配置。

 

在网上找,有两个方面的答案,一是http://topic.csdn.net/u/20080827/17/8b2dcced-316f-4b9d-80f6-e4776931ec73.html

要在摄像头支持的参数中选取

 

二是下面这种方法,来自:http://social.msdn.microsoft.com/Forums/en/windowsdirectshowdevelopment/thread/da858fcb-6f49-4d9d-8211-5092c3974697   中kavuncu的答案


hr = pGraph->AddFilter( pSource, L"Source" );

// Tell the grabber to grab 24-bit video. Must do this

// before connecting it

//

AM_MEDIA_TYPE m;

CMediaType GrabType;

GrabType.SetType( &MEDIATYPE_Video );

GrabType.SetSubtype( &MEDIASUBTYPE_YUY2 );

hr = pGrabber->SetMediaType( &GrabType );

// Get the output pin and the input pin

//

CComPtr< IPin > pSourcePin;

CComPtr< IPin > pGrabPin;

pSourcePin = GetOutPin( pSource, 0 );

VidFormat vit={ 640, 480,60};VidFormat* vidFmt=&vit;

IAMStreamConfig* pVSC;

AM_MEDIA_TYPE *pmt = NULL;

pSourcePin->QueryInterface( IID_IAMStreamConfig, (void **) &pVSC );

VIDEO_STREAM_CONFIG_CAPS scc;

int piCount, piSize;

hr = pVSC->GetNumberOfCapabilities(&piCount, &piSize);

if(hr == S_OK)

{

for(int i = 0; i < piCount; i++)

{

pVSC->GetStreamCaps(i, &pmt, reinterpret_cast(&scc));

VIDEOINFOHEADER *pVih = reinterpret_cast(pmt->pbFormat);

if(pVih->bmiHeader.biWidth == vidFmt->width && pVih->bmiHeader.biHeight == vidFmt->height)

{

if( vidFmt->framerate > 0 )

pVih->AvgTimePerFrame = (LONGLONG)(10000000 / vidFmt->framerate);

pVSC->SetFormat(pmt);

/* cvcam_properties[(uint)camera].srcwidth = pVih->bmiHeader.biWidth;

cvcam_properties[(uint)camera].srcheight = abs(pVih->bmiHeader.biHeight);*/

DeleteMediaType(pmt);

 

 

 

你可能感兴趣的:(IAMStreamConfig 设置问题/设置分辨率/准确获取filter)