Chapter 10: Writing a DirectShow Transform Filter

Part III

DirectShow Filters for Video Processing

Chapter 10

Writing a DirectShow Transform Filter

Now that we ve covered Microsoft DirectShow application programming in some detail, using it to render and capture media streams, we can focus on the extensible architecture of DirectShow. DirectShow has been carefully designed to allow the programmer to create custom DirectShow filters capture source filters, transform filters, and renderers. These hand-crafted filters can be instanced within and used by any filter graph within any DirectShow application.

This flexibility is an enormous strength of DirectShow and one that many applications already employ. For example, some video editing applications add their own suite of DirectShow filters when they install themselves and then employ these filters at application run time. It s possible even desirable to build a sophisticated media manipulation application out of a collection of DirectShow filters, each of which provides specific functionality within the application.

Although a few DirectShow programmers might be interested in the construction of a capture source filter or renderer filter, the vast majority of filters created for DirectShow are transform filters. Many Video for Windows and Windows Driver Model (WDM) drivers are already available to DirectShow as capture filters. Although a filter graph needs only one or two capture source filters and one or two renderer filters, it might have scores of transform filters between the capture and the renderer.

Transform filters handle tasks such as data compression and decompression, video encoding, file parsing, and stream splitting. And that s only a partial list of the kinds of tasks performed by transform filters. It s possible that you ll want to add your own features to a filter graph, processing an audio or a video stream in a very specific way to achieve a particular engineering goal. That s the role of the transform filter.

In this chapter, we ll explore a very simple transform filter, YUVGray, written by Mike Wasson of the DirectShow Documentation Group at Microsoft. This filter takes a video stream in one of two formats either UYVY or YUY2 (we ll discuss these formats and their differences later in this chapter) and removes all the color information from the stream, leaving the stream with only black and white data. This effect might be handy if you re trying to get a video image to look as though it were created in the 1950s, during the golden age of television. The filter s design is simple enough that it could be extended to a general filter that controls the saturation of the video image in real time.

Although YUVGray is not earth-shattering in its significance, it s quite easy to modify YUVGray to create your own DirectShow transform filter. For example, with just a change to a few lines of code, you could go from black and white to black and red, or black and green, or black and blue. You could even publish Component Object Model (COM) interfaces to your filter so that these color changes could be made in real time through a DirectShow application. So don t be fooled by the apparent simplicity of YUVGray; in these few lines of code are most everything you ll need to know to create your own DirectShow transform filters.



Programming Microsoft DirectShow for Digital Video and Television
Programming Microsoft DirectShow for Digital Video and Television (Pro-Developer)
ISBN: 0735618216
EAN: 2147483647
Year: 2002
Pages: 108
Authors: Mark D. Pesce

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net