Configuring Video Encoding
To configure the video encoder, perform the following steps:
Set any properties on the encoder DMO by using IPropertyBag::Write. The following list summarizes the minimum set of properties that are required to encode a CBR video stream (all of these values have defaults that can be used):
- TheMFPKEY_VIDEOWINDOW property specifies the buffer window to use for the stream. For more information about the buffer windows setting and how it affects content, see Encoding Methods. The default buffer window is three seconds, which is appropriate for many scenarios.
- Video complexity is set to determine the tradeoff between the quality of the encoded content and the time that is required to encode. If you do not set a value, the default value is used. However, you can find the recommended modes for a specific codec by calling IWMCodecProps::GetCodecProp to retrieve g_wszWMVCComplexityExLive, g_wszWMVCComplexityExOffline, and g_wszWMVCComplexityExMax. Then you can set MFPKEY_COMPLEXITYEX to a value between 0 and the reported maximum complexity.
- MFPKEY_CRISP specifies the relative importance of video smoothness and the image quality of encoded frames. In most cases, the default value works fine.
- For video content stored in a container other than ASF, the MFPKEY_ASFOVERHEADPERFRAME property must be set to 0. This is not the default value.
For information about configuring VBR streams, see Using VBR Encoding.
Configure the DMO_MEDIA_TYPE structure for the input type, or if you are using the Media Foundation SDK, use the MFInitMediaTypeFromVideoInfoHeader function. Use a VIDEOINFOHEADER structure describing the uncompressed input content. The codec does not resize video or convert the color space.
Configure the output type for the encoder. After the input type is set, the encoder enumerates output types that are complete except for the dwBitrate member of the VIDEOINFOHEADER structure, or the MF_MT_AVG_BITRATE attribute of the IMFMediaType interface. If you retrieve an output type before setting an input type, the delivered DMO_MEDIA_TYPE structure will not have an associated VIDEOINFOHEADER.
Retrieve the codec private data and append it to the VIDEOINFOHEADER structure that you pass to the DMO_MEDIA_TYPE structure or to IMFMediaType. For more information, see Using Video Codec Private Data.
Set the output type by calling the IMediaObject::SetOutputType or IMFTransform::SetOutputType method. Either pass the DMO_MEDIA_TYPE structure with the completed VIDEOINFOHEADER structure (including appended private data) referenced in the pbFormat member, or construct an IMFMediaType by calling MFInitMediaTypeFromVideoInfoHeader.
The video encoder object supports two outputs. The second output is for encoder "post view". It delivers the uncompressed samples as they will be delivered from the decoder. This enables you to monitor the quality of the encoding without having to wait until the entire stream is processed. This output is optional. If you want to use it, configure its type following the same process used to set the encoder input type.