Writing a Windows Media File in DES

[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 API is not supported and may be altered or unavailable in the future.]

This section describes how to write a Windows Media file using DirectShow Editing Services (DES).

Important

Do not use the Smart Render Engine to write Windows Media files. Always use the Basic Render Engine (CLSID_RenderEngine).

 

To write a Windows Media file, do the following:

  1. Call SetSite on the render engine, with a pointer to your key provider.

  2. Build the front end of the graph. (See Rendering a Project.)

  3. Create the WM ASF Writer filter and add it to the graph.

  4. Use the IFileSinkFilter interface on the WM ASF Writer filter to set the file name.

  5. Configure the WM ASF Writer to use a Windows Media profile. Each profile has a predefined number of streams. You must choose a profile that matches the groups in your project.

    The IConfigAsfWriter interface contains a few different methods for setting the profile. For example, the ConfigureFilterUsingProfileGuid method specifies a system profile as a GUID. Or, you can use Windows Media Format methods to get an IWMProfile pointer and then call IConfigAsfWriter::ConfigureFilterUsingProfile. For more information, see Configuring the ASF Writer.

  6. Connect the front end to the ASF Writer. The front end of the graph contains one output pin for each group. Assuming that you specified a compatible profile, the ASF Writer should have a matching set of input pins. Connect each output pin to the corresponding input pin. The easiest way to do this is using the ICaptureGraphBuilder2::RenderStream method. First, create a new instance of the Capture Graph Builder and initialize it with a pointer to the Filter Graph Manager:

    ICaptureGraphBuilder2 *pBuild = 0;
    hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, 0, CLSCTX_INPROC_SERVER,
        IID_ICaptureGraphBuilder2, (void**)&pBuild);
    pBuild->SetFiltergraph(pGraph); 
    

    Next, retrieve the output pin for each group by calling the IRenderEngine::GetGroupOutputPin method. Call RenderStream to connect the pin to the ASF Writer:

    long cGroups = 0;
    hr = pTimeline->GetGroupCount(&cGroups);
    for (long i = 0; i < cGroups; i++)
    {
        IPin *pPin;
        hr = pRenderEngine->GetGroupOutputPin(i, &pPin);
        if (SUCCEEDED(hr))
        {
            hr = pBuild->RenderStream(0, 0, pPin, 0, pASF);
        }
        pPin->Release();
    }
    pBuild->Release
    

Using Windows Media With DirectShow Editing Services