2011-09-12 84 views
5

我是DirectShow的新品牌,並且正在爲我的應用程序添加視頻流。我已經研究過許多解決方案(TouchLess,DirectShow.net等),並最終以此爲結局small project on Code Project沒有多少內容,這就是我選擇它的原因;我想要一個小代碼庫,因爲我需要快速實現此功能。無法使IAMStreamConfig.SetFormat()與LifeCam Studio配合使用

經過一整天的閱讀,試驗和調試,我終於得到了一切正常的工作。這是一個令人失望的延遲,但我可以在後面擔心。我現在遇到的問題是the camera is capable of 1280X720,我想使用這個解決方案。但它似乎決定在640x480捕獲。當我深入瞭解如何設置分辨率時,我終於想到了自己的想法。我還在我用作基礎的評論中找到了Code Project頁面上的代碼。

經過6個小時的試用後,我無法讓相機改變其分辨率。我沒有收到任何錯誤,並且從SetFormat()返回的HRESULT爲0,但相機不會更改分辨率。

有太多的代碼來粘貼一切,但我想包括構建圖的部分,因爲我想這是問題所在。

下面是設置在圖中的代碼

void CameraMethods::StartCamera(int camIndex, interior_ptr<int> width, 
    interior_ptr<int> height) 
{ 
    if (g_pGraphBuilder != NULL) 
     throw gcnew ArgumentException("Graph Builder was null"); 

    IMoniker *pMoniker = GetMoniker(camIndex); 
    pMoniker->AddRef(); 

    HRESULT hr = S_OK; 

    // Build all the necessary interfaces to start the capture 
    if (SUCCEEDED(hr)) 
    { 
     hr = CoCreateInstance(CLSID_FilterGraph, 
      NULL, 
      CLSCTX_INPROC, 
      IID_IGraphBuilder, 
      (LPVOID*)&g_pGraphBuilder); 
    } 

    if (SUCCEEDED(hr)) 
     hr = g_pGraphBuilder->QueryInterface(IID_IMediaControl, (LPVOID*)&g_pMediaControl); 

    if (SUCCEEDED(hr)) 
    { 
     hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, 
      NULL, 
      CLSCTX_INPROC, 
      IID_ICaptureGraphBuilder2, 
      (LPVOID*)&g_pCaptureGraphBuilder); 
    } 

    // Setup the filter graph 
    if (SUCCEEDED(hr)) 
     hr = g_pCaptureGraphBuilder->SetFiltergraph(g_pGraphBuilder); 

    // Build the camera from the moniker 
    if (SUCCEEDED(hr)) 
     hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, (LPVOID*)&g_pIBaseFilterCam); 

    // Add the camera to the filter graph 
    if (SUCCEEDED(hr)) 
     hr = g_pGraphBuilder->AddFilter(g_pIBaseFilterCam, L"WebCam"); 

    // Create a SampleGrabber 
    if (SUCCEEDED(hr)) 
     hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, 
      (void**)&g_pIBaseFilterSampleGrabber); 

    // Configure the Sample Grabber 
    if (SUCCEEDED(hr)) 
     hr = ConfigureSampleGrabber(g_pIBaseFilterSampleGrabber); 

    // Set the resolution - I have NO idea where this should be executed 
    SetCaptureFormat(camIndex, *width, *height); 

    // Add Sample Grabber to the filter graph 
    if (SUCCEEDED(hr)) 
     hr = g_pGraphBuilder->AddFilter(g_pIBaseFilterSampleGrabber, L"SampleGrabber"); 

    // Create the NullRender 
    if (SUCCEEDED(hr)) 
     hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, 
      (void**)&g_pIBaseFilterNullRenderer); 

    // Add the Null Render to the filter graph 
    if (SUCCEEDED(hr)) 
     hr = g_pGraphBuilder->AddFilter(g_pIBaseFilterNullRenderer, L"NullRenderer"); 

    // Configure the render stream 
    if (SUCCEEDED(hr)) 
     hr = g_pCaptureGraphBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, 
      g_pIBaseFilterCam, g_pIBaseFilterSampleGrabber, g_pIBaseFilterNullRenderer); 

    // Grab the capture width and height 
    if (SUCCEEDED(hr)) 
    { 
     ISampleGrabber* pGrabber = NULL; 
     hr = g_pIBaseFilterSampleGrabber->QueryInterface(IID_ISampleGrabber, (LPVOID*)&pGrabber); 
     if (SUCCEEDED(hr)) 
     { 
      AM_MEDIA_TYPE mt; 
      hr = pGrabber->GetConnectedMediaType(&mt); 
      if (SUCCEEDED(hr)) 
      { 
       VIDEOINFOHEADER *pVih; 
       if ((mt.formattype == FORMAT_VideoInfo) && 
        (mt.cbFormat >= sizeof(VIDEOINFOHEADER)) && 
        (mt.pbFormat != NULL)) 
       { 
        pVih = (VIDEOINFOHEADER*)mt.pbFormat; 
        *width = pVih->bmiHeader.biWidth; 
        *height = pVih->bmiHeader.biHeight; 
       } 
       else 
       { 
        hr = E_FAIL; // Wrong format 
       } 

       // FreeMediaType(mt); (from MSDN) 
       if (mt.cbFormat != 0) 
       { 
        CoTaskMemFree((PVOID)mt.pbFormat); 
        mt.cbFormat = 0; 
        mt.pbFormat = NULL; 
       } 
       if (mt.pUnk != NULL) 
       { 
        // Unecessary because pUnk should not be used, but safest. 
        mt.pUnk->Release(); 
        mt.pUnk = NULL; 
       } 
      } 
     } 

     if (pGrabber != NULL) 
     { 
      pGrabber->Release(); 
      pGrabber = NULL; 
     } 
    } 

    // Start the capture 
    if (SUCCEEDED(hr)) 
     hr = g_pMediaControl->Run(); 

    // If init fails then ensure that you cleanup 
    if (FAILED(hr)) 
     StopCamera(); 
    else 
     hr = S_OK; // Make sure we return S_OK for success 

    // Cleanup 
    if (pMoniker != NULL) 
    { 
     pMoniker->Release(); 
     pMoniker = NULL; 
    } 

    if (SUCCEEDED(hr)) 
     this->activeCameraIndex = camIndex; 
    else 
     throw gcnew COMException("Error Starting Camera", hr); 
} 

