Video capture devices
Selecting a video capture device
First, set VideoSource = vs_VideoCaptureDevice to select the video capture devices as video source.
Then select the current video capture device by assigning the VideoDevice property, an index in the VideoDevices list, which contains VideoDevicesCount items.
The video capture device can be selected programmatically by its name (as it appears in the VideoDevices list) with VideoDeviceIndex, e.g.:
VideoGrabber.VideoDevice = VideoGrabber.VideoDeviceIndex ("Logitech HD Pro Webcam C920")
The comparison ignores the case, and the name can begin and/or end with the * wildcard:
"Logitech HD Pro Webcam C920": the device named "Logitech HD Pro Webcam C920";"Logitech*": the 1st device whose name begins with "Logitech";"*C920": the 1st device whose name ends with "C920";"*Webcam*": the 1st device whose name contains "Webcam".
The * wildcard is recognized only at the start and at the end of the name, not in the middle. VideoDeviceIndex returns the index of the 1st device of the list that matches, or -1 if no device matches: check the result before assigning it to VideoDevice.
The order of the devices in the VideoDevices list is not guaranteed: it can change e.g. after a restart of the computer or when a device (or a virtual camera) is added. To select the same device each time, select it by its name or by its hardware identifier rather than by a fixed index. Several devices of the same brand and model have the same name: to select one of them, use its hardware identifier (see below).
The name of the current video capture device is reported by VideoDeviceName.
When a video capture device is selected, its device-dependent properties are reloaded from the registry and the OnVideoDeviceSelected event occurs.
Note
These registry settings can be reset to their default values by invoking ResetVideoDeviceSettings while the component is inactive. This is rarely needed, but may be useful if the current settings result in a black video.
Identifying the video capture device by its hardware identifier (instead of its manufacturer's name)
When several video capture devices of the same brand and model cannot be distinguished in the VideoDevices list, use VideoDeviceIndexFromId, which returns the index of the device in the VideoDevicesId list, e.g.:
VideoGrabber.VideoDevice = VideoGrabber.VideoDeviceIndexFromId ("devicepnpusbvid046dpid0826mi02739103c9a00002{65e8773d-8f56-11d0-a3b9-00a0c9223196}globalHD Webcam C525R");
The VideoDevicesId list is in the same order as the VideoDevices list: to store the identifier of a device, read its line in VideoDevicesId (see "PID and VID identifiers of USB video capture devices" below).
Note
The identifier of a USB device that has no USB serial number (which is the case of many webcams) depends on the USB port the device is plugged into: it remains the same as long as the device stays on the same port, and changes if the device is plugged into another port. The device must then be selected again and its new identifier stored.
Connecting/disconnecting a video capture device
When a video capture device is connected or disconnected, the OnDeviceArrivalOrRemoval event occurs. This event reports the name and index of the video capture device in the VideoDevices list.
After the video capture device has been disconnected, IsVideoDeviceConnected returns false until the device is reconnected.
If the device is used for preview or recording, the OnDeviceLost event occurs when the device is disconnected, and the preview or recording stops.
When a video capture device is disconnected, it is not removed from the VideoDevices list. This avoids the complexity of managing the shifted indexes of the video capture devices whose indexes are above the index of the removed device (VideoDevice selects the current video device in the VideoDevices list).
When TVideoGrabber is running, the following rules apply:
- When a device is turned on, it is added at the bottom of the VideoDevices list and the OnDeviceArrivalOrRemoval event occurs. Its IsDeviceArrival parameter reports "true", and its DeviceIndex parameter reports the index of the video device added to the list.
- When a device is turned off, it remains in the VideoDevices list and the OnDeviceArrivalOrRemoval event occurs. Its IsDeviceArrival parameter reports "false", and its DeviceIndex parameter reports the index of the video device turned off.
- If a device turned off (case 2 above) is turned on again, the VideoDevices list does not change and the OnDeviceArrivalOrRemoval event occurs. Its IsDeviceArrival parameter reports "true", and its DeviceIndex parameter reports the index the video device had when it was turned off. This also applies when the device is plugged into another USB port.
The current state of any video capture device (connected or not) can be retrieved by testing IsVideoDeviceConnected (DeviceIndex).
For example, IsVideoDeviceConnected (3) returns "true" if the device having the index 3 in the VideoDevices list is active, and "false" if the device has been turned off.
PID and VID identifiers of USB video capture devices
The PID and VID identifiers of the USB video capture devices are included in the VideoDevicesId list, which has the same number of items as the VideoDevices list (the number of items returned by VideoDevicesCount).
To retrieve them:
- Assign the VideoDevicesId list to a StringList (e.g. IdList).
- Read the
IdList[VideoGrabber.VideoDevice]string value. - If the device is a USB device, the returned string contains the "pid..." and "vid..." identifiers.
USB video capture devices
To know whether a video capture device is a USB device, call IsVideoDeviceUSB (DeviceIndex), DeviceIndex being the index of the device in the VideoDevices list. It returns false for PCI / PCIe capture cards, virtual cameras and cameras exposed by a software source filter.
E.g. to let the user choose only among the USB video capture devices currently plugged in:
// usbIndexes[i] = index in the VideoDevices list of the item i of the combo box
string[] names = VideoGrabber.VideoDevices.Split (new string[] { "\r\n" }, StringSplitOptions.None);
List<int> usbIndexes = new List<int>();
comboBox1.Items.Clear();
for (int i = 0; i < VideoGrabber.VideoDevicesCount; i++) {
if (VideoGrabber.IsVideoDeviceUSB (i) && VideoGrabber.IsVideoDeviceConnected (i)) {
usbIndexes.Add (i);
comboBox1.Items.Add (names[i]);
}
}
// when the user selects an item:
VideoGrabber.VideoDevice = usbIndexes[comboBox1.SelectedIndex];
Rebuild this list in the OnDeviceArrivalOrRemoval event to keep it up to date.
The audio capture device of a USB video capture device (e.g. the microphone of a webcam) is returned by AudioDeviceIndexFromVideoDevice, see Audio capture devices.
WDM vs VFW drivers
For more information, see Vfw vs. WDM drivers.
PointGrey cameras
The PointGreyConfig function configures the PointGrey cameras using the PointGrey FlyStream driver.