Using File Sinks

[The feature associated with this page, Windows Media Format 11 SDK, is a legacy feature. It has been superseded by Source Reader and Sink Writer. Source Reader and Sink Writer have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use Source Reader and Sink Writer instead of Windows Media Format 11 SDK, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

Under normal circumstances, you can simply pass the writer an output file name using the IWMWriter::SetOutputFilename method, and the writer object will write the file to disk automatically. In this case, the writer is actually creating and controlling a writer file sink object that handles writing the file to disk. A writer file sink object controls the flow of data from the writer object to a single file.

You can create your own file sinks to get more control over how the sink writes the file. You can also access the default writer file sink created by the writer in response to a call to SetOutputFilename.

Creating File Sinks

To create a file sink and add it to the writer, perform the following steps.

  1. Create a new sink by calling the WMCreateWriterFileSink function.
  2. Supply a file name for the sink by calling IWMWriterFileSink::Open.
  3. Add the file sink to the writer by calling IWMWriterAdvanced::AddSink.
  4. Perform writing in the usual way.
  5. After writing is completed, the sink will close the file automatically.

Stopping and Starting File Sinks

After writing operations begin, you can stop writing to a file sink by calling IWMWriterFileSink2::Stop.

There are many potential reasons why you would want to stop writing to a sink. For example, if you are recording from a live source, you may only be interested in some of the content.

You can resume writing to a file sink by calling IWMWriterFileSink2::Start. Both Stop and Start use presentation times to control approximately when the command is executed. You can use the IWMWriterFileSink3 methods to gain more control over start and stop times.

Closing File Sinks

Normally, a file sink is closed automatically. If you are finished writing to a sink, but writing operations to other sinks are continuing, you should explicitly close the sink to conserve resources. To close a file sink, call IWMWriterFileSink2::Close.

Getting Sink Statistics

You can get the file size and duration for an open sink by calling IWMWriterFileSink2::GetFileSize and IWMWriterFileSink2::GetFileDuration respectively.

IWMWriterFileSink Interface

IWMWriterFileSink2 Interface

IWMWriterFileSink3 Interface

Writer File Sink Object

Writing ASF Files