Access Mac Camera by Command Line

By  on  
FaceTime HD Camera

With all of my recent command line tutorials, I've really gotten excited about the shell's simplicity and realized the true power of using the underlying technology of pretty UIs.  Since I work from home, I spend a lot of time on video calls, so when I started playing around with command line utilities like ImageMagick and ffmpeg, I instantly asked myself:  how can I take a photo with the Mac's camera from within the terminal?

It turns outs out OS X doesn't provide that access; a third party utility named ImageSnap is the best route to taking captures from command line.

Install ImageSnap

I like using Homebrew to manage installs:

brew install imagesnap

You can compile from source if you like, obviously.

Take a Photo

To take a photo using the default video input device (FaceTime HD Camera is the default in most newer Macs), simply execute this:

# Take image, let camera warm up 1 second
imagesnap -w 1 snapshot.png

You'll wait a brief second or two, your green camera indicator will light up, and will then quickly fade out.  The image will be saved to a snapshot.png file.

ImageSnap also has the functionality to take a photo every n seconds:

# imagesnap -t {x}:{yy} seconds
imagesnap -t 1 -w 1

The command above takes a photo every second until the process is killed.

While I looked for this ability out of curiosity, there are some great use cases for taking images from command line, like tracking your Mac if it's stolen or taking a photo upon invalid login.  Imagesnap is an incredible utility:  simple to use and doesn't try to accomplish too much!

Recent Features

  • By
    Camera and Video Control with HTML5

    Client-side APIs on mobile and desktop devices are quickly providing the same APIs.  Of course our mobile devices got access to some of these APIs first, but those APIs are slowly making their way to the desktop.  One of those APIs is the getUserMedia API...

  • By
    Creating Scrolling Parallax Effects with CSS

    Introduction For quite a long time now websites with the so called "parallax" effect have been really popular. In case you have not heard of this effect, it basically includes different layers of images that are moving in different directions or with different speed. This leads to a...

Incredible Demos

  • By
    MooTools Zoomer Plugin

    I love to look around the MooTools Forge. As someone that creates lots of plugins, I get a lot of joy out of seeing what other developers are creating and possibly even how I could improve them. One great plugin I've found is...

  • By
    Fix Anchor URLs Using MooTools 1.2

    The administrative control panel I build for my customers features FCKEditor, a powerful WYSIWYG editor that allows the customer to add links, bold text, create ordered lists, and so on. I provide training and documentation to the customers but many times they simply forget to...

Discussion

  1. The utility requires a full installation of Xcode to compile this software. :P

  2. This is awesome, I didn’t know it but I’ve been looking for a utility like this for awhile now.

    Also, not to be a stick in the mud, but I’m sure you mean Facetime and not Facebook HD Camera ;)

  3. Eduardo

    I can’t install imagesnap even after installing homebrew..

  4. zalun

    I had to delay the snapshot for almost a second as photo was pure black.

    imagesnap -w 1
  5. Patricio

    is there anyway to record mac camera since terminal?

  6. JD

    Where do the images save?

  7. Crusty

    How to use Terminal to discover if any application is using my Facetime camera? With the command lsof I get all the application who request the process, but not which is using right now

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!