Writing Transform Filters
[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.]
This section describes how to write a transform filter, defined as a filter that has exactly one input pin and one output pin. To illustrate the steps, this section describes a hypothetical transform filter that outputs run-length encoded (RLE) video. It does not describe the RLE-encoding algorithm itself, only the tasks that are specific to DirectShow. (DirectShow already provides an RLE codec through the AVI Compressor filter.)
This section assumes that you will use the DirectShow base class library to create filters. Although you can write a filter without it, the base class library is strongly recommended.
Note
Before writing a transform filter, consider whether a DirectX Media Object (DMO) would fulfill your requirements. DMOs can do many of the same things as filters, and the programming model for DMOs is simpler. DMOs are hosted in DirectShow through the DMO Wrapper filter, but can also be used outside of DirectShow. DMOs are now the recommended solution for encoders and decoders.
This section includes the following topics:
- Step 1. Choose a Base Class
- Step 2. Declare the Filter Class
- Step 3. Support Media Type Negotiation
- Step 4. Set Allocator Properties
- Step 5. Transform the Image
- Step 6. Add Support for COM
Related topics