Click here to Skip to main content
12,070,030 members (67,402 online)
Click here to Skip to main content
Add your own
alternative version


78 bookmarked

DirectShow Filters - What They Are

, 16 Sep 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
This article is about DirectShow filters and how to create them


DirectShow is an architecture for media streaming on Windows platform. With its help, you can do the following things:

  • Play a media stream
  • Capture a media stream
  • Media editing

Building Environment

All applications which want to use DirectShow must include the header Dshow.h, and use the library Strmiids.lib.

First Things First - Initialize the COM

DirectShow is based on COM model, therefore it is a must to initialize the COM before using it. You can do it with CoInitialize(). You must also uninitialize the COM after you have finished using COM. You can do it with CoUninitialize(). This means that all DirectShow calls are sandwiched in COM CoInitialize() and CoUninitialize() calls.

Let Us Start a Direct Show

Let us know what is DirectShow.

DirectShow's Building Block "Filters"

As already described, DirectShow is based on COM architecture. DirectShow consists of a wide range of COM objects, which do a specific work (e.g. reading data). These COM objects are called "filters" in DirectShow. DirectShow provides a set of standard filters, and developers can write their own to extend DirectShow. For a simple example, let us examine how an AVI file is played with filters that play a role in this operation.

  • File source filter (Reads data from file)
  • AVI splitter filter (Separates audio and video)
  • Decoder filters (Decodes video frames based on the compression used)
  • Video renderer filter (Draws Video frames)
  • DirectSound Device filter (Sends audio to sound card)

From the above description, it is clear that DirectShow is made of small components which do their work separately from one another, but are joined together to do a complex operation.


As stated, these COM components are joined together to perform an operation, the joining points are also COM objects called "pins".

DirectShow's "Filter Graph"

As you have seen, to play an AVI file approximately five filters have worked together. All these  filters are a must for this operation. And if a single filter gets missed, the file will not be played as required. So a set of filters required to run an operation successfully is called a "Filter Graph".

How to Build a "Filter Graph"

Building a filter graph means, creating appropriate filters and joining them through pins so that they perform the required operation successfully. This sounds like a complex operation, but DirectShow provides components which can help us in building a filter graph. Some are listed below:

  • Filter Graph Manager (Used for file playback and for controlling filter graph)
  • Capture Graph Builder (Used for capturing)
  • DVD Graph Builder (For DVD playback)

DirectShow's Backbone "Filter Graph Manager"

Filter Graph Manager is the basic component in DirectShow, and is used in almost all DirectShow applications. Whether you want to play a file, capture with a device or want a DVD playback, filter graph manager is the component which is a must to create. It is always not necessary to create this object, sometimes it is created for us by some other objects. Filter graph manager does the following things:

  • Provides us ways to build a filter graph (to add, remove, connect filters)
  • Coordinates state changes among filters (play, pause, stop, seek)
  • Handles synchronization of filters (with a reference clock)
  • Does event notification (for applications to know about state changes and other events)

Interfaces Exposed by "Filter Graph Manager"

Following are some of the important interfaces exposed by filter graph manager:

  • IBasicAudio (controls the volume and balance of audio stream)
  • IBasicVideo (sets video properties)
  • IGraphBuilder (help building filter graph)
  • IMediaControl (controls flow of data in filter graph)
  • IMediaEventEx (for event notifications and for overriding default event handling)
  • IMediaSeeking (for seeking a position in stream)
  • IVideoWindow (sets video window properties)

Actual Creation of "Filter Graph Manager"

Step 1 (Creation of Object)

The following code creates an object of filter graph manager and also gives us an interface pointer to IGraphBuilder interface exposed by filter graph manager object.

IGraphBuilder *pGB   = NULL;
                     IID_IGraphBuilder, (void **)&pGB);

In the above code, an instance of filter graph manager is created. Now the actual work starts. You now have to decide who will build the graph. Filter graph manager supports the following ways:

  • Filter Graph Manager builds the entire graph
  • Filter Graph Manager builds the partial graph
  • The application builds the entire graph

Here I am going to use the first method.

Step 2 (Building the Graph Automatically)

IGraphBuilder::RenderFile method is used to build a filter graph automatically for a specified file. In this way, filter graph manager connects appropriate filters for the specified media file. This is called "Intelligent connect" in DirectShow.

// Have the graph builder construct the appropriate graph automatically
      pGB->RenderFile(L"J:\\VIdeo\\ruby.avi", NULL);

Step 3 (Everything is OK, Just RUN)

IMediaControl::Run method is used to start the data flow in filter graph. IMediaControl provides the methods to control data flow in filter graph such as run, pause or stop. You first have to get IMediaControl interface, then just call IMediaControl::Run.

IMediaControl *pMC   = NULL;
pGB->QueryInterface(IID_IMediaControl, (void **)&pMC);

