I want to implement SinkWriter to encode RGB32 screen frames with Windows Media Video 9 Screen Encoder (MSS2) using Media Foundation. After running the program in Visual Studio 2022, I encountered the following problem when executing IMFSinkWriter::SetInputMediaType
:
0xc00d5212 : No suitable transform was found to encode or decode the content.
I think I included all necessary headers and libraries. I also checked that I have WMVSENCD.DLL file in the System32 folder. When I run this code for H264 encoder and MP4 file, it works well. Do you have any idea how to solve this problem?
Here is my code:
HRESULT MediaFoundationScreenRecorder::InitializeSinkWriter(IMFSinkWriter** ppWriter, DWORD* pStreamIndex)
{
*ppWriter = NULL;
*pStreamIndex = NULL;
IMFSinkWriter* pSinkWriter = NULL;
IMFMediaType* pMediaTypeOut = NULL;
IMFMediaType* pMediaTypeIn = NULL;
DWORD streamIndex;
HRESULT hr = MFCreateSinkWriterFromURL(L"mfoutput.wmv", NULL, NULL, &pSinkWriter);
hr |= MFCreateMediaType(&pMediaTypeOut);
hr |= pMediaTypeOut->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
hr |= pMediaTypeOut->SetGUID(MF_MT_SUBTYPE, MEDIASUBTYPE_MSS2);
hr |= pMediaTypeOut->SetUINT32(MF_MT_AVG_BITRATE, 800000);
hr |= pMediaTypeOut->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
hr |= MFSetAttributeSize(pMediaTypeOut, MF_MT_FRAME_SIZE, SCALED_VIDEO_WIDTH, SCALED_VIDEO_HEIGHT);
hr |= MFSetAttributeRatio(pMediaTypeOut, MF_MT_FRAME_RATE, VIDEO_FPS, 1);
hr |= MFSetAttributeRatio(pMediaTypeOut, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
hr |= pSinkWriter->AddStream(pMediaTypeOut, &streamIndex);
hr |= MFCreateMediaType(&pMediaTypeIn);
hr |= pMediaTypeIn->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video);
hr |= pMediaTypeIn->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB32);
hr |= pMediaTypeIn->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
hr |= MFSetAttributeSize(pMediaTypeIn, MF_MT_FRAME_SIZE, SCALED_VIDEO_WIDTH, SCALED_VIDEO_HEIGHT);
hr |= MFSetAttributeRatio(pMediaTypeIn, MF_MT_FRAME_RATE, VIDEO_FPS, 1);
hr |= MFSetAttributeRatio(pMediaTypeIn, MF_MT_PIXEL_ASPECT_RATIO, 1, 1);
hr |= pSinkWriter->SetInputMediaType(streamIndex, pMediaTypeIn, NULL);
hr |= pSinkWriter->BeginWriting();
if (SUCCEEDED(hr))
{
*ppWriter = pSinkWriter;
(*ppWriter)->AddRef();
*pStreamIndex = streamIndex;
}
SafeRelease(&pSinkWriter);
SafeRelease(&pMediaTypeOut);
SafeRelease(&pMediaTypeIn);
return hr;
}
Your question boils down to the following: is MSS2 at all a supported format for this API?
Sink Writer is a convenience layer API over encoders and sinks. When you requests a .wmv sink writer, the API creates an ASF Media Sink internally and then tries to fit the MFVideoFormat_MSS2
format you requested there.
I am not confident that MSS2 is supported, for example Windows Media Encoders does not mention it as a listed format.
My guess that even if there is a chance to configured the internal pipeline to produce MSS2 recording, for what there is no proof or documentation reference, it might still be unable to achieve this via Sink Writer API.
At least I browsed through MSDN pages a bit, and I don't see an clear statement for codec support even for internal level of pipeline primitives. I would say screen codec is just not a supported scenario for Sink Writer API and you would have to put more of your own effort to get files in this encoding with Media Foundation.