Creating a list of attached webcams
Many applications that use a video input such as a webcam or a DV camera often give you the option of selecting which device to use, if you have more than one device available.
This is an example taken from the preferences page of Skype:
The following will describe how we can access the data to create such a list, the specifics of creating a list (for example a NSPopUpButton) will be left out.
All the information you need is found within the class QTCaptureDevice. There are four class methods:
- defaultInputDeviceWithMediaType:
- deviceWithUniqueID:
- inputDevices
- inputDevicesWithMediaType:
The first method mentions a ‘media type’. QTCaptureDevice represents more than just webcams, it also includes microphones and DV cameras. There are three media types:
- QTMediaTypeVideo – devices with video output: iSignt cameras and other webcams
- QTMediaTypeMuxed – devices with a mix of audio and video: DV cameras
- QTMediaTypeSound – devices with audio output: microphones
Using the above information we can access all the data we need create our list. First we need a list of devices:
NSArray *inputDevices = [QTCaptureDevice inputDevices];
This is an array of all devices, of all media types. If you loop through this array you’ll need to check each item to see if it is the media type you want:
for(QTCaptureDevice *device in inputDevices) {
if([device hasMediaType:QTMediaTypeVideo]) {
// do what you need with the device
}
}
All we need now is to access the name of the device, this is provided by the instance method of QTCaptureDevice:
[device localizedDisplayName];
This will provide the name such as “Build-in iSight”.
This should provide all the information required to create a list of webcams attached to your Mac.
Recent Posts
Pages
My links


