none
Setting up Webcam properties with directshow

    Question

  • Hi everybody.

    For a webcam preview and capture application, I am trying to set in I420 the video stream coming from my webcam.

    I tried to use this code (given in directshow help) but i can't manage to initialize the config pointer pConfig. While debbuging, I saw that there the HRESULT hr is equal to E_NOINTERFACE. Have i forgotten something?

    Thanks in advance.


                       
    Code Snippet

    IAMStreamConfig *pConfig = NULL;
                        HRESULT hr = g_pCapture->FindInterface(
                        &PIN_CATEGORY_PREVIEW, // Preview pin.
                        0,    // Any media type.
                        pCap, // Pointer to the capture filter.
                        IID_IAMStreamConfig, (void**)&pConfig);
                   
                        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 *pmtConfig;
                                hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc);
                                if (SUCCEEDED(hr))
                                {
                                    /* Examine the format, and possibly use it. */
                                    hr = pConfig->SetFormat(pmtConfig);
                                    pmtConfig->subtype = MEDIASUBTYPE_RGB24;
                                    // Delete the media type when you are done.
                                    //DeleteMediaType(pmtConfig);
                                }
                            }


                   
                           
                   
                    //        if ((pmtConfig.majortype == MEDIATYPE_Video) &&
                    //    (pmtConfig.subtype == MEDIASUBTYPE_RGB24) &&
                    //    (pmtConfig.formattype == FORMAT_VideoInfo) &&
                    //    (pmtConfig.cbFormat >= sizeof (VIDEOINFOHEADER)) &&
                    //    (pmtConfig.pbFormat != NULL))
                    //{
                    //    VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig.pbFormat;
                    //    // pVih contains the detailed format information.
                    //    LONG lWidth = pVih->bmiHeader.biWidth;
                    //    LONG lHeight = pVih->bmiHeader.biHeight;
                    //}
                   
                   
                   
                        }
    Tuesday, May 29, 2007 11:55 AM

Answers

  • Problem solved after a day of work! You were right my webcam didn't have a preview pin and I tried by passing the capture pin and it works fine now.
    Wednesday, May 30, 2007 2:08 PM

All replies

  • Perhaps your webcam doesn't have a preview pin?
    Tuesday, May 29, 2007 8:04 PM
  • Hi. Thanks for the answer!

    I managed to see the stream coming from my webcam by using GraphEdit and also by using the function RenderStream().

    Unfortunately, the video format is in RGB24 and not in I420. In GraphEdit, I manage to call the dialog box which allows me to access to this parameter in a list box. But when I try to call this dialog box through my program, at the function FindInterface( ) the HRESULT returns E_NOINTERFACE.

    I don't understand what I should do to configure the output stream of my webcam.

    Please help me.

    Thanks in advance.
    Wednesday, May 30, 2007 7:51 AM
  • Are you still calling FindInterface against the preview pin?  What other options have you tried here?
    Wednesday, May 30, 2007 8:31 AM
  • I tried to call the webcam properties dialog box by using this code :

    Code Snippet

    // Query the capture filter for the IAMVfwCaptureDialogs interface.
    g_pControl->Stop();
    IAMVfwCaptureDialogs *pVfw = 0;
    HRESULT hr = pCap->QueryInterface(IID_IAMVfwCaptureDialogs, (void**)&pVfw);
    if (SUCCEEDED(hr))
    {
    // Check if the device supports this dialog box.
    if (S_OK == pVfw->HasDialog(VfwCaptureDialog_Source))
    {
    // Show the dialog box.
    hr = pVfw->ShowDialog(VfwCaptureDialog_Format, hwnd);
    }
    }
    g_pControl->Run();



    And I get the same result for HRESULT hr = E_NOINTERFACE.

    Moreover I look at the directshow help concerning the differents subtype for the video format, and I didn't find the I420 format. Do you know where I could find it in order to set my webcam into this format?

    thanks in advance
    Wednesday, May 30, 2007 8:55 AM
  • Problem solved after a day of work! You were right my webcam didn't have a preview pin and I tried by passing the capture pin and it works fine now.
    Wednesday, May 30, 2007 2:08 PM