Assigning Output Formats
[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.]
Some codecs can decompress digital media data into several uncompressed formats. You can find all of the supported formats for a specific output using either the asynchronous reader or the synchronous reader.
To examine all of the available formats for an output, perform the following steps. These procedures are identical for both the asynchronous reader and the synchronous reader. Where interface names vary, the synchronous reader methods are listed in parentheses after the methods of the asynchronous reader.
Create a reader object and load a file for reading. For more information, see To Create a Reader and Open a File (or To Create a Synchronous Reader and Open a File).
Determine the output for which you want to find the available formats. If you don't already know which output you want to use, you can identify the outputs in the file using the procedures in To Identify Output Numbers.
Retrieve the total number of available formats for the desired output by calling IWMReader::GetOutputFormatCount (or IWMSyncReader::GetOutputFormatCount).
Loop through the available formats one at a time, performing the following steps for each:
Retrieve the IWMOutputMediaProps interface for the current output format by calling IWMReader::GetOutputFormat (or IWMSyncReader::GetOutputFormat).
Retrieve the WM_MEDIA_TYPE structure for the output format by making two calls to IWMMediaProps::GetMediaType. Make the first call to get the size of the structure, then allocate memory for it and pass a pointer to the allocated memory on the second call.
Find the media subtype of the output format in WM_MEDIA_TYPE.subtype.
For video, if the current subtype is the format you want to use for output, break out of the loop. Otherwise go to the next iteration.
For audio, you must check the values in the WAVEFORMATEX structure against your requirements. WM_MEDIA_TYPE.pbFormat points to the WAVEFORMATEX structure for audio outputs.
When you have found the output desired, set it for use with the reader by calling IWMReader::SetOutputProps (or IWMSyncReader::SetOutputProps). You must pass a pointer to the IWMOutputMediaProps interface obtained in the first step of the loop.
Related topics