在程式中設定 Video Capture Source 的 Pin 屬性

來源:互聯網
上載者:User

DShow從WDM驅動程式自動產生的Video Capture Source Filter有一個Pin Property Page,想必各位高手都知道並且見過。這個Pin Property Page裡面可以設定幀率、鏡頭解析度等設定。

我想問的是,難道不能從程式裡設定幀率,和鏡頭解析度嗎?

當然可以通過程式來設定:用IAMStreamConfig::SetFormat。

首先你獲得你想要設定的Pin的IPin指標;然後QueryInterface得到IAMStreamConfig介面,通過這個介面就可以設定了。你可以參考一下AMCap例子,裡面有使用IAMStreamConfig介面的示範。

陸老師說得太好了!
完全就那麼回事!

給段代碼給你參考:

// 設定視頻輸出Pin的視頻大小,並且將設定的值返回<br />// 如果bMaxSize為TRUE則輸出最大支援的視頻大小,否則按指定大小輸出<br />HRESULT CCardVideoOpt::SetVideoSize(IBaseFilter* pVideoFilter<br />, OUT int &iWidth , OUT int &iHeight, IN BOOL bMaxSize)<br />{<br />HRESULT hr = NOERROR;<br />IAMStreamConfig *pAMStreamConfig = NULL;<br />IPin *pOutPin = NULL;<br />VIDEOINFOHEADER *pVihTmp;<br />int iDefaultW,iDefaultH; // 預設的視頻寬和高 </p><p>//AM_MEDIA_TYPE* pMediaType;<br />pOutPin = CGraphUtility::GetFirstPin(pVideoFilter,PINDIR_OUTPUT);<br />if(pOutPin == NULL)<br />{<br />return E_FAIL;<br />}<br />hr = pOutPin->QueryInterface(IID_IAMStreamConfig,(void**)&pAMStreamConfig);<br />if(FAILED(hr))<br />{<br />SAFE_RELEASE(pOutPin);<br />return hr;<br />} </p><p>int iCount, iSize;<br />VIDEO_STREAM_CONFIG_CAPS scc;<br />AM_MEDIA_TYPE *pmt; </p><p>hr = pAMStreamConfig->GetNumberOfCapabilities(&iCount, &iSize);<br />if (sizeof(scc) != iSize)<br />{<br />SAFE_RELEASE(pOutPin);<br />SAFE_RELEASE(pAMStreamConfig);<br />return E_FAIL;<br />} </p><p>for(int i=0;i<iCount;i++)<br />{<br />hr = pAMStreamConfig->GetStreamCaps(i, &pmt, (BYTE*)(&scc));<br />pVihTmp = (VIDEOINFOHEADER*)(pmt->pbFormat); </p><p>if(pmt->subtype == MEDIASUBTYPE_RGB32)<br />break;<br />}<br />iDefaultW = pVihTmp->bmiHeader.biWidth;<br />iDefaultH = pVihTmp->bmiHeader.biHeight; </p><p>if (hr == S_OK)<br />{<br />// Find the biggest output size.<br />if(bMaxSize)<br />{<br />iWidth = scc.MaxOutputSize.cx;<br />iHeight = scc.MaxOutputSize.cy;<br />}<br />LONG cbPixel = pVihTmp->bmiHeader.biBitCount/8; // Bytes per pixel in RGB32 </p><p>// Modify the format block.<br />VIDEOINFOHEADER *pVih =<br />(VIDEOINFOHEADER*)(pmt->pbFormat);<br />pVih->bmiHeader.biWidth = iWidth;<br />pVih->bmiHeader.biHeight = iHeight; </p><p>// Set the sample size and image size.<br />// (Round the image width up to a DWORD boundary.)<br />pmt->lSampleSize = pVih->bmiHeader.biSizeImage =<br />((iWidth + 3) & ~3) * iHeight * cbPixel; </p><p>// Now set the format.<br />hr = pAMStreamConfig->SetFormat(pmt);<br />if (FAILED(hr))<br />{<br />iWidth = iDefaultW;<br />iHeight = iDefaultH;<br />pVih->bmiHeader.biWidth = iWidth;<br />pVih->bmiHeader.biHeight = iHeight;<br />hr = pAMStreamConfig->SetFormat(pmt);<br />if (FAILED(hr))<br />{<br />SAFE_RELEASE(pOutPin);<br />SAFE_RELEASE(pAMStreamConfig);<br />return hr;<br />} </p><p>SAFE_RELEASE(pOutPin);<br />SAFE_RELEASE(pAMStreamConfig);<br />return hr;<br />}<br />}<br />SAFE_RELEASE(pOutPin);<br />SAFE_RELEASE(pAMStreamConfig); </p><p>return hr;<br />}</p><p>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.