• Advertisement
Sign in to follow this  

DirectShow - Capturing Webcam Video to WM File

This topic is 2301 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all,

I wrote a piece of C++ Code sometimes to Capture the Webcam Video Stream to a Windows Media File as it's explained here.
But somehow it doesn't work. I checked every line and the error apparently occurs when I want to call the following function: IMediaControl::Run().
Though I don't see what is wrong with it, so I thought maybe you would see it.

Anyway here's my Code:

// Initalizing FilterGraph and CaaptureGraphBuilder
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC, IID_IGraphBuilder, (void **)&pGraph);
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void**)&pBuild);
hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
hr = pGraph->QueryInterface(IID_IMediaEventEx, (void **)&pEvent);

hr = pEvent->SetNotifyWindow((OAHWND)hWnd, WM_GRAPHNOTIFY, 0);
hr = pBuild->SetFiltergraph(pGraph);

// Searching for a Video-Input Device(Webcam)
{
IMoniker* pMoniker = NULL;
ICreateDevEnum *pDevEnum = NULL;
IEnumMoniker *pClassEnum = NULL;

hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC, IID_ICreateDevEnum, (void **)&pDevEnum);
hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pClassEnum, 0);
hr = pClassEnum->Next(1, &pMoniker, NULL);
hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&pCap);
pMoniker->Release();
pDevEnum->Release();
pClassEnum->Release();
}

// Adding the previously found Video Input Device to the FilterGraph
hr = pGraph->AddFilter(pCap, L"Video Capture");
// Creating the File-Writing section of the FilterGraph
hr = pBuild->SetOutputFileName(&MEDIASUBTYPE_Asf, L"I:\\VidCap.wmv", &pASFWriter, NULL);
hr = pASFWriter->QueryInterface(IID_IConfigAsfWriter, (void**)&pConfig); // <-The config file. I actually don't know what to do with it, maybe this is why I get the error?
// Connecting Video Capture Filter to File Writing Section
hr = pBuild->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, pCap, 0, pASFWriter);
pConfig->Release();

hr = pControl->Run(); // <- This is where I get E_FAIL!!!


Regards,
el-enemigo

EDIT: I commented the code, so maybe now someone could help me.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement