Handling Repaint Events in Video Capture
[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]
If you build a video capture graph without using the ICaptureGraphBuilder2 interface, and you preview the video using the old Video Renderer filter, then you should override the default handling for EC_REPAINT events. Query the Filter Graph Manager for the IMediaEvent interface and call the IMediaEvent::CancelDefaultHandling method with the value EC_REPAINT:
IMediaEvent *pEvent = 0;
hr = pGraph->QueryInterface(IID_IMediaEvent, (void**)&pEvent);
if (SUCCEEDED(hr))
{
pEvent->CancelDefaultHandling (EC_REPAINT);
pEvent->Release();
}
This prevents a possible error that can corrupt your capture file. If the user covers and uncovers the preview window, the Video Renderer filter receives a WM_PAINT message. By default, the Video Renderer requests a new frame, and the Filter Graph Manager pauses the graph in order to cue another video frame. If that happens while the graph is writing a file, it will corrupt the file. Overriding the default EC_REPAINT behavior prevents the renderer from requesting a new frame.
You do not have to perform this step if you are using the ICaptureGraphBuilder2 interface, because the Capture Graph Builder does it for you automatically. Also, it is not required if you are using the Video Mixing Renderer (VMR) for preview. The VMR always has the most recent frame available, so it does not send EC_REPAINT events.
Related topics