directshow 视频预览

1. 建立captrue filter

2. 调用ICaptureGraphBuilder2接口的renderstream

hr = m_build->RenderStream(&PIN_CATEGORY_PREVIEW,

        &MEDIATYPE_Video,

        pCapFilter,

        pSGFilter,

        NULL);

我这里的pSGFilter是ISampleGrabber, 用来做视频数据采集的

注意, 用PIN_CATEGORY_PREVIEW采集到的视频数据是不带时间戳的, 带时间戳的是PIN_CATEGORY_CAPTURE

3. 在MFC中的dialog中建立一个picture control控件。

HWND hwndPreview = NULL;

    GetDlgItem( IDC_PREVIEW, &hwndPreview );

    RECT rc;

    ::GetWindowRect( hwndPreview, &rc );

4. 将控件与视频绑定, 使用的是IVideoWindow接口, 需要包含dshow sdk中的头文件control.h

IVideoWindow *pWindow = NULL;

    hr = m_graph->QueryInterface(IID_IVideoWindow, (void**)&pWindow);



    hr = pWindow->put_Owner( (OAHWND) hwndPreview );

    hr = pWindow->put_Left( 0 );

    hr = pWindow->put_Top( 0 );

    hr = pWindow->put_Width( width );

    hr = pWindow->put_Height( height );

    hr = pWindow->put_WindowStyle( WS_CHILD | WS_CLIPSIBLINGS );

    hr = pWindow->put_Visible( OATRUE );

5.IMediaControl Run();

 

详细信息请参考sdk中的例子StillCap

你可能感兴趣的:(show)