To Force Key-Frame Insertion

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

The Windows Media Video 9 codec supports forced key-frame insertion. When you pass a sample to the writer, you can specify that it must be encoded as a key frame.

To force key-frame insertion for a sample, perform the following steps.

  1. Allocate a buffer to hold the sample, and retrieve a pointer to the INSSBuffer interface containing the buffer by calling IWMWriter::AllocateSample.
  2. Retrieve the location and size of the buffer created in step 1 by calling INSSBuffer::GetBufferAndLength.
  3. Copy your sample data to the buffer location, making sure that the sample passed will fit in the allocated buffer. Depending upon the source of your samples, you can use a variety of functions to copy the data. For example, if you are copying a stream from an AVI file, you can use the AVI function, AVIStreamRead.
  4. Update the amount of data used in the buffer to reflect the actual size of the sample by calling INSSBuffer::SetLength.
  5. Obtain a pointer to the INSSBuffer3 interface by calling INSSBuffer::QueryInterface.
  6. Set the sample as a forced key frame by calling the INSSBuffer3::SetProperty method to set the WM_SampleExtensionGUID_OutputCleanPoint property. This property is a Boolean value; set it to TRUE.
  7. Pass the buffer interface to the writer along with the input number and sample time by using the IWMWriter::WriteSample method.

IWMWriter::WriteSample

To Write Samples

Variable Bit Rate (VBR) Encoding

Writing ASF Files