51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

DirectShow设置摄像头帧率

DirectShow设置摄像头帧率代码如下所示:

|------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | IGraphBuilder* pGB; ICaptureGraphBuilder2* pCapture; // 创建IGraphBuilder接口 hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&pGB); // 创建ICaptureGraphBuilder2接口 hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC, IID_ICaptureGraphBuilder2, (void**)&pCapture); if (FAILED(hr))return hr; pCapture->SetFiltergraph(pGB); IAMStreamConfig* pSC = NULL; hr = pCapture->FindInterface(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, m_pBF, IID_IAMStreamConfig, (void**)&pSC); AM_MEDIA_TYPE* mmt = NULL; pSC->GetFormat(&mmt); //取得默认参数 VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)mmt->pbFormat; pvih->AvgTimePerFrame = 1000000 / 120; // 这里设置帧率为120fps mmt->pbFormat = (unsigned char*)pvih; pSC->SetFormat(mmt); //重新设置参数 |

设置的帧率是介于一个最小值与最大值之间的一个值。当设置的帧率超过最大值,系统会选择最大值作为帧率,同样,当设置的帧率小于最小值,系统就会选择最小值作为帧率。

当设置的帧率介于两者之间,但是摄像头又不支持的话,系统会选取一个最接近的帧率。


赞(0)
未经允许不得转载:工具盒子 » DirectShow设置摄像头帧率