我在互聯網上發現了一個很好的例子,解釋了directshow如何工作。ISampleGrabber可以將視頻幀轉換爲特定的mediaType嗎?
在該示例中在兩個samplegrabbers。一個叫做NON-RGB採集卡,另一個叫RGB-grabber。
第一個:(NON-RGB)
#pragma region Non-RGB Sample Grabber
{
CComPtr<IBaseFilter> pBaseFilter;
ATLENSURE_SUCCEEDED(pBaseFilter.CoCreateInstance(__uuidof(SampleGrabber)));
ATLENSURE_SUCCEEDED(pFilterGraph->AddFilter(pBaseFilter, L"Non-RGB Sample Grabber")); // This will connect in MJPG format
const CComQIPtr<ISampleGrabber> pSampleGrabber = pBaseFilter;
ATLASSERT(pSampleGrabber);
#if TRUE
// NOTE: IFilterGraph::Connect would do just fine, but with a real capture device, if we prefer having Smart Tee added, we need to use
// Capture Graph Builder (only here)
CComPtr<ICaptureGraphBuilder2> pCaptureGraphBuilder;
ATLENSURE_SUCCEEDED(pCaptureGraphBuilder.CoCreateInstance(CLSID_CaptureGraphBuilder2));
ATLENSURE_SUCCEEDED(pCaptureGraphBuilder->SetFiltergraph(pFilterGraph));
ATLENSURE_SUCCEEDED(pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, NULL, pCurrentOutputPin, NULL, pBaseFilter));
#else
ATLENSURE_SUCCEEDED(pFilterGraph->Connect(pCurrentOutputPin, GetPin(pBaseFilter, 0)));
#endif
MessageBox(GetActiveWindow(), _T("After Non-RGB Sample Grabber Connected"), _T("Debug"), MB_OK);
pCurrentOutputPin = GetPin(pBaseFilter, 1);
}
#pragma endregion
第二:(RGB)
#pragma region RGB Sample Grabber
{
CComPtr<IBaseFilter> pBaseFilter;
ATLENSURE_SUCCEEDED(pBaseFilter.CoCreateInstance(__uuidof(SampleGrabber)));
ATLENSURE_SUCCEEDED(pFilterGraph->AddFilter(pBaseFilter, L"RGB Sample Grabber"));
const CComQIPtr<ISampleGrabber> pSampleGrabber = pBaseFilter;
ATLASSERT(pSampleGrabber);
AM_MEDIA_TYPE MediaType;
ZeroMemory(&MediaType, sizeof MediaType);
MediaType.majortype = MEDIATYPE_Video;
MediaType.subtype = MEDIASUBTYPE_RGB24;
ATLENSURE_SUCCEEDED(pSampleGrabber->SetMediaType(&MediaType));
ATLENSURE_SUCCEEDED(pFilterGraph->Connect(pCurrentOutputPin, GetPin(pBaseFilter, 0)));
MessageBox(GetActiveWindow(), _T("After RGB Sample Grabber Connected"), _T("Debug"), MB_OK);
pCurrentOutputPin = GetPin(pBaseFilter, 1);
}
#pragma endregion
的方法 「setmediatype()」 被用於僅在 「RGB」 的版本。但我想知道。在MSDN頁面上說setmediatype()表示樣本抓取器過濾器的輸入引腳中可以使用的數據類型。如果可以在不使用媒體類型的情況下使用採樣器,爲什麼我應該將其設置爲任何內容?
問題:
不要樣本採集做任何類型的媒體轉換?
我爲什麼要設置樣品採集的媒體類型?
如果介質類型形成凸輪被設置爲MJPG,我在samplegrabber設置媒體類型RGB24,會發生什麼?
莫不是使用一個比另一個的任何性能差異?爲了提高軟件的性能(fps),我應該移除其中一個採樣卡嗎?
謝謝!