Click here to Skip to main content
Click here to Skip to main content

DirectShow Editing Services (DES) and combining AVI files

, 9 Sep 2011
Rate this:
Please Sign up or sign in to vote.
A sample C++ project that uses DES to combine two or more AVI files.

DESCombine.gif

Introduction

One of my first DirectShow (DS) projects was to use DirectShow Editing Services (DES) to combine multiple media (.AVI) files. I was unable to find a complete C++ project that used DES and so wrote several test programs based on the DES documentation. Not surprisingly, none of them worked. I subsequently discovered DirectShowNet (http://directshownet.sourceforge.net/about.html) that includes the sample DESCombine project which illustrates many of the DES concepts. The code is written in C# and VB. I ported it to C++ and, not surprisingly, it too did not work - the devil was in the details. It was only after many pots of coffee and a support call to Microsoft that I was able to get this C++ version working.

Writing a DS/DES application is a non-trial task for those new to writing multimedia applications. There are more than a few obvious reasons but one that I found most surprising is just how difficult it can be to simply understand why your application does not work. For example, I have received error codes that were so obscure as to be meaningless. Your best friend at such a time is a working test project that you can use for comparison purposes. The C# version of DESCombine was helpful but what I really needed when I first started was a C++ version. I am making my C++ version available as a small way of giving back to the development community and hopefully being of some help to other DS/DES newbies.

Running the sample program

  1. Make three copies of the demo.avi file in the avi directory because these copies will be used as input. (Note: My requirements were that all media files had the same number and sequence of media streams).
  2. You can run DSCombine.exe in the bin directory. Or, if you wish to compile and run this test project in VS2008, then you need to:
    1. Install VS2008, Windows SDK V7.0A, and DirectX (August, 2007).
    2. Run VS2008 under an Administrative account. The project can then enable the DS base class debug/logging feature (i.e., DbgInitialise/DbgTerminate), providing of course, you make the relevant Registry changes. More specifically, running this application the first time will create the following keys in the Registry:
    3. [HKLM][Software][Microsoft][DirectShow][DESCombine.dll] and [HKLM][Software][Microsoft][DirectShow][DESCombineTest.exe]

      You can then set the logging level in the Registry for each of the different test categories. The implementation details can be found in the DS base class file wxdebug.cpp.

    4. Set the 03 DESCombine Test project configuration options:
    5. Set [Configuration Properties][Debugging][Working Directory] to $OutputSet [Configuration Properties][Link][Additional Library Directories] to $Output

  3. In the main window, click on the Add button. This will display a standard Windows file selection window. Select the three copies of the demo.avi file that you created in Step 1. Click on the Save button.
  4. The media file data interval dialog will be displayed and here you enter the start/end time interval (in seconds) to specify what part of the media files will be processed. Default start/end times of 0 and -1 indicate the entire files will be processed. Click on the OK button to return to the main window.
  5. You can preview the selected media files by clicking on the Preview radio button. Alternatively, to have the media files combined into a single output file, click on the To AVI radio button. In this case, you can select the name of the output file by clicking on the ellipsis (...) button.
  6. Click on the Combine Files button to begin processing the selected media files. If the Preview button has been selected then two video streams will be displayed as illustrated in the above image. You should also hear the accompanying audio. If instead, the To AVI radio button has been selected, then the combined media will be output to an AVI file and the GUI will only display the list of DS event notification codes.

Points of interest

The main class that invokes DES is DESCombine (see the file DESCombine.cpp in the project 02 DESCombine - DLL). The key steps in using this class are as follows:

  1. The class is initialized by calling the member function DESCombine::initialize with the names of the input files.
  2. The next function to be called is determined by whether DES will render to a window or an output file. To preview, call the member function DESCombine::renderToWindow. To write the combined input files to a single media file, call the member function DESCombine::renderToAVI.
  3. To begin processing the input files, call the member function DESCombine::startRendering.

You can find this sequence of function calls is performed in CCombineFilesDLG::_initialize() of the test project 03 DESCombine Test. These are important functions that new DES users will probably want to pay particular attention to.

If you compare this C++ version to the C# version, then you will find there are some differences which reflect my preferences:

  1. The C# version creates a dedicated thread (DESCombine::EventWait()) to poll or query for events while DES performs its work. In contrast, this C++ version enables event notification using a message handler as described in the MSDN documentation.
  2. This C++ version adds a number of helper classes (e.g., InputFiles, StreamInformation, and VideoInformation).
  3. Both the C# and C++ versions use the MyCallback::BufferCB() callback function to monitor the progress of DES. The C# version directly updates the GUI fields while this C++ version posts messages to the parent window so that the parent window is responsible for updating the GUI fields.

File compression

If the To AVI radio button is selected so that DES renders the timeline to an output file, then the output file will contain uncompressed media and be quite large. To enable file compression, the K-Lite Codec Pack must first be installed on the computer. Once installed, the constant COMPRESS_OUTPUT_FILE must be set to a non-zero value in the file CombineFilesDLG.cpp in the 03 DESCombine Test project.

A hiccup

This project was written as a way of learning and testing DES. In the end, the decision was made not to use DES and I stopped working on this test project. There is one outstanding problem that I am aware of. Occasionally, DES would immediately stop when it begins processing the first file. When this happens, I just close the window (i.e., click on the Close button) and restart the process again (i.e., click on the Combine files button). This project will nevertheless serve as a valuable starting point for anyone starting to use DES.

License

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

Share

About the Author

Ian00Bell
Sales Bell Canada
Canada Canada
No Biography provided

Comments and Discussions

 
QuestionDES not good? PinmemberWolfgang_Baron27-Sep-11 20:44 
AnswerRe: DES not good? PinmemberIan00Bell28-Sep-11 4:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web04 | 2.8.140827.1 | Last Updated 9 Sep 2011
Article Copyright 2011 by Ian00Bell
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid