How can my application draw text and graphics on top of a running movie, for example as caption text?
The simplest way is to use OvTool. This is a freely available tool that provides an HDC that you can draw text and graphics on, which is overlaid using source colour keying. On non-XP systems, this uses the Overlay Mixer together with a custom source filter that is part of ovtool. When your app calls GetDC, the custom source filter gets a buffer from the overlay mixer and gives you a DC onto it. When you call ReleaseDC, the buffer is delivered to the overlay mixer and source-colour-keyed into the video window. On XP systems, OvTool uses the IVMRMixerBitmap interface to deliver the bitmaps directly to the Video Mixing Renderer.
Note: New Fixes: The latest version fixes an XP-specific bug that only allowed white text -- it created a monochrome bitmap by mistake. There have also been reports of OvTool not working if the video is played back in an application window instead of the default popup window. This is because the window is made visible and receives repaint messages, which make the graph active. OvTool's graph building (inserting the overlay mixer) will not work if the graph is running. The latest version works around this (though you could also just call OvTool.SetGraph before the window re-parenting). End Note
Note: New (1 July 2002): Cleaning up after errors: If the overlay cannot be created, OvTool now reconnects the graph as it was, so playback can continue without the overlay.
29 Sep 2002: If the graph is paused, the ReleaseDC method would block indefinitely. This is now fixed, so you can repeatedly deliver overlays even when the graph is paused. Note: this applies to ovmix mode only. The VMR will not update the display when paused, so you need to force a refresh of the display by, for example, setting the current position (graph.CurrentPosition = graph.CurrentPosition).
To show how simple it is, there is a VB app included in the zip that allows simple overlay of text in only a few lines of VB. There is also an MFC-based C++ application that does the same thing (in source and binary form). Both applications create a filter graph, and then pass it to OvTool. If there is no Video Mixing Renderer or Overlay Mixer, OvTool will insert the Overlay Mixer into the graph. Note that this will not work for all types of graphs, since not all video streams can provide the YUV formats that are typically needed to connect to the overlay mixer. This is especially true for uncompressed RGB and some AVI codecs. To fix this, download the YUV-RGB converter filter.
The overlay mixer uses colour-keyed DirectDraw overlays. This is not ideal for all applications, and it does not work with all decoders. On XP systems, the Video Mixing Renderer provides a far superior tool for mixing, using alpha-blending rather than colour-keying. OvTool ensures that your app can work with the VMR, but it does not take full advantage of it.
Note that there are two problems on XP with playback of raw RGB files. Both are apparently related to confusion between RGB and ARGB formats. If you want to use OvTool with RGB files on XP, you should consider using the overlay mixer in the graph to prevent use of VMR.
Extensive thanks to Stephen Estrop for his patience and advice on XP support.
PS: there is a well-publicised hack involving IOverlay to get the window handle. This will not work on XP, and on pre-XP systems is highly unreliable and is more likely to result in a flickering mess than a successful mix. Please don't use it.