本文介绍了无法使MFCaptureD3D示例以非默认帧大小运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从Media Foundation SDK(http://msdn.microsoft.com/zh-cn/library/dd743690%28VS.85%29.aspx)中获取MFCaptureD3D示例更改捕获格式,以使相机以1024 x 768(而不是默认分辨率)运行 640 x 480(或默认格式以外的任何其他格式)的图像.我正在使用此处介绍的SetDeviceFormat()和EnumerateCaptureFomats()例程.

http://msdn.microsoft.com/zh-cn/library/ff485858%28VS.85%29.aspx

我尽可能长时间地延迟调用SetDeviceFormat();我注意到,如果在调用IMFSourceReader-> SetCurrentMediaType()(用于设置YUY2帧格式)之前调用它,则SetCurrentMediaType()会将格式重置为640 X 480.所以, 在调用IMFSourceReader-> ReadSample()询问第一个样本之前,我将对SetDeviceFormat()的调用移到了紧要点.

SetDeviceFormat()调用成功,并且如果我在调用后立即转储当前捕获格式,则它表示预期的1024 x 768.但是,在调用OnReadSample()回调时,状态HRESULT为E_FAIL(0x80004005).

有人知道如何解决这个问题吗?

I'm having trouble getting the MFCaptureD3D sample from the Media Foundation SDK (http://msdn.microsoft.com/en-us/library/dd743690%28VS.85%29.aspx) to work when changing the capture format so that the camera runs at 1024 x 768 instead of the default resolution of 640 x 480 (or indeed, any other format except the default).  I am using the SetDeviceFormat() and EnumerateCaptureFomats() routines described here.

http://msdn.microsoft.com/en-us/library/ff485858%28VS.85%29.aspx

I delay calling SetDeviceFormat() as long as possible; I noticed that if I call it before calling IMFSourceReader->SetCurrentMediaType() (which is used to set up YUY2 frame format), then SetCurrentMediaType() resets the format to 640 X 480.  Therefore, I moved the call to SetDeviceFormat() to the point immediately before calling IMFSourceReader->ReadSample() to ask for the first sample.

The SetDeviceFormat() call succeeds, and if I dump the current capture format immediately after the call, it indicates 1024 x 768 as expected. However, when the OnReadSample() callback is invoked, the status HRESULT is E_FAIL (0x80004005).

Anyone know how to fix this?

谢谢迈克

推荐答案

IMFSourceReader :: GetNativeMediaType
http://msdn.microsoft.com/en-us/library/dd374661 (v = VS.85).aspx

IMFSourceReader::GetNativeMediaType
http://msdn.microsoft.com/en-us/library/dd374661(v=VS.85).aspx

如果所需的格式不是本机类型之一,您仍然可以尝试IMFSourceReader :: SetCurrentMediaType,如果成功,则意味着您设置的类型是本机类型,或者可以将解码器添加到本机类型.转换为您的类型 设置. IMFSourceReader :: SetCurrentMediaType

If the format you want is not one of the native types, you can still try IMFSourceReader::SetCurrentMediaType, and if it succeeds it means that the type you are setting is either a native type or that a decoder could be added to convert to the type you are setting.  IMFSourceReader::SetCurrentMediaType

http://msdn.microsoft.com/en-us/library/dd374667(VS.85).aspx

在IMFSourceReader :: SetCurrentMediaType方法中,IMFMediaType实际上不仅指定颜色格式(例如YUY2),而且还指定大小.要指定大小,请参见MF_MT_FRAME_SIZE属性:

In the IMFSourceReader::SetCurrentMediaType method, the IMFMediaType actually specifies not only the color format (such as YUY2) but it also specifies the size as well.  To specify the size you want see the MF_MT_FRAME_SIZE attribute:

http://msdn.microsoft.com/en-us/library/ms701619(v = VS.85).aspx

注意:

""SetCurrentMediaType()将格式重置为640 X 4800"

"SetCurrentMediaType() resets the format to 640 X 480" 

   -如果我不得不猜测,您输入的尺寸为640x480,这就是为什么您将其视为您的格式.尝试指定MF_MT_FRAME_SIZE属性.

    - If I had to guess, you are passing in a size of 640x480 and that is why you are seeing that as your format. Try specifying the MF_MT_FRAME_SIZE attribute.

"我尽可能长时间地延迟调用SetDeviceFormat();我注意到,如果在调用IMFSourceReader-> SetCurrentMediaType()

"I delay calling SetDeviceFormat() as long as possible; I noticed that if I call it before calling IMFSourceReader->SetCurrentMediaType() "

   -如果您通过IMFSourceReader :: SetCurrentMediaType设置格式,则不应使用SetDeviceFormat().我猜你会得到错误,因为SourceReader需要一种格式(从您的IMFSourceReader-> SetCurrentMediaType() 调用) 并且MediaSource提供的格式与您的SetCurrentMediaType()函数不同).

    - you shouldn't use SetDeviceFormat() if you are setting the format with IMFSourceReader::SetCurrentMediaType.  I would guess you get the error you do because the SourceReader expects one format (from your IMFSourceReader->SetCurrentMediaType() call) and the MediaSource is delivering a different format (from your SetCurrentMediaType() function).


这篇关于无法使MFCaptureD3D示例以非默认帧大小运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 16:46