Microsoft DirectX 9.0

Writing a Windows Media File in DES

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