I have a UVC device that outputs in YUV and MJPEG formats. I am trying to capture data in both formats,I can successfully obtain YUV data, but I fail to capture MJPEG data.
The StartPreview call asynchronously returns an error: No suitable transform was found to encode or decode the content,Is it that mfcaptureengine cannot output compressed formats?Thank you very much for any answers and help

This is Set Device MediaType:
bool CameraClass::SetCurMediaType(MediaTypeInfoEx Type)
{
MediaTypeInfoEx Out;
if (!DeviceIsOpen())
{
return false;
}
HRESULT hr = S_OK;
DWORD dwIndex = 0;
IMFMediaType* pMediaType = NULL;
IMFMediaType* pMediaType2 = NULL;
ComPtr < IMFCaptureSink> pSink = NULL;
// 获取第一个视频流的媒体类型
hr = CaptureSource->GetCurrentDeviceMediaType(
MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_VIDEO_PREVIEW, // 第一个视频流
&pMediaType // 接收媒体类型
);
while (SUCCEEDED(hr))
{
// 获取第一个视频流的媒体类型
hr = CaptureSource->GetAvailableDeviceMediaType(
MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_VIDEO_PREVIEW, // 第一个视频流
dwIndex, // 媒体类型索引
&pMediaType // 接收媒体类型
);
if (SUCCEEDED(hr)) {
// 输出媒体类型信息
UINT32 numerator = 0, denominator = 0;
GUID majorType, subtype, AmFormat;
if (SUCCEEDED(pMediaType->GetGUID(MF_MT_MAJOR_TYPE, &majorType)) &&
SUCCEEDED(pMediaType->GetGUID(MF_MT_SUBTYPE, &subtype)))
{
if (subtype == GetGUIDFromMediaTypeEnum(Type.TypeInfo.MediaType))
{
UINT32 Width, height;
MFGetAttributeSize(pMediaType, MF_MT_FRAME_SIZE, &Width, &height);
if (Width == Type.TypeInfo.Width && height == Type.TypeInfo.Height)
{
break;
}
}
}
// 准备下一个索引
dwIndex++;
}
}
hr = CaptureSource->SetCurrentDeviceMediaType(
MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_VIDEO_PREVIEW, // 第一个视频流
pMediaType // 接收媒体类型
);
SafeRelease(&pMediaType);
SafeRelease(&pMediaType2);
UserMediaType = Type;
return SUCCEEDED(hr);
}
this is StartPrevie
HRESULT CameraClass::StartPrevie()
{
HRESULT hr = S_OK;
hr = PreviewSink->RemoveAllStreams();
if (!DeviceIsOpen())
{
return E_FAIL;
}
// Get a pointer to the preview sink.
// hr = spCaptureEngine->GetSink(MF_CAPTURE_ENGINE_SINK_TYPE_PREVIEW, &PreviewSink);
if (FAILED(hr))
{
return false;
}
IMFMediaType* pMediaType = NULL;
IMFMediaType* pMediaType2 = NULL;
DWORD Num;
CaptureSource->GetDeviceStreamCount(&Num);
// 获取第一个视频流的媒体类型
hr = CaptureSource->GetCurrentDeviceMediaType(
MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_VIDEO_PREVIEW, // 第一个视频流
&pMediaType // 接收媒体类型
);
if (!UserMediaType.TypeInfo.IsUnDefine())
{
hr = CloneVideoMediaType(pMediaType, UserMediaType.TypeInfo.GetMediaTypeGUID(), &pMediaType2);
MFSetAttributeSize(pMediaType2, MF_MT_FRAME_SIZE, UserMediaType.TypeInfo.Width, UserMediaType.TypeInfo.Height);
if (UserMediaType.CurFps > 0)
{
MFSetAttributeRatio(pMediaType2, MF_MT_FRAME_RATE, UserMediaType.CurFps, 1);
}
//pMediaType2->SetGUID(MF_MT_SUBTYPE, MEDIASUBTYPE_MJPG);
hr = PreviewSink->AddStream(MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_VIDEO_PREVIEW, pMediaType2, NULL, &StreamIndex);
IMFCaptureSink2* Sink2;
//PreviewSink->QueryInterface(IID_PPV_ARGS(&Sink2));
//hr = Sink2->SetOutputMediaType(StreamIndex, pMediaType2, NULL);
}
else
{
hr = PreviewSink->AddStream(MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_VIDEO_PREVIEW, pMediaType, NULL, &StreamIndex);
}
hr= PreviewSink->SetSampleCallback(StreamIndex, CallbackObj.Get());
CurMediaType = MediaTypeInfoEx::FromMFMeidiaType(pMediaType);
SafeRelease(&pMediaType);
SafeRelease(&pMediaType2);
hr = spCaptureEngine->StartPreview();
if (SUCCEEDED(hr))
{
isPrevie = true;
}
return hr;
}