我正在尝试使用Color Converter DMO(http://msdn.microsoft.com/en-us/library/windows/desktop/ff819079(v=vs.85).aspx)通过Media Foundation将RBG24转换为YV12 / NV12。我通过CLSID_CColorConvertDMO创建了一个Color Converter DSP实例,然后尝试设置所需的输入/输出类型,但即使使用GetOutputAvailableType
和GetInputAvailableType
返回的媒体类型,调用也始终返回E_INVALIDARG 。如果我将媒体类型设置为NULL
,那么我会收到媒体类型无效的错误,这是有道理的。我已经看过MSDN的例子,人们也这样做 - 枚举可用的类型,然后将它们设置为输入类型 - 他们声称它有效,但我有点卡在E_INVALIDARG上。我知道如果没有代码示例,这很难回答,如果没有人有类似的经历,我会尝试发布一个小贴士,但也许有人遇到过同样的问题?
答案 0 :(得分:3)
此DMO / DSP是双接口的,既是IMediaObject
的DMO,也是IMFTransform
的MFT。这两个接口共享很多,这里有一个代码片段,用于测试RGB24到YV12转换的初始化:
#include "stdafx.h"
#include <dshow.h>
#include <dmo.h>
#include <wmcodecdsp.h>
#pragma comment(lib, "strmiids.lib")
#pragma comment(lib, "wmcodecdspuuid.lib")
int _tmain(int argc, _TCHAR* argv[])
{
ATLVERIFY(SUCCEEDED(CoInitialize(NULL)));
CComPtr<IMediaObject> pMediaObject;
ATLVERIFY(SUCCEEDED(pMediaObject.CoCreateInstance(CLSID_CColorConvertDMO)));
VIDEOINFOHEADER InputVideoInfoHeader;
ZeroMemory(&InputVideoInfoHeader, sizeof InputVideoInfoHeader);
InputVideoInfoHeader.bmiHeader.biSize = sizeof InputVideoInfoHeader.bmiHeader;
InputVideoInfoHeader.bmiHeader.biWidth = 1920;
InputVideoInfoHeader.bmiHeader.biHeight = 1080;
InputVideoInfoHeader.bmiHeader.biPlanes = 1;
InputVideoInfoHeader.bmiHeader.biBitCount = 24;
InputVideoInfoHeader.bmiHeader.biCompression = BI_RGB;
InputVideoInfoHeader.bmiHeader.biSizeImage = 1080 * (1920 * 3);
DMO_MEDIA_TYPE InputMediaType;
ZeroMemory(&InputMediaType, sizeof InputMediaType);
InputMediaType.majortype = MEDIATYPE_Video;
InputMediaType.subtype = MEDIASUBTYPE_RGB24;
InputMediaType.bFixedSizeSamples = TRUE;
InputMediaType.bTemporalCompression = FALSE;
InputMediaType.lSampleSize = InputVideoInfoHeader.bmiHeader.biSizeImage;
InputMediaType.formattype = FORMAT_VideoInfo;
InputMediaType.cbFormat = sizeof InputVideoInfoHeader;
InputMediaType.pbFormat = (BYTE*) &InputVideoInfoHeader;
const HRESULT nSetInputTypeResult = pMediaObject->SetInputType(0, &InputMediaType, 0);
_tprintf(_T("nSetInputTypeResult 0x%08x\n"), nSetInputTypeResult);
VIDEOINFOHEADER OutputVideoInfoHeader = InputVideoInfoHeader;
OutputVideoInfoHeader.bmiHeader.biBitCount = 12;
OutputVideoInfoHeader.bmiHeader.biCompression = MAKEFOURCC('Y', 'V', '1', '2');
OutputVideoInfoHeader.bmiHeader.biSizeImage = 1080 * 1920 * 12 / 8;
DMO_MEDIA_TYPE OutputMediaType = InputMediaType;
OutputMediaType.subtype = MEDIASUBTYPE_YV12;
OutputMediaType.lSampleSize = OutputVideoInfoHeader.bmiHeader.biSizeImage;
OutputMediaType.cbFormat = sizeof OutputVideoInfoHeader;
OutputMediaType.pbFormat = (BYTE*) &OutputVideoInfoHeader;
const HRESULT nSetOutputTypeResult = pMediaObject->SetOutputType(0, &OutputMediaType, 0);
_tprintf(_T("nSetOutputTypeResult 0x%08x\n"), nSetOutputTypeResult);
// TODO: ProcessInput, ProcessOutput
pMediaObject.Release();
CoUninitialize();
return 0;
}
这应该可以正常工作并打印两个S_OK
...