[UPDATE]增加下面

HRESULT CameraMethods::ConfigureSampleGrabber(IBaseFilter *pIBaseFilter) 
{ 
    HRESULT hr = S_OK; 
    ISampleGrabber *pGrabber = NULL; 

    hr = pIBaseFilter->QueryInterface(IID_ISampleGrabber, (void**)&pGrabber); 
    if (SUCCEEDED(hr)) 
    { 
     AM_MEDIA_TYPE mt; 
     ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE)); 
     mt.majortype = MEDIATYPE_Video; 
     mt.subtype = MEDIASUBTYPE_RGB24; 
     mt.formattype = FORMAT_VideoInfo; 
     hr = pGrabber->SetMediaType(&mt); 
    } 

    if (SUCCEEDED(hr)) 
     hr = pGrabber->SetCallback(new SampleGrabberCB(), 1); 

    if (pGrabber != NULL) 
    { 
     pGrabber->Release(); 
     pGrabber = NULL; 
    } 

    return hr; 
} 

的ConfigureSampleGrabber()方法,該方法是非常從CodeProject上源確切的代碼碼。然後我加入這個方法來設置分辨率:

void CameraMethods::SetCaptureFormat(int camIndex, int width, int height) 
{ 
    HRESULT hr = S_OK; 
    IMoniker* pMoniker = GetMoniker(camIndex); 

    IBaseFilter* pCap; 
    hr=pMoniker->BindToObject(0,0,IID_IBaseFilter,(void **)&pCap); 

    if(!SUCCEEDED(hr)) 
     return; 

    IAMStreamConfig *pConfig = NULL; 

    if(g_pCaptureGraphBuilder == NULL) // no CaptureGraphBuilder initialised 
     return; 

    hr = g_pCaptureGraphBuilder->FindInterface(
     &PIN_CATEGORY_CAPTURE, // Preview pin. 
     0, // Any media type. 
     pCap, // Pointer to the capture filter. 
     IID_IAMStreamConfig, (void**)&pConfig); 

    if(!SUCCEEDED(hr)) 
     return; 

    int iCount = 0, iSize = 0; 
    hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize); 

    // Check the size to make sure we pass in the correct structure. 
    if (iSize == sizeof(VIDEO_STREAM_CONFIG_CAPS)) { 

     // Use the video capabilities structure. 
     for (int iFormat = 0; iFormat < iCount; iFormat++) 
     { 
      VIDEO_STREAM_CONFIG_CAPS scc; 
      AM_MEDIA_TYPE *pmt; 
      /* Note: Use of the VIDEO_STREAM_CONFIG_CAPS structure to configure a video device is 
      deprecated. Although the caller must allocate the buffer, it should ignore the 
      contents after the method returns. The capture device will return its supported 
      formats through the pmt parameter. */ 
      hr = pConfig->GetStreamCaps(iFormat, &pmt, (BYTE*)&scc); 
      if (SUCCEEDED(hr)) 
      { 
       /* Examine the format, and possibly use it. */ 
       if (pmt->formattype == FORMAT_VideoInfo) { 
        // Check the buffer size. 
        if (pmt->cbFormat >= sizeof(VIDEOINFOHEADER)) 
        { 
         VIDEOINFOHEADER *pVih = reinterpret_cast<VIDEOINFOHEADER*>(pmt->pbFormat); 
         BITMAPINFOHEADER *bmiHeader = &pVih->bmiHeader; 

         /* Access VIDEOINFOHEADER members through pVih. */ 
         if(bmiHeader->biWidth == width && bmiHeader->biHeight == height && 
          bmiHeader->biBitCount == 24) 
         { 
          hr = pConfig->SetFormat(pmt); 
         } 
        } 
       } 

       // Delete the media type when you are done. 
       DeleteMediaType(pmt); 
      } 
     } 
    } 
} 

