Using the Sink Writer

Overview

File Container Types

The sink writer has built-in support for several file container types. For a complete list, see MF_TRANSCODE_CONTAINERTYPE. You can support additional container types by writing a custom media sink. The file container is specified when you create a new instance of the sink writer.

Stream Formats

For each stream, the application must specify the following.

  • The input format is the format that the application sends to the sink writer.
  • The output format is the format that will be written to the file.

The input and output formats can be either compressed or uncompressed. The sink writer supports the following combinations:

  • Uncompressed input with compressed output. This is the typical case, and is used for encoding or transcoding scenarios. A Microsoft Media Foundation encoder must be available that accepts the input type and encodes to the output type.
  • Compressed input with identical output. Use this combination to remux a file without transcoding.
  • Uncompressed input with identical output. Use this combination to write uncompressed audio or video to a file container.

The sink writer does not support video resizing, frame-rate conversion, or audio resampling, unless these functions are provided by the encoder. Otherwise, the application can use Digital Signal Processors to convert the input data, before sending the data to the

Creating the Sink Writer

There are two functions that create the sink writer:

If you are using one of the built-in media sinks, the MFCreateSinkWriterFromURL function is preferable, because the caller does not need to configure the media sink.

The MFCreateSinkWriterFromURL method provides several options for specifying the type of file container. In the simplest case, the function uses the file name extension in the URL to select the file container. For details, refer to the function reference page.

For example, the following code specifies the file name "output.wmv" for the URL. Based on the file name extension, the sink writer will load the ASF Media Sink to create an Advanced Systems Format (ASF) file.

    HRESULT hr = MFCreateSinkWriterFromURL(L"output.wmv", NULL, NULL, &pSinkWriter);

In the case of MFCreateSinkWriterFromMediaSink, the file type is determined by the media sink.

Sink Writer