Assigning Input 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.]
When you have identified the input format that matches your data, you can set it for use by the writer by calling IWMWriter::SetInputProps.
For video streams, you must set the size of the frames in the input samples. The following example code demonstrates how to configure and set a video input. It uses the FindInputFormat function defined in the To Enumerate Input Formats section to get the input format for 24-bit RGB video. For more information about using this code, see Using the Code Examples.
HRESULT ConfigureVideoInput(IWMWriter* pWriter,
DWORD dwInput,
GUID guidSubType,
LONG lFrameWidth,
LONG lFrameHeight)
{
DWORD cbSize = 0;
LONG lStride = 0;
IWMInputMediaProps* pProps = NULL;
WM_MEDIA_TYPE* pType = NULL;
WMVIDEOINFOHEADER* pVidHdr = NULL;
BITMAPINFOHEADER* pbmi = NULL;
// Get the base input format for the required subtype.
HRESULT hr = FindInputFormat(pWriter, dwInput, guidSubType, &pProps);
if (FAILED(hr))
{
goto Exit;
}
// Get the size of the media type structure.
hr = pProps->GetMediaType(NULL, &cbSize);
if (FAILED(hr))
{
goto Exit;
}
// Allocate memory for the media type structure.
pType = (WM_MEDIA_TYPE*) new (std::nothrow) BYTE[cbSize];
if (pType == NULL)
{
hr = E_OUTOFMEMORY;
goto Exit;
}
// Get the media type structure.
hr = pProps->GetMediaType(pType, &cbSize);
if (FAILED(hr))
{
goto Exit;
}
// Adjust the format to match your source images.
// First set pointers to the video structures.
pVidHdr = (WMVIDEOINFOHEADER*) pType->pbFormat;
pbmi = &(pVidHdr->bmiHeader);
pbmi->biWidth = lFrameWidth;
pbmi->biHeight = lFrameHeight;
// Stride = (width * bytes/pixel), rounded to the next DWORD boundary.
lStride = (lFrameWidth * (pbmi->biBitCount / 8) + 3) & ~3;
// Image size = stride * height.
pbmi->biSizeImage = lFrameHeight * lStride;
// Apply the adjusted type to the video input.
hr = pProps->SetMediaType(pType);
if (FAILED(hr))
{
goto Exit;
}
hr = pWriter->SetInputProps(dwInput, pProps);
Exit:
delete [] pType;
SAFE_RELEASE(pProps);
return hr;
}
Related topics