// connect the video port pin to an overlay mixer. required if present on
the capture filter.
{
IPin *pPinOut; // Video port pin on capture filter. 
IPin *pPinIn; // Input pin on Overlay Mixer.

ICaptureGraphBuilder2* pCGB = m_pCaptureGraphBuilder2;

// Find the video port pin.
HRESULT hr = pCGB->FindPin(
m_pSrcFilter, // Pointer to capture filter.
PINDIR_OUTPUT, // Find an output pin.
&PIN_CATEGORY_VIDEOPORT, // Find a video port pin.
NULL, // Any media type.
TRUE, // Pin must be unconnected.
0, // Retrieve first matching pin.
&pPinOut // Address of pointer to pin.
);

if (SUCCEEDED(hr))
{

// Create the overlay mixer.
IBaseFilter *pOvMix = NULL;
CoCreateInstance(CLSID_OverlayMixer, NULL, CLSCTX_INPROC,
IID_IBaseFilter, (void **)&pOvMix);

// Add it to the filter graph.
m_pGraphBuilder->AddFilter(pOvMix, L"Overlay Mixer");

// Retrieve input pin 0 on the overlay mixer.
pCGB->FindPin(pOvMix, PINDIR_INPUT, NULL, NULL, TRUE, 0, &pPinIn);

// Connect the two pins.
m_pGraphBuilder->Connect(pPinOut, pPinIn);

// Retrieve output pin on the overlay mixer.
pCGB->FindPin(pOvMix, PINDIR_OUTPUT, NULL, NULL, TRUE, 0, &pPinOut);

// create a video renderer
IBaseFilter *pVideo;
hr = CoCreateInstance(CLSID_VideoRenderer, NULL, CLSCTX_INPROC_SERVER, 
IID_IBaseFilter, (LPVOID*) &pVideo);
m_pFilterGraph->AddFilter(pVideo, L"Video Renderer");

// Retrieve input pin on the video renderer
pCGB->FindPin(pVideo, PINDIR_INPUT, NULL, NULL, TRUE, 0, &pPinIn);

// Connect the two pins.
m_pGraphBuilder->Connect(pPinOut, pPinIn);

// release the things we added to the graph
SafeRelease(pOvMix);
SafeRelease(pVideo);

} // if

}