关于应用程序中使用dmo的一些问题
DMO_MEDIA_TYPE m_mt;
ZeroMemory(&m_mt,sizeof(DMO_MEDIA_TYPE));
VIDEOINFOHEADER *m_pVfx=new VIDEOINFOHEADER; //http://msdn.microsoft.com/en-us/library/dd407325(VS.85).aspx
ZeroMemory(m_pVfx, sizeof(VIDEOINFOHEADER));
DMO_MEDIA_TYPE m_mt2;
ZeroMemory(&m_mt2,sizeof(DMO_MEDIA_TYPE));
VIDEOINFOHEADER *m_pVfx2=new VIDEOINFOHEADER; //http://msdn.microsoft.com/en-us/library/dd407325(VS.85).aspx
ZeroMemory(m_pVfx2, sizeof(VIDEOINFOHEADER));
DWORD dwType = 0;
DWORD dwInCount=0;
DWORD dwOutCount=0;
/************************************************************************/
// 枚举解码器GUID,创建DMO对象
/************************************************************************/
hr = GetVideoEncoderDMOGuid(); //获取编码DMO
REFCLSID CLSID_Wmv3=g_rgDmoInfo.clsidDMO;
hr = CoCreateInstance(CLSID_Wmv3, NULL, CLSCTX_INPROC_SERVER, IID_IMediaObject, (void **)&m_pObject);
if(FAILED(hr))
{
return hr;
}
DWORD dwFlags = 0;
m_pObject->GetOutputStreamInfo(0,&dwFlags);//return 0x000b
m_pObject->GetInputStreamInfo(0,&dwFlags);//return 0x0003
m_pObject->GetStreamCount(&dwInCount,&dwOutCount); //输入为1输出的引脚为2
/************************************************************************/
// 对输入流的媒体类型进行设置
/************************************************************************/
// RECT rect2={0,0,640,480};
// m_pVfx2->rcSource = rect2; //RECT structure that specifies the source video window. This structure can be a clipping rectangle, to select a portion of the source video stream m_pVfx2->rcTarget = rect2; //RECT structure that specifies the destination video window
// m_pVfx2->dwBitRate = 5120000; //Approximate data rate of the video stream, in bits per second
m_pVfx2->dwBitErrorRate = 0; //Data error rate, in bit errors per second
m_pVfx2->AvgTimePerFrame = 400000; //100ns,The desired average display time of the video frames, in 100-nanosecond units. The actual time per frame may be longer
m_pVfx2->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
m_pVfx2->bmiHeader.biWidth = FRAME_WIDTH;
m_pVfx2->bmiHeader.biHeight = FRAME_HEIGHT;
m_pVfx2->bmiHeader.biPlanes = 1; //must be set to 1
m_pVfx2->bmiHeader.biBitCount = 24; //number of bits per pixel
m_pVfx2->bmiHeader.biCompression = 0x32595559; //0xe436eb7d; //If the bitmap is compressed, this member is a FOURCC the specifies the compression. For uncompressed formats, the following values are possible:BI_RGB/BI_BITFIELDS
m_pVfx2->bmiHeader.biSizeImage = 0;
m_pVfx2->bmiHeader.biXPelsPerMeter = 0; //Specifies the horizontal resolution, in pixels per meter, of the target device for the bitmap
m_pVfx2->bmiHeader.biYPelsPerMeter = 0; //Specifies the vertical resolution, in pixels per meter, of the target device for the bitmap
m_pVfx2->bmiHeader.biClrUsed = 0; //Specifies the number of color indices in the color table that are actually used by the bitmap
m_pVfx2->bmiHeader.biClrImportant = 0; //Specifies the number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important
m_mt2.majortype = MEDIATYPE_Video; //Major type GUID of the stream.
m_mt2.subtype = MEDIASUBTYPE_YUY2; //WMMEDIASUBTYPE_WMV3; //Subtype GUID of the stream.
m_mt2.bFixedSizeSamples = 0; //If TRUE, samples are of a fixed size. This field is informational only. For audio, it is generally set to TRUE. For video, it is usually TRUE for uncompressed video and FALSE for compressed video.
m_mt2.bTemporalCompression = 1; //If TRUE, samples are compressed using temporal (interframe) compression. (A value of TRUE indicates that not all frames are key frames.) This field is informational only.
m_mt2.lSampleSize = FRAME_HEIGHT*FRAME_WIDTH*3; //Size of the sample in bytes. For compressed data, the value can be zero.
m_mt2.formattype = FORMAT_VideoInfo; //GUID specifying the format type. The pbFormat member points to the corresponding format structure.
m_mt2.pUnk = NULL; //not used
m_mt2.cbFormat = sizeof(VIDEOINFOHEADER); //Size of the format block of the media type.
m_mt2.pbFormat = (BYTE*)(m_pVfx2); //Pointer to the format structure. The structure type is specified by the formattype member. The format structure must be present, unless formattype is GUID_NULL or FORMAT_None.
hr = m_pObject->SetInputType(0, &m_mt2,0); //0x80040203 = DMO_E_TYPE_NOT_SET
/************************************************************************/
// 对输出流的媒体类型进行设置
/************************************************************************/
// hr = m_pObject->GetInputType(0,0,&m_mt); //2th param: 2 = WMMEDIASUBTYPE_WMV3 33564D57-0000-0010-8000-00AA00389B71
RECT rect={0,0,640,480};
m_pVfx->rcSource = rect; //RECT structure that specifies the source video window. This structure can be a clipping rectangle, to select a portion of the source video stream
m_pVfx->rcTarget = rect; //RECT structure that specifies the destination video window
m_pVfx->dwBitRate= 5120000; //Approximate data rate of the video stream, in bits per second
m_pVfx->dwBitErrorRate= 0;
m_pVfx->AvgTimePerFrame= 400000; //100ns,The desired average display time of the video frames, in 100-nanosecond units. The actual time per frame may be longer
m_pVfx->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
m_pVfx->bmiHeader.biWidth = FRAME_WIDTH;
m_pVfx->bmiHeader.biHeight = FRAME_HEIGHT;
m_pVfx->bmiHeader.biPlanes = 1; //must be set to 1
m_pVfx->bmiHeader.biBitCount = 24; //number of bits per pixel
m_pVfx->bmiHeader.biCompression = 0x33564D57;//861293911;//MAKEFOURCC/mmioFOURCC('W','M','V','3'); //If the bitmap is compressed, this member is a FOURCC the specifies the compression. For uncompressed formats, the following values are possible:BI_RGB/BI_BITFIELDS
m_pVfx->bmiHeader.biSizeImage = 0;//m_pVfx->bmiHeader.biWidth * m_pVfx->bmiHeader.biHeight * m_pVfx->bmiHeader.biBitCount /8; //in bytes
m_pVfx->bmiHeader.biXPelsPerMeter = 0; //Specifies the horizontal resolution, in pixels per meter, of the target device for the bitmap
m_pVfx->bmiHeader.biYPelsPerMeter = 0; //Specifies the vertical resolution, in pixels per meter, of the target device for the bitmap
m_pVfx->bmiHeader.biClrUsed = 0; //Specifies the number of color indices in the color table that are actually used by the bitmap
m_pVfx->bmiHeader.biClrImportant = 0; //Specifies the number of color indices that are considered important for displaying the bitmap. If this value is zero, all colors are important
m_mt.majortype = MEDIATYPE_Video; //Major type GUID of the stream.
m_mt.subtype = WMMEDIASUBTYPE_WMV3;
m_mt.bFixedSizeSamples = 0; //If TRUE, samples are of a fixed size. This field is informational only. For audio, it is generally set to TRUE. For video, it is usually TRUE for uncompressed video and FALSE for compressed video.
m_mt.bTemporalCompression = 1; //If TRUE, samples are compressed using temporal (interframe) compression. (A value of TRUE indicates that not all frames are key frames.) This field is informational only.
m_mt.lSampleSize = 0;
//m_mt.lSampleSize = m_pVfx->bmiHeader.biSizeImage ; //Size of the sample in bytes. For compressed data, the value can be zero.
m_mt.formattype = FORMAT_VideoInfo; //GUID specifying the format type. The pbFormat member points to the corresponding format structure.
m_mt.pUnk = NULL; //not used
m_mt.cbFormat = sizeof(VIDEOINFOHEADER); //Size of the format block of the media type.
m_mt.pbFormat = (BYTE*)(m_pVfx); //Pointer to the format structure. The structure type is specified by the formattype member. The format structure must be present, unless formattype is GUID_NULL or FORMAT_None.
hr = m_pObject->SetOutputType(0, &m_mt,0);
delete m_pVfx;
delete m_pVfx2;
以上是我使用编码dmo的代码,为什么hr = m_pObject->SetOutputType(0, &m_mt,0);老是返回0x80040205的错误。