none
video preview stops when a still image is captured (windows mobile5,DirectShow)

    Question

  • Hi

    In my mobile application I am capturing video using DirectShow filters. I have two separate RenderStreams for video preview and video capture.

     

    These are the two render streams

     

    m_pCaptureGraphBuilder->RenderStream( &PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,

    m_pVideoCaptureFilter, NULL, NULL );

    m_pCaptureGraphBuilder->RenderStream( &PIN_CATEGORY_STILL, &MEDIATYPE_Video,

    m_pVideoCaptureFilter, pSGFilter, pNullRenderer );// pSGFilter--custom sample grabber filter and pNullRenderer-- custom null renderer filter

     

     The video preview stops after receiving the first sample . I want to get the still image of each sample contiuously with out affecting the preview.Please advice me on how to achieve this?

     

    Also I am using the PIN_CATEGORY_STILL to get a high resolution buffer. Is there any other way to get the high resolution image with out using the still capture?

     

    Thanks in advance

    Tuesday, November 25, 2008 4:21 PM

Answers

  • Typically, you cannot capture from a high resolution Still Pin and show the Preview Pin simultaneously because the driver switches modes internally to support one or the other pin.

     

    As stated in the SDK docs:

     

    The recommended way to get still images from the device is to use the Windows Image Acquisition (WIA) APIs. For more information, see "Windows Image Acquisition" in the Platform SDK documentation. However, you can also use DirectShow to capture an image.

     

    Whether you can use WIA while using dshow preview is device dependent.

     

     

    Wednesday, November 26, 2008 1:52 PM
    Moderator