被執行SetFormat()的調用我已經通過代碼加強和驗證,並返回一個有效的HRESULT。沒有更改捕獲的幀雖然。

沒有錯誤消息,很難知道從哪裏開始。我希望在這裏有一些DirectShow專家會看到問題,我甚至會對一個好的時尚居高臨下感到滿意。「好的,你認爲一旦緩衝區分配在過濾器堆棧和小部件初始化爲foobar!pft ... lol「;)

教我,哦,DirectShow/COM神!

[更新#2](僅供參考,這是奇怪的是,我們不能只是增加一個新的消息,該系統需要編輯這樣的原件)

每羅馬的建議,我已經使用GraphStudio來看看我的圖表。我承認我仍然不明白我在看什麼。我發現了一個「文本報告」功能,並認爲在這裏發佈該報告會有幫助,以防它顯示一些有價值的信息。

-------------------------------------------------- 
    Filters 
-------------------------------------------------- 
    1. Smart Tee 
    2. MJPEG Decompressor 
    3. SampleGrabber 
    4. NullRenderer 
    5. WebCam 

-------------------------------------------------- 
    Connections 
-------------------------------------------------- 
    1. [Smart Tee]/(Capture) -> [MJPEG Decompressor]/(XForm In) 
     Major: MEDIATYPE_Video 
     Subtype: MEDIASUBTYPE_MJPG 
      bFixedSizeSamples: TRUE 
      bTemporalCompression: FALSE 
      lSampleSize:   921600 
      cbFormat:    88 
     Format: FORMAT_VideoInfo 
     VIDEOINFOHEADER: 
      rcSource:    (0,0,0,0) 
      rcTarget:    (0,0,0,0) 
      dwBitRate:   221184000 
      dwBitErrorRate:  0 
      AvgTimePerFrame:  333333 
     BITMAPINFOHEADER: 
      biSize:    40 
      biWidth:    640 
      biHeight:    480 
      biPlanes:    1 
      biBitCount:   24 
      biCompression:  0x47504A4D 
      biSizeImage:   921600 
      biXPelsPerMeter:  0 
      biYPelsPerMeter:  0 
      biClrUsed:   0 
      biClrImportant:  0 

    2. [MJPEG Decompressor]/(XForm Out) -> [SampleGrabber]/(Input) 
     Major: MEDIATYPE_Video 
     Subtype: MEDIASUBTYPE_RGB24 
      bFixedSizeSamples: TRUE 
      bTemporalCompression: FALSE 
      lSampleSize:   921600 
      cbFormat:    88 
     Format: FORMAT_VideoInfo 
     VIDEOINFOHEADER: 
      rcSource:    (0,0,0,0) 
      rcTarget:    (0,0,0,0) 
      dwBitRate:   221184221 
      dwBitErrorRate:  0 
      AvgTimePerFrame:  333333 
     BITMAPINFOHEADER: 
      biSize:    40 
      biWidth:    640 
      biHeight:    480 
      biPlanes:    1 
      biBitCount:   24 
      biCompression:  0x00000000 
      biSizeImage:   921600 
      biXPelsPerMeter:  0 
      biYPelsPerMeter:  0 
      biClrUsed:   0 
      biClrImportant:  0 

    3. [SampleGrabber]/(Output) -> [NullRenderer]/(In) 
     Major: MEDIATYPE_Video 
     Subtype: MEDIASUBTYPE_RGB24 
      bFixedSizeSamples: TRUE 
      bTemporalCompression: FALSE 
      lSampleSize:   921600 
      cbFormat:    88 
     Format: FORMAT_VideoInfo 
     VIDEOINFOHEADER: 
      rcSource:    (0,0,0,0) 
      rcTarget:    (0,0,0,0) 
      dwBitRate:   221184221 
      dwBitErrorRate:  0 
      AvgTimePerFrame:  333333 
     BITMAPINFOHEADER: 
      biSize:    40 
      biWidth:    640 
      biHeight:    480 
      biPlanes:    1 
      biBitCount:   24 
      biCompression:  0x00000000 
      biSizeImage:   921600 
      biXPelsPerMeter:  0 
      biYPelsPerMeter:  0 
      biClrUsed:   0 
      biClrImportant:  0 

    4. [WebCam]/(Capture) -> [Smart Tee]/(Input) 
     Major: MEDIATYPE_Video 
     Subtype: MEDIASUBTYPE_MJPG 
      bFixedSizeSamples: TRUE 
      bTemporalCompression: FALSE 
      lSampleSize:   921600 
      cbFormat:    88 
     Format: FORMAT_VideoInfo 
     VIDEOINFOHEADER: 
      rcSource:    (0,0,0,0) 
      rcTarget:    (0,0,0,0) 
      dwBitRate:   221184000 
      dwBitErrorRate:  0 
      AvgTimePerFrame:  333333 
     BITMAPINFOHEADER: 
      biSize:    40 
      biWidth:    640 
      biHeight:    480 
      biPlanes:    1 
      biBitCount:   24 
      biCompression:  0x47504A4D 
      biSizeImage:   921600 
      biXPelsPerMeter:  0 
      biYPelsPerMeter:  0 
      biClrUsed:   0 
      biClrImportant:  0 

[更新#3] - 神聖的COW,我開始了什麼? 爲什麼Google搜索會比我之前使用過的Google搜索引擎的色彩更深一些? I downloaded the app並立即必須修復一個太小的緩衝區的錯誤。 - 這是後已經在圖中通過AddFilter,但其尚未輸出引腳連接之前

Dump Version: 1.2 

Using device: Microsoft® LifeCam Studio(TM) 
Interface: USB 

Pin Name: Capture 
Pin direction: Output 
Pin category: Capture 

IAMVideoCompression: No 
ISpecifyPropertyPages: Yes 
IMediaSeeking: Yes 
IPinConnection: No 
IPinFlowControl: No 
IAMDroppedFrames: No 
IAMVideoProcAmp: No 
IAMVideoControlCaps: 0 

Major Type Sub Type Format Type FixedSamples Temporal Compression Sample Size Max Input Size Min Output Size Max Output Size Min-Max FPS Video Standard 
Video YUY2 VideoInfo Fixed NotTemporal 614400 640x480 640x480 640x480 7.50-30.00 {none} 
Video YUY2 VideoInfo2 Fixed NotTemporal 614400 640x480 640x480 640x480 7.50-30.00 {none} 
Video YUY2 VideoInfo Fixed NotTemporal 1843200 1280x720 1280x720 1280x720 7.50-10.00 {none} 
Video YUY2 VideoInfo2 Fixed NotTemporal 1843200 1280x720 1280x720 1280x720 7.50-10.00 {none} 
Video YUY2 VideoInfo Fixed NotTemporal 1044480 960x544 960x544 960x544 7.50-20.00 {none} 
Video YUY2 VideoInfo2 Fixed NotTemporal 1044480 960x544 960x544 960x544 7.50-20.00 {none} 
Video YUY2 VideoInfo Fixed NotTemporal 716800 800x448 800x448 800x448 7.50-30.00 {none} 
Video YUY2 VideoInfo2 Fixed NotTemporal 716800 800x448 800x448 800x448 7.50-30.00 {none} 
Video YUY2 VideoInfo Fixed NotTemporal 460800 640x360 640x360 640x360 7.50-30.00 {none} 
Video YUY2 VideoInfo2 Fixed NotTemporal 460800 640x360 640x360 640x360 7.50-30.00 {none} 
Video YUY2 VideoInfo Fixed NotTemporal 203520 424x240 424x240 424x240 7.50-30.00 {none} 
Video YUY2 VideoInfo2 Fixed NotTemporal 203520 424x240 424x240 424x240 7.50-30.00 {none} 
Video YUY2 VideoInfo Fixed NotTemporal 202752 352x288 352x288 352x288 7.50-30.00 {none} 
Video YUY2 VideoInfo2 Fixed NotTemporal 202752 352x288 352x288 352x288 7.50-30.00 {none} 
Video YUY2 VideoInfo Fixed NotTemporal 153600 320x240 320x240 320x240 7.50-30.00 {none} 
Video YUY2 VideoInfo2 Fixed NotTemporal 153600 320x240 320x240 320x240 7.50-30.00 {none} 
Video YUY2 VideoInfo Fixed NotTemporal 960000 800x600 800x600 800x600 7.50-20.00 {none} 
Video YUY2 VideoInfo2 Fixed NotTemporal 960000 800x600 800x600 800x600 7.50-20.00 {none} 
Video YUY2 VideoInfo Fixed NotTemporal 50688 176x144 176x144 176x144 7.50-30.00 {none} 
Video YUY2 VideoInfo2 Fixed NotTemporal 50688 176x144 176x144 176x144 7.50-30.00 {none} 
Video YUY2 VideoInfo Fixed NotTemporal 38400 160x120 160x120 160x120 7.50-30.00 {none} 
Video YUY2 VideoInfo2 Fixed NotTemporal 38400 160x120 160x120 160x120 7.50-30.00 {none} 
Video YUY2 VideoInfo Fixed NotTemporal 4147200 1920x1080 1920x1080 1920x1080 5.00-5.00 {none} 
Video YUY2 VideoInfo2 Fixed NotTemporal 4147200 1920x1080 1920x1080 1920x1080 5.00-5.00 {none} 
Video MJPG VideoInfo Fixed NotTemporal 921600 640x480 640x480 640x480 7.50-30.00 {none} 
Video MJPG VideoInfo2 Fixed NotTemporal 921600 640x480 640x480 640x480 7.50-30.00 {none} 
Video MJPG VideoInfo Fixed NotTemporal 6220800 1920x1080 1920x1080 1920x1080 7.50-30.00 {none} 
Video MJPG VideoInfo2 Fixed NotTemporal 6220800 1920x1080 1920x1080 1920x1080 7.50-30.00 {none} 
Video MJPG VideoInfo Fixed NotTemporal 2764800 1280x720 1280x720 1280x720 7.50-30.00 {none} 
Video MJPG VideoInfo2 Fixed NotTemporal 2764800 1280x720 1280x720 1280x720 7.50-30.00 {none} 
Video MJPG VideoInfo Fixed NotTemporal 1566720 960x544 960x544 960x544 7.50-30.00 {none} 
Video MJPG VideoInfo2 Fixed NotTemporal 1566720 960x544 960x544 960x544 7.50-30.00 {none} 
Video MJPG VideoInfo Fixed NotTemporal 1075200 800x448 800x448 800x448 7.50-30.00 {none} 
Video MJPG VideoInfo2 Fixed NotTemporal 1075200 800x448 800x448 800x448 7.50-30.00 {none} 
Video MJPG VideoInfo Fixed NotTemporal 691200 640x360 640x360 640x360 7.50-30.00 {none} 
Video MJPG VideoInfo2 Fixed NotTemporal 691200 640x360 640x360 640x360 7.50-30.00 {none} 
Video MJPG VideoInfo Fixed NotTemporal 1440000 800x600 800x600 800x600 7.50-30.00 {none} 
Video MJPG VideoInfo2 Fixed NotTemporal 1440000 800x600 800x600 800x600 7.50-30.00 {none} 
Video MJPG VideoInfo Fixed NotTemporal 311040 432x240 432x240 432x240 7.50-30.00 {none} 
Video MJPG VideoInfo2 Fixed NotTemporal 311040 432x240 432x240 432x240 7.50-30.00 {none} 
Video MJPG VideoInfo Fixed NotTemporal 304128 352x288 352x288 352x288 7.50-30.00 {none} 
Video MJPG VideoInfo2 Fixed NotTemporal 304128 352x288 352x288 352x288 7.50-30.00 {none} 
Video MJPG VideoInfo Fixed NotTemporal 76032 176x144 176x144 176x144 7.50-30.00 {none} 
Video MJPG VideoInfo2 Fixed NotTemporal 76032 176x144 176x144 176x144 7.50-30.00 {none} 
Video MJPG VideoInfo Fixed NotTemporal 230400 320x240 320x240 320x240 7.50-30.00 {none} 
Video MJPG VideoInfo2 Fixed NotTemporal 230400 320x240 320x240 320x240 7.50-30.00 {none} 
Video MJPG VideoInfo Fixed NotTemporal 57600 160x120 160x120 160x120 7.50-30.00 {none} 
Video MJPG VideoInfo2 Fixed NotTemporal 57600 160x120 160x120 160x120 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 460800 640x480 640x480 640x480 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 460800 640x480 640x480 640x480 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 1382400 1280x720 1280x720 1280x720 7.50-15.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 1382400 1280x720 1280x720 1280x720 7.50-15.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 783360 960x544 960x544 960x544 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 783360 960x544 960x544 960x544 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 537600 800x448 800x448 800x448 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 537600 800x448 800x448 800x448 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 345600 640x360 640x360 640x360 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 345600 640x360 640x360 640x360 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 152640 424x240 424x240 424x240 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 152640 424x240 424x240 424x240 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 152064 352x288 352x288 352x288 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 152064 352x288 352x288 352x288 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 115200 320x240 320x240 320x240 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 115200 320x240 320x240 320x240 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 720000 800x600 800x600 800x600 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 720000 800x600 800x600 800x600 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 38016 176x144 176x144 176x144 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 38016 176x144 176x144 176x144 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 28800 160x120 160x120 160x120 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 28800 160x120 160x120 160x120 7.50-30.00 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo Fixed NotTemporal 3110400 1920x1080 1920x1080 1920x1080 7.50-7.50 {none} 
Video {3032344D-0000-0010-8000-00AA00389B71} VideoInfo2 Fixed NotTemporal 3110400 1920x1080 1920x1080 1920x1080 7.50-7.50 {none} 

Pin Name: Video Camera Terminal 
Pin direction: Input 
Pin category: {3EBC7959-3310-493B-AA81-C7E132D56F71} 

IAMVideoCompression: No 
ISpecifyPropertyPages: Yes 
IMediaSeeking: No 
IPinConnection: No 
IPinFlowControl: No 
IAMDroppedFrames: No 
IAMVideoProcAmp: No 
IAMVideoControlCaps: 0 

Major Type Sub Type Format Type FixedSamples Temporal Compression Sample Size 

回答

3

你把它放到正確的地方:解決了我能夠生成以下報告後。如果您的HRESULT成功了,那麼您可能會期望改變格式,但可能會有例外情況,例如,此媒體類型未被下游過濾器接受,並且他們從一開始就開始協商。

您沒有在此處顯示ConfigureSampleGrabber,因此可能會出現這種情況,您希望此媒體類型不被採樣卡製作濾波器圖表嘗試替換媒體類型和/或中間濾波器(如解碼器)所接受。

實際上你可以做幾件事情。

  1. 有關故障排除,你可能想:

    1. add the filter graph to ROT,或而不只是install DirectShow Spy有你同樣的自動完成
    2. 在你的代碼你SetCaptureFormat之後添加一個MessageBox
    3. 當消息框仍然在屏幕上時,使用GraphEdit(GraphStudio)來檢查您的過濾器圖形,並查看它在其輸出引腳上枚舉的媒體類型;通常第一媒體類型將是用於實時連接的一個,所以在SetFormat您的全成HRESULT基本假設現在媒體類型是這個名單
  2. 要強制媒體類型的頂部,你可能想使用IFilterGraph :: ConnectDirect與配置的引腳,它是您感興趣的直接鄰居下游引腳和媒體類型。

希望這會有所幫助。

+0

我已更新原始文章以包含ConfigureSampleGrabber()方法。同時,我會研究你列出的附加選項。感謝您的回覆 –

+0

因此,您可能會在相機上設置非RGB媒體類型,並且您將Sample Grabber設置爲僅接受RGB視頻。然後你要求把這兩樣東西連接在一起...... 如果(a)相機決定嘗試另一種媒體類型,而不是你指示它使用的類型,或者(b)會有另一箇中間過濾器並再次發生媒體類型改變。 –

+1

...你可以通過明確地設置媒體類型來處理這個問題,就像我上面寫的那樣,或者插入一個額外的採樣卡,它可以在攝像機過濾之後立即接受任何視頻,以便所有後續操作都涉及到SG的輸出引腳,而不是攝像機。這將保留通過SetFormat選擇的原始媒體類型。 –

0

史蒂夫,你不應該在SetCaptureFormat重建攝像頭(從綽號),但使用g_pIBaseFilterCam

相關問題