Share via


Using Transform Plug-Ins

Windows Media Encoder SDK banner art

The Windows Media Encoder 9 Series SDK enables developers to write transform plug-ins that customize and build upon encoding functionality. Windows Media Encoder supports Microsoft DirectShow® and Microsoft DirectX® Media Objects (DMO) transform filters by providing a wrapper plug-in.

At this time, you must register plug-ins using the Plug-ins tab in the Session Properties panel in Windows Media Encoder. Then the plug-ins can be used in the Windows Media Encoder SDK. IWMEncTransformPluginInfoManager manages the plug-ins that have been registered. Use IWMEncPluginInfo to retrieve information about a specific plug-in.

Transform plug-ins can be applied to an individual source stream, to an entire source group, or both. You can determine the plug-in type by using the transform flags property in IWMEncPluginInfo.

To use a transform plug-in:

  1. Using IWMEncTransformCollection, retrieve the transform collection from the source or the source group, depending on the type of plug-in that you are using:
    • When using a stream-level plug-in, use the transform collection property in IWMEncSource.
    • When using a group-level plug-in, use the group-transform collection property in IWMEncSourceGroup.
  2. Add a transform plug-in to the collection using IWMEncTransform.

The following Visual Basic and C# examples show how to apply a stream-level plug-in, while the C++ example shows how to apply a group-level plug-in. For end-to-end code examples, see Complete Code Examples.

Visual Basic Example

' Create a WMEncoder object.
Dim Encoder As WMEncoder
Set Encoder = New WMEncoder

' Configure the profile and an audio source.

' Retrieve the transform collection from the audio source.
Dim SrcTrnsColl As IWMEncTransformCollection
Set SrcTrnsColl = SrcAud.TransformCollection

' Add a transform plug-in to the collection.
Dim Trans As IWMEncTransform
Set Trans = SrcTrnsColl.Add

' Apply a DMO Audio Transform Filter to the source.
Trans.SetInput "PluginWrapperForDMO://Echo"

' Add another DMO Audio Transform Filter.
Set Trans = SrcTrnsColl.Add
Trans.SetInput "PluginWrapperForDMO://Gargle"

' Display the names of the plug-ins in the current source collection.
Dim sScheme As String, sDataInit As String
For i = 0 To SrcTrnsColl.Count – 1
  MsgBox SrcTrnsColl.Item(i).GetInput(sScheme , sDataInit)
Next i

C++ Example

// Include libraries.
#include <windows.h>
#include <atlbase.h>
#include "wmencode.h"

    // Declare variables.
    HRESULT hr;
    IWMEncoder* pEncoder;
    IWMEncSourceGroupCollection* pSrcGrpColl;
    IWMEncSourceGroup* pSrcGrp;
    IWMEncSource* pAudSrc;
    IWMEncSource* pVidSrc;
    IWMEncTransformCollection* pTransColl;
    IWMEncTransform* pTransform;

// Initialize the COM library and retrieve a pointer
// to an IWMEncoder interface.

hr = CoInitialize(NULL);

if ( SUCCEEDED( hr ) )
{
    hr = CoCreateInstance(CLSID_WMEncoder,
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          IID_IWMEncoder,
                          (void**) &pEncoder);
}

// Retrieve a pointer to an IWMEncSourceGroupCollection
// interface.
if ( SUCCEEDED( hr ) )
{
    hr = pEncoder->get_SourceGroupCollection(&pSrcGrpColl);
}

// Add a source group to the collection.
if ( SUCCEEDED( hr ) )
{
    hr = pSrcGrpColl->Add(CComBSTR("SG_1"), &pSrcGrp);
}

// Add a video and audio source to the source group.
if ( SUCCEEDED( hr ) )
{
    hr = pSrcGrp->AddSource(WMENC_VIDEO, &pVidSrc);
}

if ( SUCCEEDED( hr ) )
{
    hr = pSrcGrp->AddSource(WMENC_AUDIO, &pAudSrc);
}

// Retrieve the transform collection from the source group.
if ( SUCCEEDED( hr ) )
{
    hr = pSrcGrp->get_GroupTransformCollection(&pTransColl);
}

// Add an IWMEncTransform object to the collection.
if ( SUCCEEDED( hr ) )
{
    hr = pTransColl->Add(&pTransform);
}

// Set the time compression plug-in for the source group.
if ( SUCCEEDED( hr ) )
{
    hr = pTransform->SetInput(CComBSTR("TCGroupTransformPlugin://TimeCompression1"));
}

// Retrieve the name of the transform plug-in.
    CComBSTR bstrScheme;
    CComBSTR bstrInitData;
    CComBSTR bstrTransName;

if ( SUCCEEDED( hr ) )
{
    hr = pTransform->GetInput(&bstrScheme,&bstrInitData, &bstrTransName);
}

// Release pointers.
if ( pSrcGrpColl )
{
    pSrcGrpColl->Release();
    pSrcGrpColl = NULL;
}
if ( pSrcGrp )
{
    pSrcGrp->Release();
    pSrcGrp = NULL;
}
if ( pAudSrc )
{
    pAudSrc->Release();
    pAudSrc = NULL;
}
if ( pVidSrc )
{
    pVidSrc->Release();
    pVidSrc = NULL;
}
if ( pTransColl )
{
    pTransColl->Release();
    pTransColl = NULL;
}
if ( pTransform )
{
    pTransform->Release();
    pTransform = NULL;
}
if ( pEncoder )
{
    pEncoder->Release();
    pEncoder = NULL;
}

C# Example

using WMEncoderLib;

try
{
  // Create a WMEncoder object.
  WMEncoder Encoder;
  Encoder = new WMEncoder();

  // Configure the profile and an audio source.

  // Retrieve the transform collection from the audio source.
  IWMEncTransformCollection SrcTrnsColl;
  SrcTrnsColl = SrcAud.TransformCollection;

  // Add a transform plug-in to the collection.
  IWMEncTransform Trans;
  Trans = SrcTrnsColl.Add();

  // Apply a DMO Audio Transform Filter to the source.
  Trans.SetInput("Echo", "PluginWrapperForDMO", "");

  // Add another DMO Audio Transform Filter.
  Trans = SrcTrnsColl.Add();
  Trans.SetInput("Gargle", "PluginWrapperForDMO", "");

  // Retrieve the name of the plug-ins in the current source collection.
  string sName;
  string sScheme;
  string sInitData;
  for (i = 0; i < SrcTrnsColl.Count; i++)
  {
    sName = SrcTrnsColl.Item(i).GetInput(out sScheme, out sInitData);
  }
}

catch (Exception e)
{
  // TODO: Handle exceptions.
}

See Also