两种方法:
1、选择系统profile
IConfigAsfWriter *pConfig = 0; hr = gcap.pRender->QueryInterface(IID_IConfigAsfWriter, (void**)&pConfig); CComPtr <IWMProfileManager> pIWMProfileManager;HRESULT hr = WMCreateProfileManager( &pIWMProfileManager );
printf("MapProfile: Failed to create profile manager! hr=0x%x\n", hr);}
return hr;
printf("MapProfile: Failed to QI IWMProfileManager2!\n");}
return E_UNEXPECTED;
printf("MapProfile: Failed to set system profile version! hr=0x%x\n", hr);}
return hr;
printf("MapProfile: Failed to get system profile count! hr=0x%x\n", hr);}
return hr;
TRACE(TEXT("Failed to ConfigureFilterUsingProfileGuid ! hr=0x%x"), hr);
return hr;
}
2、自定义
HRESULT CMyAmCapDlg::ConfigAsfWriter (CComQIPtr<IConfigAsfWriter> pConfig) { int nWidth = 1024,nHeight = 768; //设置它的高与宽 HRESULT hr; CComQIPtr<IWMProfile> pProfile; hr = pConfig->GetCurrentProfile( &pProfile ); //删除多余的其它流数据,否则会出错 DWORD nStreamCount; hr = pProfile->GetStreamCount(&nStreamCount); CComQIPtr<IWMStreamConfig> pStreamConfig; hr = pProfile->GetStream(1, &pStreamConfig); //因为应该只有一个流,所以获取视频流的 //ERRORBOX(hr); pStreamConfig->SetBitrate(4096*1000); /////设置视频流的属性 CComQIPtr<IWMMediaProps> pMediaProps; pMediaProps = pStreamConfig; ASSERT (!!pMediaProps); //WM_MEDIA_TYPE *pType = reinterpret_cast<WM_MEDIA_TYPE *>( &mt ); WM_MEDIA_TYPE *mediaType; DWORD bufsize; pMediaProps->GetMediaType(NULL,&bufsize); BYTE *pBuf = new BYTE[bufsize]; mediaType = (WM_MEDIA_TYPE*) pBuf; pMediaProps->GetMediaType(mediaType,&bufsize); VIDEOINFOHEADER *pVih = reinterpret_cast<VIDEOINFOHEADER*>(mediaType->pbFormat); pVih->bmiHeader.biWidth = nWidth; pVih->bmiHeader.biHeight = nHeight; pVih->bmiHeader.biSizeImage = GetBitmapSize(&pVih->bmiHeader); pVih->dwBitRate = 4096*1000; mediaType->lSampleSize = pVih->bmiHeader.biSizeImage; RECT src = {0,0,pVih->bmiHeader.biWidth,pVih->bmiHeader.biHeight}; pVih->rcSource = src; pVih->rcTarget = src; hr = pMediaProps->SetMediaType (mediaType); hr = pProfile->ReconfigStream (pStreamConfig); hr = pConfig->ConfigureFilterUsingProfile(pProfile); delete []pBuf;
注意
pStreamConfig->SetBitrate(4096*1000);
pVih->dwBitRate = 4096*1000;都要设置且要相同。
参考了 http://blog.csdn.net/meuck/article/details/1211831