DirectShow® and Delphi


DirectShow is a Microsoft Windows Application Programming Interface (API) that enables Windows applications to interact with and control Windows "Media" input devices such as camcorders, webcams, DVD drives, TV Tuner cards and Analogue Video capture cards. DirectShow can also be used to play media files and, in the DirectShow model, the media file is simply treated like any other input device.

The versatility of DirectShow is due, in part, to its modular approach. Audio and video are treated as data 'streams' and software 'modules' are able to control and interact with these streams on their passage from the input device - webcam, capture card, etc - to the output device - generally the soundcard, the video monitor or a file.


Video streams are either a sequence of uncompressed RGB bitmaps or a set of numerical values that represent the original images in compressed form. By choosing the correct software 'modules', the programmer is able to ensure the data stream is processed correctly and is displayed (rendered) correctly by the output device.

Audio streams consist of sequences of samples each representing the amplitude of the sound at a given point in time. The number of samples taken in a given period depends on the required audio quality. For example, CD quality audio uses 16-bits to represent each sample and the samples are recorded and played back (rendered) at 44.1 kHz.

Instead of samples representing the actual audio amplitude, compressed audio uses data to represent several samples which have been combined using a specific mathematical formula. Provided the 'inverse' of the same formula (Algorithm) is used further along the stream to de-compress the data, the original sound will be rendered correctly.


Compression is really just a necessary evil to 'fit' the data for a given length of audio or video into an acceptable amount of bandwidth or storage space but media can be processed in an almost unlimited number of ways to enhance or otherwise modify the original input.

This processing is accomplished through software modules that DirectShow calls Filters of which there are three basic kinds: source filters for input, transform filters for any intermediate processing step and renderer filters for output. Although the filters may step into each others' territory at times, transform filters may be better known to you as codecs - compression-decompression. Not a particularly good description because an almost infinite number of different transform filters can perform an almost infinite number of other processes besides just simple compression and de-compression.

Using DirectShow, an application is able to connect filters together in whatever configuration is required. Although, as I mentioned above, the filter's rôles may overlap at times, the basic configuration will always be a source filter to accept input from an external device, one or more transform filters to process the data stream in some way and a renderer filter - usually used to present the data stream to the user.

Filters are COM Objects

If, like me, you have managed to avoid using COM in Delphi, this heading may have come as a bit of a disappointment but, luckily, we don't need much of an understanding of COM to use DirectShow in Delphi. We're already familiar with the concept of Delphi Objects having properties and methods. In COM, we can think of these as Interfaces and all we need for our purposes are one or two simple techniques in order to 'interrogate', or expose these Interfaces.

Follow this link for a very brief introduction to COM. (Especially if you use Delphi 5)

To be honest, the fact that we need a limited understanding of COM programming is the least of our problems! All of the Microsoft DirectShow Documentation (and there's plenty of it!) is written in C++ so we also need to gain some knowledge of programming in that language in order to translate the code to Delphi. There are also some examples written in Visual Basic so, if you're familiar with VB, those examples may be of some assistance.


In common with other Windows API's, using DirectShow consists of making function and procedure calls. As you'll know, Borland has already done the hard work in Delphi's windows.pas by converting many of the Windows API calls into Delphi. Although Borland hasn't converted any of the DirectShow headers for us, we are very fortunate that Henri Gourvest has done so and made the results of his labours available to the rest of us for free. In addition, he and his team have produced several ready-to-run Delphi components which can really make our work easier - particularly the COM Object-creation side of things.

You can download DSPack at the website where you will also find an active forum. (Download link).

Be aware, though, that you may find the forum a little intimidating. What the forum members won't do is provide loads of code for you. They will expect you to have studied the DirectShow documentation at Learning DirectShow (in any programming language, I suspect) is a series of hurdles with faltering steps between.

Update:: It appears that is no longer hosting DSPack or the forum, which is a great shame. Please see this post for an explanation.

DSPack is currently available for download from Google Code.

There's also a DSPack section at StackOverflow.

So, download DSPack and follow the installation notes carefully. Delphi will now have a new Tab on the Components palette and a whole new set of DirectShow components. Equally important, you now have all of the DirectShow headers converted to Delphi for you.

I'm sure we've all, at some time, tried to install a 3rd party component into Delphi only to find it won't install or doesn't compile. Rest assured that DSPack is a tried and tested set of very robust components. If it won't install, read the instructions again - particularly with regard to the Library Paths you need to set in the Delphi IDE and the order in which you install the packages.


Next page...

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12

This site and its contents are © Copyright 2005 - All Rights Reserved.