请教大侠:如何将8位位图写入wmv?SetInputProps语句报错
请教一下大家:
我想将bmp位图写入到wmv格式中,遇到一些问题,当位图为8位时,无法保存为wmv文件,而16位,24位,32位,却可以?这是为什么呢?是不是当位图为8位时,要将调色板的信息也要写入wmv中,我新手,向大家请教,谢谢!
//dwInputCount的值为2,guidProfileID 值为 WMProfile_V80_384Video for(DWORD i=0;i<dwInputCount;i++) { if(FAILED(m_pWMWriter->GetInputProps(i,&pInputProps))) { SetErrorMessage("Unable to GetInput Properties"); goto TerminateConstructor; } if(FAILED(pInputProps->GetType(&guidInputType))) { SetErrorMessage("Unable to Get Input Property Type"); goto TerminateConstructor; } //当i=1时,能进入此if语句内部 if(guidInputType==WMMEDIATYPE_Video) { m_pVideoProps=pInputProps; m_dwVideoInput=i; break; } else { pInputProps->Release(); pInputProps=NULL; } } WM_MEDIA_TYPE mt; mt.majortype = WMMEDIATYPE_Video; if( bmpInfo.bmiHeader.biCompression == BI_RGB ) { if( bmpInfo.bmiHeader.biBitCount == 32 ) { mt.subtype = WMMEDIASUBTYPE_RGB32; } else if( bmpInfo.bmiHeader.biBitCount == 24 ) { mt.subtype = WMMEDIASUBTYPE_RGB24; } else if( bmpInfo.bmiHeader.biBitCount == 16 ) { mt.subtype = WMMEDIASUBTYPE_RGB555; } else if( bmpInfo.bmiHeader.biBitCount == 8 ) { mt.subtype = WMMEDIASUBTYPE_RGB8; } else { mt.subtype = GUID_NULL; } } mt.bFixedSizeSamples = false; mt.bTemporalCompression = false; mt.lSampleSize = 0; mt.formattype = WMFORMAT_VideoInfo; mt.pUnk = NULL; mt.cbFormat = sizeof(WMVIDEOINFOHEADER); mt.pbFormat = (BYTE*)&videoInfo; if(FAILED(m_pVideoProps->SetMediaType(&mt))) { SetErrorMessage("Unable to Set Media Type"); return E_FAIL; } if(FAILED(m_pWMWriter->SetInputProps(m_dwVideoInput,m_pVideoProps))) { SetErrorMessage("Unable to Set Input Properties for Media Writer"); return E_FAIL; }
WMVIDEOINFOHEADER * pVidHdr = (WMVIDEOINFOHEADER*)pMediaType->pbFormat;pVidHdr->AvgTimePerFrame = 10000000 / 25;pVidHdr->dwBitRate = 500000;pVidHdr->bmiHeader.biWidth = m_pBase->m_frameRect.right;//这里pVidHdr->bmiHeader.biHeight = m_pBase->m_frameRect.bottom;//这里pVidHdr->bmiHeader.biBitCount = /*32*/m_pBase->m_dwBitCount;
[解决办法]
就是在配置profile的时候,带上这些信息。
就拿bmp来说,一般是filehead bmphead data。有调色板就为:filehead bmphead 调色板 data。
这时候需要注意head里的变量大小的设置,需要加上调色板的大小
[解决办法]
使用glaobalalloc函数分配存储空间,然后解锁获得指针,给各个变量赋值。这样就可以分配连续的存储空间
------解决方案--------------------
HANDLE hDIB = GlobalAlloc(GMEM_FIXED,(DWORD)(sizeof(WMVIDEOINFOHEADER) + sizeof(RGBQUAD)*256));
WMVIDEOINFOHEADER * lpbi=(WMVIDEOINFOHEADER *)GlobalLock(hDIBlpbi->AvgTimePerFrame=((QWORD)1) * 10000 * 1000 / m_dwFrameRate;