用direct show 做视频采集程序,知道 怎么预览,怎么存成avi文件了,
可 没看明白 怎么 单帧采集,难道也是用回调或是消息处理,
那 单帧采集应该触发什么消息啊  
有知道的吗 谢谢

解决方案 »

  1.   

    要设置一个回调函数,例如:
    CComPtr<ISampleGrabber> m_pGrabber;////////////////////////////////////////////////////////////////////////////////////
    // create a sample grabber
    hr = m_pGrabber.CoCreateInstance(CLSID_SampleGrabber);
    if(!m_pGrabber)
    {
      AfxMessageBox("Fail to create SampleGrabber, maybe qedit.dll is not registered?");
      return;
    }CComQIPtr< IBaseFilter, &IID_IBaseFilter > pGrabBase(m_pGrabber);//设置视频格式
    AM_MEDIA_TYPE mt;
    ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE));
    mt.majortype = MEDIATYPE_Video;
    mt.subtype = MEDIASUBTYPE_RGB24;hr = m_pGrabber->SetMediaType(&mt);
    if(FAILED(hr))
    {
      AfxMessageBox("Fail to set media type!");
      return;
    }hr = g_pGraph->AddFilter(pGrabBase, L"Grabber");
    if(FAILED(hr))
    {
      AfxMessageBox("Fail to put sample grabber in graph");
      return;
    }// try to render preview/capture pin
    // 通常情况下,当每个filter只有一个输出pin和一个输入pin时,RenderStream方法就才适用。
    hr = g_pCapture->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, pSrcFilter, pGrabBase, NULL);
    if(FAILED(hr))
      hr = g_pCapture->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, pSrcFilter, pGrabBase, NULL);if(FAILED(hr))
    {
      AfxMessageBox("Can’t build the graph");
      return;
    }hr = m_pGrabber->GetConnectedMediaType( &mt );
    if ( FAILED( hr) )
    {
      AfxMessageBox("Failt to read the connected media type");
      return;
    }VIDEOINFOHEADER * vih = (VIDEOINFOHEADER*) mt.pbFormat;
    mCB.SetVideoBase(this);
    FreeMediaType(mt);hr = m_pGrabber->SetBufferSamples( FALSE );
    hr = m_pGrabber->SetOneShot( FALSE );//设置快照
    hr = m_pGrabber->SetCallback( &mCB, 1 );//设置回调 /*
    //输出到文件
    IBaseFilter *pMux;
    hr = g_pCapture->SetOutputFileName(
    &MEDIASUBTYPE_Avi, // Specifies AVI for the target file.
    L"C:\\Example.avi", // File name.
    &pMux, // Receives a pointer to the mux.
    NULL); // (Optional) Receives a pointer to the file sink. hr = g_pCapture->RenderStream(
      &PIN_CATEGORY_CAPTURE, // Pin category.
      &MEDIATYPE_Video, // Media type.
      pSrcFilter, // Capture filter.
      NULL, // Intermediate filter (optional).
      pMux); // Mux or file sink filter. // Release the mux filter.
    pMux->Release();*/
      

  2.   

    mCB 在回调里面 怎么取图像呢 ISampleGrabber 用它的 方法吗 
    我第一次 用  多谢你们拉