Share via


Saving Encoded Content to a File

Windows Media Encoder SDK banner art

You can save (or archive) encoded content to a Windows Media file, either concurrently with a broadcast or as the only output. You can also limit the size of the output file that is saved, either by specifying a maximum duration or a maximum file size.

You can also control various aspects of the archival process:

  • You can specify which source groups to archive. For example, if you are encoding a static welcome screen, a live presentation and a static goodbye screen, you might want to archive only the live presentation. By default, source groups are automatically archived, so set the AutoArchive property in IWMEncSourceGroup.AutoArchive to Stop or Pause for those source groups you don't want to archive.
  • To manually start, stop, or pause the archival process, set the Archive method using IWMEncoder or WMEncoder. By default, archiving starts as soon as encoding begins. If you want to manually start the archival process, set the EnableAutoArchive property to false.

The following examples show how to save encoded content to a file using IWMEncFile2. 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

' Declare variables.
  Dim File As IWMEncFile2

' Retrieve an IWMEncFile2 object.
  Set File = Encoder.File

' Specify the output file's path and name.
  File.LocalFileName = "C:\filename.wmv"

' Specify a size limit for the file.
  File.FileSize = (300000/10000)    ' 300 Kb

' Or specify a duration limit.
  File.FileDuration = 20000/10000   ' 20s

C++ Example

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

// Declare variables.
    HRESULT hr;
    IWMEncoder* pEncoder;
    IWMEncFile* pFile;

// Initialize the COM library and retrieve a pointer
// to an IWMEncoder interface.
    if ( SUCCEEDED( hr ) )
    {
        hr = CoCreateInstance( CLSID_WMEncoder,
                           NULL,
                           CLSCTX_INPROC_SERVER,
                           IID_IWMEncoder,
                           (void**) &pEncoder);
    }

// Specify a file in which to save encoded content.
    if ( SUCCEEDED( hr ) )
    {
        hr = pEncoder->get_File(&pFile);
    }
    if ( SUCCEEDED( hr ) )
    {
        hr = pFile->put_LocalFileName(CComBSTR("C:\\filename.wmv"));
    }

    // Release pointers.
    if ( pFile )
    {
        pFile->Release();
        pFile = NULL;
    }
    if ( pEncoder )
    {
        pEncoder->Release();
        pEncoder = NULL;
    }

C# Example

using WMEncoderLib;

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

    // Retrieve an IWMEncFile2 object.
    IWMEncFile2 File = (IWMEncFile2)Encoder.File;

    // Specify the output file's path and name.
    File.LocalFileName = "C:\\OutputFile.wmv";

    // Specify a size limit for the file, in bytes.
    File.FileSize = (300000/10000);    // 300 Kb

    // Or specify a duration limit.
    File.FileDuration = (8000/10000);  // 8 seconds
} 

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

See Also