I have blogged about Media Foundation before; it’s the “next generation” of DirectShow, introduced in Windows Vista, enhanced in Windows 7 and further enhanced in Windows 8 (more on that in a future post). One of the tasks I encountered recently was to do a video capture from a camera. This is not too difficult to do (once you understand how Media Foundation works) and there’s even two sample in the SDK. But how do you control various camera properties, such as focus, zoom, white balance, etc.?
It turns out Media Foundation does not define any specific interfaces for these tasks. Curiously enough, it implements interfaces defined by its predecessor, DirectShow, on its media source (represented by the IMFMediaSource interface), when that media source is a video camera.
This means that all you need to do is use the usual COM QueryInterface on the media source to get to the relevant functionality, represented by (at least) two DirectShow-defined interfaces, IAMCameraControl and IAMVideoProcAmp. Here’s an example that sets some properties of a camera passed in as a media source:
Note that any such modifications may fail, because some properties are not supported by the individual camera or the camera driver. If you know your camera supports some functionality for sure, your best bet is to update the driver. Sometimes a generic camera driver is not enough and the vendor-specific driver is required.