All replies

  • You have to set m_pCaptureGraphBuilder->SetOneShot(FALSE); To FALSE
    Tuesday, November 25, 2008 5:37 PM
  •  

    m_pCaptureGraphBuilder is an object of ICaptureGraphBuilder2 and I could not find any method SetOneShot() for this object. Also my Sample Grabber is a custom sample grabber . Please advice me on how to solve this problem?
    Wednesday, November 26, 2008 5:20 AM
  • You should do the following for you Sample Grabber:

    hr = pSampleGrabberFilter->QueryInterface(IID_ISampleGrabber, (void **)&pGrabb);
    [...]
    pGrabb->SetOneShot(FALSE);

    Even it´s a custom filter it should implement that interface, otherwise it would be not very usefull as a sample grabber...
     

    Wednesday, November 26, 2008 12:45 PM
  •  Mister-Zorg wrote:
    pGrabb->SetOneShot(FALSE);

    Even it´s a custom filter it should implement that interface, otherwise it would be not very usefull as a sample grabber...
    
    

    This is not a valid assertion.  If you have a custom fitler for sample grabber and do not need one shot mode then there is no reason to implement this mode.

    Wednesday, November 26, 2008 1:46 PM
    Moderator
  • Typically, you cannot capture from a high resolution Still Pin and show the Preview Pin simultaneously because the driver switches modes internally to support one or the other pin.

     

    As stated in the SDK docs:

     

    The recommended way to get still images from the device is to use the Windows Image Acquisition (WIA) APIs. For more information, see "Windows Image Acquisition" in the Platform SDK documentation. However, you can also use DirectShow to capture an image.

     

    Whether you can use WIA while using dshow preview is device dependent.

     

     

    Wednesday, November 26, 2008 1:52 PM
    Moderator
  • Hi Sreejit,

    I am doing a similar project like yours using a custom samplegrabber and nullrenderer. Can you share on how u did ur implementation? I have a project but the mobile application has problems with the custom filters when i try to do pMediaControl->run(). my email is at -  lightbolt1985 (a){t} [h0tmail] (d0t) <c0m> .

    Thanks in advance :)
    Tuesday, October 20, 2009 3:23 AM
  • IBaseFilter *pVideoSrcFilter = NULL;
    IMediaControl * m_pMC ;
    IMediaEventEx * m_pME ;
    IGraphBuilder * m_pGraph ;
    ICaptureGraphBuilder2 * m_pCapture ;
    IBaseFilter* m_pGrabberFilter;
    ISampleGrabber *pSG = NULL;
    IBaseFilter* m_pGrabberFilter1;
    ISampleGrabber *pSG1 = NULL;
    IBaseFilter *pNullRenderer;
    IBaseFilter *pNullRenderer1;
    
        // Create the filter graph
        HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,
                              IID_IGraphBuilder, (void **) & m_pGraph);
        if (FAILED(hr))
        {
            qDebug()<<"failed to create filter graph";
            SAFE_RELEASE(m_pGraph);
        }
    
        // Create the capture graph builder
        hr = CoCreateInstance(CLSID_CaptureGraphBuilder2 , NULL, CLSCTX_INPROC,
                              IID_ICaptureGraphBuilder2, (void **) & m_pCapture);
        if (FAILED(hr))
        {
            SAFE_RELEASE(m_pCapture);
    
        }
    
        // Attach the filter graph to the capture graph
        hr = m_pCapture->SetFiltergraph(m_pGraph);
        if (FAILED(hr))
        {
             qDebug()<<"failed to SetFiltergraph";
        }
    
    
        QString videoDevice;
        int deviceID = 1;
        hr = findCaptureDevice(&pVideoSrcFilter, CLSID_VideoInputDeviceCategory, deviceID, &videoDevice);
        if (FAILED(hr)) {
    
    
            qDebug() << "Failed to Get Video Capture Device";
            SAFE_RELEASE(pVideoSrcFilter);
    
        }
        // Add Capture filter to our graph.
        hr = m_pGraph->AddFilter(pVideoSrcFilter, L"Video Capture");
        if (FAILED(hr)) {
            qDebug() << "Add failed Video Capture Device";
        }
    
        // Create the Sample Grabber.
        hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,
                                      IID_IBaseFilter, (void**) & m_pGrabberFilter);
    
        if (FAILED(hr)) {
            qDebug() << "Add failed Create the Sample Grabber.";
    
        }
    
    
        hr = m_pGraph->AddFilter(m_pGrabberFilter, L"Sample Grabber");
        if (FAILED(hr)) {
             qDebug() <<"Error. Could not addFilter - m_pGrabberFilter.";
    
        }
    
    
    
        hr = m_pGrabberFilter->QueryInterface(IID_ISampleGrabber, (void**)&pSG);
        if (SUCCEEDED(hr))
        {
            hr = pSG->SetOneShot(FALSE);
            hr = pSG->SetBufferSamples(TRUE);
            hr = pSG->SetCallback(this, 1); // 0 = Use the SampleCB callback method.
        }
    
    
    
        hr = CoCreateInstance(
            CLSID_NullRenderer,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_IBaseFilter,
            (void**)&pNullRenderer
            );
    
        hr = m_pGraph->AddFilter(pNullRenderer, L"NullRender");
    
        // Create the Sample Grabber.
        hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,
                                      IID_IBaseFilter, (void**) & m_pGrabberFilter1);
    
        if (FAILED(hr)) {
            qDebug() << "Add failed Create the Sample Grabber.";
    
        }
    
    
        hr = m_pGraph->AddFilter(m_pGrabberFilter1, L"Sample Grabber1");
        if (FAILED(hr)) {
             qDebug() <<"Error. Could not addFilter - m_pGrabberFilter1.";
    
        }
    
    
    
        hr = m_pGrabberFilter1->QueryInterface(IID_ISampleGrabber, (void**)&pSG1);
        if (SUCCEEDED(hr))
        {
            hr = pSG1->SetOneShot(FALSE);
            hr = pSG1->SetBufferSamples(TRUE);
            hr = pSG1->SetCallback(this, 1); // 0 = Use the SampleCB callback method.
        }
    
    
    
        hr = CoCreateInstance(
            CLSID_NullRenderer,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_IBaseFilter,
            (void**)&pNullRenderer1
            );
    
        hr = m_pGraph->AddFilter(pNullRenderer1, L"NullRender1");
    
    
        hr = m_pCapture->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,
                                      pVideoSrcFilter, m_pGrabberFilter, pNullRenderer);
        if (FAILED(hr))
        {
            QString valueInHex= QString("%1").arg(hr , 0, 16);
            qDebug()<<"failed to render capture pin"<<valueInHex;
        }
    
    
    
    
       hr = m_pCapture->RenderStream(&PIN_CATEGORY_STILL, &MEDIATYPE_Video,
                                     pVideoSrcFilter, m_pGrabberFilter1, pNullRenderer1);
    
        if (FAILED(hr))
        {
            QString valueInHex= QString("%1").arg(hr , 0, 16);
            qDebug()<<"failed to render still pin"<<valueInHex;
        }
    
    
    
        // Obtain interfaces for media control and Video Window
        hr = m_pGraph->QueryInterface(IID_IMediaControl, (LPVOID *) & m_pMC);
        if (FAILED(hr))
        {
    
             qDebug()<<"failed to create IID_IMediaControl";
             SAFE_RELEASE(m_pMC);
    
        }
    
    
        m_pMC->Run();
    
    
    
    //Grab still image
    
    HRESULT hr;
    
        IAMVideoControl *pAMVidControl = NULL;
    
        hr = pVideoSrcFilter->QueryInterface(IID_IAMVideoControl, (void**)&pAMVidControl);
    
        if (SUCCEEDED(hr))
        {
            // Find the still pin.
            IPin *pPin = NULL;
    
            // pBuild is an ICaptureGraphBuilder2 pointer.
    
            hr = m_pCapture->FindPin(
                pVideoSrcFilter,                  // Filter.
                PINDIR_OUTPUT,         // Look for an output pin.
                &PIN_CATEGORY_STILL,   // Pin category.
                NULL,                  // Media type (don't care).
                FALSE,                 // Pin must be unconnected.
                0,                     // Get the 0'th pin.
                &pPin                  // Receives a pointer to thepin.
                );
    
            if (SUCCEEDED(hr))
            {
    
                qDebug()<<"SetMode ...........!!!!!!";
                hr = pAMVidControl->SetMode(pPin, VideoControlFlag_Trigger);
                pPin->Release();
                if (FAILED(hr))
                {
                    QString valueInHex= QString("%1").arg(hr , 0, 16);
    
                     qDebug()<<"SetMode FAILED...........!!!!!!"<<valueInHex;
                }
    
            }
            pAMVidControl->Release();
        }
    m_pMC->Run();
    Wednesday, March 22, 2017 10:45 AM