Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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.
Posted
Updated 4-Jul-12 0:50am
v2
Comments
[no name] 3-Jul-12 8:26am    
Does it not compile, not record or wrong record? Is there any error message out there?
Member 8643404 4-Jul-12 6:50am    
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.
[no name] 4-Jul-12 13:27pm    
I think the file is not valid (header, format, whatever). Can you put an example to download?
Vardhraz 9-Oct-12 0:15am    
hi..while stop recording you have to release the filters properly..checkout that place....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900