CommandCam – a DirectShow command line cam image grabber for Windows

EDIT (24-11-2011) : Since publishing this post, I have found myself making frequent updates to the CommandCam program, so I’ve created a dedicated page for it instead, with up-to-date information and download links.

Get CommandCam here (binary download and source code available).

This entry was posted in Uncategorized and tagged , , , , , , , , , , , . Bookmark the permalink.

22 Responses to CommandCam – a DirectShow command line cam image grabber for Windows

  1. Stephen says:


    Thanks for this. I just tested it though – my Toshiba laptop has a built in USB 2.0 Web cam. This is the error I was given:

    CommandCom.exe –
    Written by Ted Burke – this version 15-11-2011

    Capture device: USB 2.0 Camera
    Could not get buffer size

    Let me know if there is anything you need me to check for you.

    • batchloaf says:

      Hi Stephen,

      Thanks very much for the feedback. That’s interesting that you’re seeing that message. I get that sometimes on my laptop if I set the time delay to a very short duration (e.g. significantly less than a second). Is it possible that your camera takes a little longer to ‘wake up’ than my one does? Can you please try running it again a few times with a longer time delay. For example, you could try a 5 second delay with the following command:

      CommandCam.exe image.bmp 5000

      If that works (either reliably or intermittently), then I’ll try to find a way to automatically detect when the camera is definitely ready to take the picture. Because this is the error that you’re seeing, CommandCam must be successfully finding and opening your camera. Otherwise, you would have got a different error earlier in the program.

      Thanks again for your help!

  2. Stephen says:

    By the way, your commandcam.exe link above actually says it is a commandcom.exe link.

  3. batchloaf says:

    Update: I’ve just fixed a memory leak and I’ve also modified the code that checks whether the camera is ready to capture the image to make it more robust – it should work with more cameras now. If the program runs without printing any errors, but the saved image is completely black, it’s probably just because the image was snapped too soon after your camera turned on. To prevent this, just specify a longer delay (in milliseconds) on the command line (e.g. “CommandCam.exe image.bmp 5000” will capture an image to the file “image.bmp” after 5 seconds). The default delay (now 2 seconds) is long enough with my laptop and webcam, but if I make the delay much shorter (e.g. 1 second) I only get a black image.

    If this program works (or doesn’t work) for you, please let me know so that I can try to improve it! Thanks

  4. S says:

    It is really good. Thanks!

  5. 刘江 says:

    Thanks for this. I just tested it though – my Fujitsu laptop has two cam. the first cam is Virtual webcam.can’t use it.only the second one can used. but,when i run the commandcam.
    such as:
    ” commandcam /devnum 2″
    “commandcam /devnum 2 /delay 5000″
    ” commandcam /devnum 2 5000″

    This is the error I was given:

    Capture device: FJ Camera
    Could not create capture filter

    • batchloaf says:

      Hi 刘江,
      Thanks very much for the feedback. Sorry to hear you’re having a problem with it. Two suggestions:

      1. Have you tried the most recent version of CommandCam? It’s available from this page.
      2. Once you have the most recent version of the program, can you please try running “CommandCam /devlist” to see what devices it finds?


  6. John Newall says:

    Hi Ted,

    first of all thanks for a great tool! I’ve tested it and found it just great.

    I would like to save files each minute over a 24 hour period and save the files to an external source. Is this possible?


    • batchloaf says:

      Hi John,

      Thanks for your comment. There are two ways you could do this.

      The first way is to write a batch file which calls CommandCam every 60 seconds for 24 hours (1440 times in total). Each time an image is saved, you rename it (and / or transfer it the file to another location). For example, save something like the following in a file called “cam.bat”:

          FOR /L %%i IN (1,1,1440) DO (
              rename image.bmp %%i.bmp
              sleep 60

      When you run “cam.bat” it should snap an image called “image.bmp” every 60 seconds and rename it to “1.bmp”, “2.bmp”, “3.bmp”, etc.

      Alternatively, I have another program called RobotEyez that I’ve been working on, which captures multiple images at a specified interval from a webcam. You can download it from Unfortunately, at the moment RobotEyez only saves images as PGM format which is probably not what you want. However, I suppose I could modify it to save BMP files instead if that would do the trick for you. Could you try running it to see if it works as it is? I’ve written a PGM image file viewer that you can download from the same page as RobotEyez, so you should be able to see if the PGM images are being saved correctly. PGM files are black and white, by the way, so if your images appear that way, that’s perfectly normal.


      • j says:

        Hi Ted,
        Thanks for the prompt reply!
        I tried the above batch and it takes the pictures and counts them up, that works fine – but the sleep command doesn’t seem to work properly, the camera takes a picture every couple of seconds, no matter the value (I also tried sleep 180 and sleep 1800 but it had no effect).

        Still to try the roboteyes, I’ll get back to you on that one.

      • batchloaf says:

        Hi John,
        I’m not sure whether the “sleep” command is available in every version of Windows. It’s working for me in XP, but if you’re running Vista or Windows 7 perhaps you might try replacing “sleep 60” with “timeout 60”. I expect it will probably have the same effect.
        Do try RobotEyez though – if it works for you, it’s probably more convenient than the batch file anyway.

    • batchloaf says:

      Actually, I’ve just added a bitmap output option to RobotEyez, so that’s probably the easiest thing to use. Here’s an example command

      RobotEyez /frames 1440 /period 60000 /number_files /bmp

      Here’s the link to the RobotEyez page:

  7. Steve Elwell says:

    Hi Ted,

    I am looking for a command line webcam picture taking program that when called will start the camera showing a preview but wait for a “take picture” button to be pressed or a function key on the keyboard to cause the image capture. Will CommandCam do this?


    • batchloaf says:

      Hi Steve,

      CommandCam isn’t really designed for this kind of picture taking (with user interaction I mean). It’s really intended for automating the process of capturing images using USB cameras. I’m pretty sure there are other programs that would do this for you though. VLC springs to mind as one application that I’ve used for this kind of thing in the past. Depending what version of Windows you’re using, you might even be able to run the built in snapshot utility for imaging devices (although I couldn’t get that to work in Windows 8 which is what I’m running now). Apart from that, there are tons of other programs, such as those listed here:

      Hope that helps.


      • Steve Elwell says:

        Hi Ted,

        Thank you for the reply. So my next question, how must would it cost to contract (PAY) you to write the click to take the picture into CommandCam? We would like to own the source code afterward of course. In that way we would hold the copyright and would not have to worry about copyright infringement.


  8. sreejith says:

    how to use it in remote desktop situations. Maybe hyou can help. ….

    • batchloaf says:

      I’m not quite sure what you mean. There shouldn’t be any particular problems running CommandCam on a remote computer that you’re logged into via remote desktop.

      Can you please explain exactly what’s not working for you?


  9. Pal Sch says:

    Cool tool… Worked perfectly. But if you dont’t know it just saves a picture in the current directory it could be you don’t see it works… Lucky me in my folder weren’t too many files!

    • batchloaf says:

      Thanks Pal,

      Yes, if you just specify a filename without a full path, the image will be saved in the current directory. However, using the “/filename” command line option, I think you should be able to specify a filename with a full path (e.g. “C:\images\pic.bmp”) to save the image in a location of your choice.

      Thanks again,

  10. Suresh says:

    Good work and Great tool. Its working fine without any problem
    I got some new idea on it, can we add a key stroke to capture ?
    it needs to wait until we need press a key (any letter “O” ?) so that we can adjust cam then we press key, then it will take image, got my point ?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s