Configuring Video Streams

[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.]

Video streams are more flexible in their configuration than audio streams. This is because the properties of the frames that make up the video can vary widely from one file to the next. When you retrieve the codec format for the codec you are using, you must set the following values for video stream configuration objects.

Value Description
Bit rate Call IWMStreamConfig::SetBitrate to set to the desired value. The video codec will try to compress the media to meet your specifications. If your values are too low, the resulting compressed video will be very degraded.
Buffer window Call IWMStreamConfig::SetBufferWindow to set to the desired value. The video codec will try to compress the media to meet your specifications. If your values are too low, the resulting compressed video will be very degraded.
WMVIDEOINFOHEADER.rcSource The upper left corner must be set to 0,0. The lower right corner must be set to the frame dimensions. For example, in a 640x480 stream, these settings would be 0,0,640,480.
WMVIDEOINFOHEADER.rcTarget Must match rcSource.
WMVIDEOINFOHEADER.dwBitRate Must match the bit rate set for the stream.
WMVIDEOINFOHEADER.AvgTimePerFrame Set to the approximate time per frame.
BITMAPINFOHEADER.biWidth Set to the width, in pixels, of the desired frame size.
BITMAPINFOHEADER.biHeight Set to the height, in pixels, of the desired frame size.

 

Video content does not play correctly unless it is encoded to a size that is a multiple of four for both width and height. The exception is RGB uncompressed video, which can be any size. If you try to set a size that is not a multiple of four, one of the following errors will be returned by the writer:

  • NS_E_INVALID_INPUT_FORMAT
  • NS_E_INVALID_OUTPUT_FORMAT
  • NS_E_INVALIDPROFILE

If you are using variable bit rate encoding, you may need to make other adjustments. For more information, see Configuring VBR Streams.

Some Windows Media Video codecs support multiple complexity levels. Complexity levels determine the algorithms that the codec will use when encoding a video stream. Using a high complexity level will require more processing power for encoding and decoding.

Each codec that supports complexity settings exposes the following settings that you can retrieve with the IWMCodecInfo3::GetCodecProp method.

Setting Description
g_wszComplexityMax The maximum quality level supported by the codec.
g_wszComplexityOffline The suggested quality level for offline playback.
g_wszComplexityLive The suggested quality level for streaming playback.

 

To set the complexity for a video stream in a profile, use the IWMPropertyVault::SetProperty method using the property g_wszComplexity. The value you set must be less than or equal to the maximum supported complexity for the codec.

Configuration Common to All Streams

Configuring Streams

Video Complexity Settings