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

Incredible Demos

  • By
    Scrolling “Go To Top” Link Using Dojo

    One of the most popular code snippets of posted on my blog has been the scrolling "Go To Top" link snippet. The premise of the snippet is simple: once the user scrolls an element (usually the BODY element) past a given threshold, a "Go...

  • By
    Create an Animated Sliding Button Using MooTools

    Buttons (or links) are usually the elements on our sites that we want to draw a lot of attention to. Unfortunately many times they end up looking the most boring. You don't have to let that happen though! I recently found a...

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!