How to capture a camera image in Windows Desktop / Windows 10 recurring to an external application.

  Windows General

CommandCam is a simple and easy to use command line webcam image grabber for Windows. It captures a single image from a webcam and stores it in a bitmap file. CommandCam is ideal for use in batch files and other situations where you want a very simple way to automate image capture. CommandCam uses Microsoft’s DirectShow API to access webcams, so it should work with most USB cameras.


CommandCam Options

Several useful options can be specified using command line arguments.

To specify a time delay between the camera being turned on and the image being grabbed, use the "/delay" option to specify a time delay in milliseconds. For example, to add a 5 second delay,

CommandCam /delay 5000

The default output filename for the grabbed image is "image.bmp". To specify a different filename, use the "/filename" option. If the filename contains any spaces, enclose it in inverted commas. For example, to save the image as "face.bmp":

CommandCam /filename face.bmp

By default, the first available video capture device will be used. To specify a particular device (if you have more than one), use the "/devnum" option. For example, to open the second video capture device:

CommandCam /devnum 2

Alternatively, to specify a capture device by name, use the "/devname" option. If the device name contains any spaces, it should be enclosed in inverted commas. For example, to select a device called “USB Video Device”:

CommandCam /devname "USB Video Device"

To specify a capture device by serial number (for example if you wish to select between two cameras of the same model), use the "/devserial" option. For example, to select a device with the serial number “314159265”:

CommandCam /devserial 314159265

By default, CommandCam does not display any video on the screen before capturing the image. However, you can enable a video preview window using the "/preview" option.

CommandCam /preview

To list the available capture devices, for example to check which device number corresponds to which device, use the "/devlist" option.

CommandCam /devlist

To list the available capture devices with extra detail (currently just the DevicePath for each camera), use the "/devlistdetail" option.

CommandCam /devlistdetail

More than one command line option can be specified at once. For example, to capture an image from the second video capture device to a file called "output.bmp" after a 10 second delay, the following command would be used:

CommandCam /filename output.bmp /delay 10000 /devnum 2

To suppress the text normally printed to the console by CommandCam (welcome message and other information), use the "/quiet" option.

CommandCam /quiet

CommandCam error codes

If CommandCam exits due to an error, it returns one of the following error code values:

  1. “Error: no filename specified”
  2. “Error: invalid delay specified”
  3. “Error: invalid device number”
  4. “Error: invalid device name”
  5. “Error: invalid device serial number”
  6. “Unrecognised command line argument”
  7. “Could not initialise COM”
  8. “Could not create filter graph”
  9. “Could not create capture graph builder”
  10. “Could not attach capture graph builder to graph”
  11. “Could not create system device enumerator”
  12. “No video devices found”
  13. “No devices found”
  14. “Video capture device not found”
  15. “Error getting device name and DevicePath”
  16. “Could not create capture filter”
  17. “Could not add capture filter to graph”
  18. “Could not create Sample Grabber filter”
  19. “Could not get ISampleGrabber interface to sample grabber filter”
  20. “Could not enable sample buffering in the sample grabber”
  21. “Could not set media type in sample grabber”
  22. “Could not add Sample Grabber to filter graph”
  23. “Could not create Null Renderer filter”
  24. “Could not add Null Renderer to filter graph”
  25. “Could not render capture video stream”
  26. “Could not render preview video stream”
  27. “Could not get media control interface”
  28. “Could not run filter graph”
  29. “Could not get buffer size”
  30. “Could not allocate data buffer for image”
  31. “Could not get buffer data from sample grabber”
  32. “Could not get media type”
  33. “Error opening output file”
  34. “Wrong media type”


Download in the .git repository.