Rediger

Del via


Writing Streams with Non-Square Pixels

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

There are two ways to create video streams with non-square pixels that will be displayed correctly in Windows Media Player. The first technique involves setting stream-level attributes in the file header. The second technique involves adding a data unit extension to a stream in the profile, and then setting a value for it in every sample that is written.

To Use Stream-level Header Attributes to Set Pixel Aspect Ratio

  1. Set up the writer object. For more information, see Writing ASF Files.
  2. Create or load a profile with one or more video streams. For more information, see To Use Profiles with the Writer.
  3. Call IWMWriter::SetProfile. (Always call this method before setting any header attributes.)
  4. Call QueryInterface to obtain the IWMHeaderInfo3 interface and call AddAttribute twice to add AspectRatioX and AspectRatioY as stream-level attributes of the video stream. These attributes are DWORD values.
  5. Write the file.

To Use Data Unit Extensions to Set Pixel Aspect Ratio

Before writing:

  1. Set up the writer object. For more information, see Writing ASF Files.
  2. Create or load a profile with one or more video streams. For more information, see To Use Profiles with the Writer.
  3. For each stream (of any media type) in the profile, call IWMStreamConfig::SetStreamName to specify a unique name of your choice. Do not give two streams the same name.
  4. Use IWMStreamConfig2::AddDataUnitExtension on the video stream to add a data unit extension for pixel aspect ratio.
  5. Call IWMWriter::SetProfile.
  6. Write the file.

While writing:

  • For each sample, call INSSBuffer3::SetProperty and specify the WM_SampleExtensionGUID_PixelAspectRatio property along with the correct value. Aspect ratio values are written as two concatenated two-digit values. For example, 16:9 is written as 1609 or 0x0649. This is always a 2-byte value.

To Read and Write Video Streams with Non-Square Pixels