I am using direct show to record avi file using the following filters:
FileSource(Async)->AviSpliter->AviMux ->FileWriter
I am pasting relevant source code here:
hr = CoInitialize(NULL);
if(FAILED(hr))
{
GetErrorMessage(hr);
}
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2,NULL,CLSCTX_INPROC_SERVER,IID_ICaptureGraphBuilder2,(void**)&pCapture);
if(FAILED(hr))
{
GetErrorMessage(hr);
}
hr = CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER,IID_IGraphBuilder,(void**)&pGraph);
if(FAILED(hr))
{
GetErrorMessage(hr);
}
hr = pGraph->QueryInterface(IID_IMediaControl,(void**)&pControl);
if(FAILED(hr))
{
GetErrorMessage(hr);
}
hr = pGraph->QueryInterface(IID_IMediaEventEx,(void**)&pEventx);
if(FAILED(hr))
{
GetErrorMessage(hr);
}
pCapture->SetFiltergraph(pGraph);
if(FAILED(hr))
{
GetErrorMessage(hr);
}
hr = CoCreateInstance(CLSID_AviSplitter,NULL,CLSCTX_INPROC_SERVER,IID_IBaseFilter,(void**)&pAviSpliter);
if(FAILED(hr))
{
GetErrorMessage(hr);
}
hr = CoCreateInstance(CLSID_AviDest,NULL,CLSCTX_INPROC_SERVER,IID_IPersistMediaPropertyBag,(void**)&pBag);
if(FAILED(hr))
{
GetErrorMessage(hr);
}
hr = pBag->QueryInterface(IID_IBaseFilter,(void**)&pAviMux);
if(FAILED(hr))
{
GetErrorMessage(hr);
}
hr = CoCreateInstance(CLSID_FileWriter,NULL,CLSCTX_INPROC_SERVER,IID_IFileSinkFilter2,(void**)&pSink);
if(FAILED(hr))
{
GetErrorMessage(hr);
}
hr = pSink->QueryInterface(IID_IBaseFilter,(void**)&pFileWriter);
if(FAILED(hr))
{
GetErrorMessage(hr);
}
hr = pSink->SetFileName(m_SaveFile.AllocSysString(),NULL);
if(FAILED(hr))
{
GetErrorMessage(hr);
}
hr = pGraph->AddFilter((IBaseFilter*)pFileWriter,L"FileWriter");
if(FAILED(hr))
{
AfxMessageBox(L"unable to Add");
return FALSE;
}
hr = pGraph->AddFilter((IBaseFilter*)pAviMux,L"AviDest");
if(FAILED(hr))
{
GetErrorMessage(hr);
}
hr = CoCreateInstance(CLSID_MediaPropertyBag,NULL,CLSCTX_INPROC_SERVER,IID_IMediaPropertyBag,(void**)&pPropBag);
pBag->Load(pPropBag,NULL);
hr = pGraph->AddFilter(pAviSpliter,L"AviSplitter");
if(FAILED(hr))
{
GetErrorMessage(hr);
}
pGraph->RenderFile(m_StrmUrl.AllocSysString(),NULL);
if(FAILED(hr))
{
GetErrorMessage(hr);
}
pEventx->SetNotifyWindow((OAHWND)GetSafeHwnd(), WM_GRAPH_NOTIFY, 0);
pControl->Run();
return TRUE;
}
BOOL CRecordingDlg::GetErrorMessage(HRESULT hr)
{
switch(hr)
{
case S_OK:
break;
case S_FALSE:
AfxMessageBox(L"Comlibrary Already Initialized in this thread");
break;
case VFW_S_PARTIAL_RENDER:
AfxMessageBox(L"VFW_S_PARTIAL_RENDER");
break;
case E_ABORT:
AfxMessageBox(L"E_ABORT");
break;
case E_POINTER:
AfxMessageBox(L"E_POINTER");
break;
case VFW_E_CANNOT_CONNECT:
AfxMessageBox(L"VFW_E_CANNOT_CONNECT");
break;
case VFW_E_NOT_IN_GRAPH:
AfxMessageBox(L"VFW_E_NOT_IN_GRAPH");
break;
case E_UNEXPECTED:
AfxMessageBox(L"The two initialization methods are mutually exclusive");
break;
}
return TRUE;
Recording done successfully. File is also created without any error, but I am not able to play the file, error from WMP, is: not supported format.
plz help me thank in advanced.