views:

318

answers:

1

I am targeting windows machines. I need to get access to the pointer to the byte array describing the individual streaming frames from an attached usb webcam. I saw the playcap directshow sample from the windows sdk, but I dont see how to get to raw data, frankly, I don't understand how the video actually gets to the window. Since I don't really need anything other than the video capture I would prefer not to use opencv.

Visual Studio 2008 c++

+1  A: 

Insert the sample grabber filter. Connect the camera source to the sample grabber and then to the null renderer. The sample grabber is a transform, so you need to feed the output somewhere, but if you don't need to render it, the null renderer is a good choice.

You can configure the sample grabber using ISampleGrabber. You can arrange a callback to your app for each frame, giving you either a pointer to the bits themselves, or a pointer to the IMediaSample object which will also give you the metadata.

You need to implement ISampleGrabberCB on your object, and then you need something like this (pseudo code)

IFilterInfoPtr      m_pFilterInfo;
ISampleGrabberPtr   m_pGrabber;

m_pGrabber = pFilter;

m_pGrabber->SetBufferSamples(false);
m_pGrabber->SetOneShot(false);

// force to 24-bit mode
AM_MEDIA_TYPE mt;
ZeroMemory(&mt, sizeof(mt));
mt.majortype = MEDIATYPE_Video;
mt.subtype = MEDIASUBTYPE_RGB24;
m_pGrabber->SetMediaType(&mt);

m_pGrabber->SetCallback(this, 0);
// SetCallback increments a refcount on ourselves,
// but we own the grabber so this is recursive
/// -- must addref before SetCallback(NULL)
Release();
Geraint Davies
I was looking into the SampleGrabber but I was having a hard time getting it hooked up right. I couldn't possibly get a code snippet from you, could I? I am expecting that I should be take the playcap sample and just add the samplegrabbber and null renderer to the graph and then use the samplegrabber's call back to get at the info I need.
Mr Bell
I've added some brief code notes above -- hope that helps
Geraint Davies