Step 4 (We are Done, Call Release)

After you have finished, just call Release() for the interfaces used in the application to free resources.


Good luck. Happy programming with DirectShow.


  • Sunday 30 July 2006: Just a bare minimum working model


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

tanvon malik
Pakistan Pakistan
tanvon malik ( real name Tanveer Ahmad )I am a CNC Programmer, cnc setter, cnc operator. want to know about me visit my blog.
CNC Programming Blog

Reach Me
cnc blog | facebook | twitter | linkedin | flickr | google+

I been in Switzerland MAG former +FMS+ for CNC training.

Most interesting technologies I like COM MFC DirectShow such as filter development. I am from Pakistan.
Have worked on projects mostly related video capturing, video data processing and real time object tracking on videos. For these I have worked on projects which use "Open CV Library". Which is mostly used for capturing data and its processing.

my vc++ blog tanvon++
my blog about DirectShow in my national language URDU
and below is the place where we discuss DirectShow and VC++

You may also be interested in...

Comments and Discussions

QuestionGood Review Pin
h.ahmadi8628-May-14 4:57
memberh.ahmadi8628-May-14 4:57 
QuestionHow Can I Render To A Section Of The Screen? Pin
Member 98407435-Feb-14 20:18
memberMember 98407435-Feb-14 20:18 
GeneralScreen capture using Windows media encoder and render it using direct show.. Pin
kalyanikalakonda9-Jul-09 0:44
memberkalyanikalakonda9-Jul-09 0:44 
GeneralLive audio/video stream capture Pin
kazim bhai8-Jun-09 2:38
memberkazim bhai8-Jun-09 2:38 
Questionrequirements to run a direct show mobile 5.0 application Pin
sreejit P1-Oct-08 1:52
membersreejit P1-Oct-08 1:52 
Generalnice tutorial Pin
whitehat.c7-Sep-08 23:32
memberwhitehat.c7-Sep-08 23:32 
GeneralI want to take the codec name from a filter... Pin
Vasi Floroiu20-Aug-08 0:30
memberVasi Floroiu20-Aug-08 0:30 
GeneralMultiple Sample Grabber Objects Pin
kazim bhai11-Jun-08 6:42
memberkazim bhai11-Jun-08 6:42 
QuestionWhat Filter to use for mms stream? Pin
ajovanov26-Mar-08 9:13
memberajovanov26-Mar-08 9:13 
QuestionSound filter ? Pin
Sukhjinder_K24-Aug-07 2:47
memberSukhjinder_K24-Aug-07 2:47 
Questionhelp me Pin
vikram panwar25-Jul-07 23:43
membervikram panwar25-Jul-07 23:43 
QuestionDirectShow and Windows Media Encoder Pin
shfnet21-Apr-07 22:52
membershfnet21-Apr-07 22:52 
QuestionRe: DirectShow and Windows Media Encoder Pin
fatihsen14-Jun-07 5:34
memberfatihsen14-Jun-07 5:34 
AnswerRe: DirectShow and Windows Media Encoder Pin
jcaple@cisco.com19-Jul-07 12:24
memberjcaple@cisco.com19-Jul-07 12:24 
Generalhey... Pin
emadpejman2-Feb-07 1:31
memberemadpejman2-Feb-07 1:31 
GeneralRe: hey... Pin
FlyingTinman26-Feb-07 13:58
memberFlyingTinman26-Feb-07 13:58 
GeneralRe: hey... Pin
tanvon malik6-Sep-08 22:52
membertanvon malik6-Sep-08 22:52 
GeneralRegarding adding Transform filter Pin
ericlnl7-Jan-07 21:26
memberericlnl7-Jan-07 21:26 
GeneralFastforward / Rewind of Playback Pin
Cookie80825-Oct-06 4:30
memberCookie80825-Oct-06 4:30 
GeneralRe: Fastforward / Rewind of Playback Pin
tanvon25-Oct-06 6:41
membertanvon25-Oct-06 6:41 
GeneralRe: Fastforward / Rewind of Playback Pin
Cookie80825-Oct-06 8:03
memberCookie80825-Oct-06 8:03 
GeneralRe: Fastforward / Rewind of Playback Pin
tanvon25-Oct-06 20:36
membertanvon25-Oct-06 20:36 
Generalmp3 Pin
surfman1917-Sep-06 14:36
membersurfman1917-Sep-06 14:36 
GeneralRe: mp3 Pin
Tanvon17-Sep-06 16:12
memberTanvon17-Sep-06 16:12 
QuestionMulti player Pin
tokayadmin29-Aug-06 3:57
membertokayadmin29-Aug-06 3:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.160208.1 | Last Updated 16 Sep 2006
Article Copyright 2006 by tanvon malik
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid