Tutorials‎ > ‎

DirectShow Video Player

posted Aug 28, 2014, 12:30 AM by Muhammad Zullidar   [ updated Aug 15, 2016, 11:29 PM by Surya Wang ]

Directshow is a media-streaming architecture for Microsoft Windows. Using Directshow, our application can perform high-quality video and audio playback or capture.
Directshow is based on the Component Object Model (COM). Directshow is designed for C++. Microsoft does not provide a managed API for DirectShow.
Directshow simplifies media playback, format conversion, and capture tasks. At the same time, it provides access to the underlying stream control architecture for applications that require custom solutions.
To make a DirectShow application, you have to use Dshow.h header. And you also need the static library files such as Strmiids.lib, Quartz.lib.
The building block of Directshow is a software component called a filter. A filter is a software component that performs some operation on a multimedia stream.
In this tutorial, we will make a simple video player using DirectShow. This video player also can do reverse playback. To do reverse playback, we need third party filter, called Multi-Format Source DirectShow by Medialooks. We use MFC to build the program, but in this tutorial, i'll just explain about how to make the video player using Directshow, but the User interface code, you can see it in the project that i attach in this tutorial.
For your information, i use Visual Studio 2012, Windows SDK v7.0, Multi-Format Source Medialooks (Download it at http://www.medialooks.com/directshow/mfs/). Remember to install the Multi-Format Source DirectShow filter first before you start code.
This is the preview of the application:

Here is the tutorial :
  1. To make a video player using DirectShow, we create an instance of Filter Graph Manager, use the Filter Graph Manager to build a filter graph, and run the graph. Run the graph causing data to move through the filters. Call CoCreateInstance to create the Filter Graph Manager. The call to CoCreateInstance returns the IGraphBuilder interface, which mostly contains methods for building the filter graph.
    There are four interfaces that we used to make this application. There are IMediaControl, IMediaEventEx, IMediaSeeking, IFilterGraph2.
    • IMediaControl control streaming. It contains methods for stopping and starting the graph.
    • IMediaEventEx has methods for getting events from the Filter Graph Manager.
    • IMediaSeeking has methods to setting rate of the video, set the position of the video, etc.
    • IFilterGraph2 is used to render filters pin.
    Here is the code how to make the Filter Graph Manager:

    After we have already make the Filter Graph Manager, then we add some filters into the graph.
  2. We already make a filter graph. Now we have to add some filters into the filter graph. We have to know how the filter graph will looks like. Here is the picture of filter graph:

    After we look at the picture above, we can conclude that we need Multi-Format Source DirectShow Filter, Video Mixing Renderer 9, and Default DirectSound Device. Here is the code about how to create instance of MFS DS Filter and add it into the graph:

    After we add MFS to filter, then we two renderers, audio renderer and video renderer. For video renderer, we use Video Mixing Renderer 9. To create video renderer's instance, add it to filter graph and then set some rendering mode and control to VMR9, we can use this code:

  3. And after we finish adding video renderer to filter graph, then we add the audio renderer. we use Direct Sound Renderer and add it to the filter graph. Here is the code:

  4. We already have filter graph and the filters. Now, it's time to connect each filter pins. First, we enumerate medialooks pins and then connect the output pin to the existing renderers that we have added to the filter graph before. Here is the code to enumerate the pin and then connect the medialooks's video and audio pins to existing renderers:

  5. After we connect those pins, then we have to make sure that the input pin of two renderers have been connected with output pin of medialooks. So we take a look at the code:

    From the code above, we can see a function that being called twice. It's RemoveUnconnectedRenderer(). Here is the code of RemoveUnconnectedRenderer() function:

We have already done making a video player application. Now, we make a play, reverse, stop, rewindtostart, and pause functions. Here is the code:

Now you know how to make video player using DirectShow and Medialooks. Here i attached the project that you can download and try it. Hope this tutorial helps you.
Muhammad Zullidar,
Aug 28, 2014, 12:30 AM