Click here to Skip to main content
11,496,146 members (798 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
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 3:18am
Edited 4-Jul-12 1:50am
v2
Comments
idle63 at 3-Jul-12 8:26am
   
Does it not compile, not record or wrong record? Is there any error message out there?
Member 8643404 at 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 at 4-Jul-12 13:27pm
   
I think the file is not valid (header, format, whatever). Can you put an example to download?
Vardhraz at 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
0 Dnyaneshwar@Pune 692
1 RyanDev 230
2 CHill60 163
3 Sascha Lefèvre 145
4 Sergey Alexandrovich Kryukov 124
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 4 Jul 2012
Copyright © CodeProject, 1999-2015
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