Click here to Skip to main content
12,303,183 members (77,190 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ directshow
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 3-Jul-12 2:18am
Edited 4-Jul-12 0:50am
v2
Comments
idle63 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.
idle63 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160530.1 | Last Updated 4 Jul 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100