jump to navigation

ImageSnap: Capturing a Video Image with QTKit on Snow Leopard September 14, 2009

Posted by Robert Harder in Utility.
Tags: , , , , ,

ImageSnap is a Public Domain command-line tool that lets you capture still images from an iSight or other video source. You might remember Axel Bauer’s original isightcapture tool (that is no longer supported but still works on most systems). I wanted a similar tool with source available so I could make feature changes or at least recompile with Apple’s ever-changing architectures.

At some point Apple introduced QTKit, a new and oh-so-welcome abstraction bringing QuickTime programming into the 21st century. Nothing against die-hard ANSI C programming, but it fits awkwardly into what are otherwise clean Objective-C Cocoa programs.

Rather than provide a detailed tutorial about using QTKit (sorry if you wanted one), I’ll just point you to the ImageSnap code so you can take a look at a few useful things like starting a QTCaptureSession, capturing output with QTCaptureDecompressedVideoOutput, and saving an NSImage to disk.


1. Lexel - September 28, 2009

Thanks for this tool, wich works as a charm,
but…the pict is a little bit to large 5,3 Mo, is there a way to reduce it ?

Robert Harder - September 28, 2009

That’s pretty big. Are you saving as an uncompressed image like TIFF or PNG?

2. Robert Harder - October 13, 2009

Found and fixed a bug that caused images to save as TIFF. Probably explains problem above. Fixed in v0.2.3. -Rob

3. Jesse Thouin - December 11, 2009

Cool idea, but I’m getting this error when I run imagesnap:

_NXCreateWindow: error setting window property (1002)
_NXTermWindow: error releasing window (1002)

I read somewhere (http://cocoadev.com/forums/comments.php?DiscussionID=372) about using this:

[NSApplication sharedApplication];

Do you think that would solve the problem? I don’t have XCode (Linux at Work, Mac at home), so I’m not able to compile and test. Email me directly if you get this anytime soon.


thouin @ verypopularemailthatstartswithG

4. JP - January 10, 2010

The imagesnap program seems to be very useful, however I’m having the same problem Jesse Thouin just described. The iSight camera briefly tuns on, then shows these messages:

2010-01-10 23:01:37.064 imagesnap[4577:807] _NXCreateWindow: error setting window property (1002)
2010-01-10 23:01:37.318 imagesnap[4577:807] _NXTermWindow: error releasing window (1002)
Capturing image from device “Built-in iSight”…

And finally exits, with no image captured.

It would be great if you could make it work.

Thanks in advance for such a useful replacement of isightcapture.


5. EHB - January 17, 2010

Hi Robert,

thanks for releasing imagesnap. i’ve had fun messing around with running it from applescript, mainly as an attempt to start learning some programming skills, and have just submitted a hint using it to Mac OS X Hints. Hopefully someone might find it useful.

I didn’t have any of the problems mentioned above. It worked straight out of the tin, unlike iSightCapture, which I could only seem to run from a terminal window rather than as a ‘do shell script’

thanks again

6. Robert Harder - January 18, 2010

EHB, that’s good to hear. I wish we could figure out where these _NXCreateWindow errors are coming from. -Rob

7. Josh - January 21, 2010

I made the Debug version, and it errors out with this (followed by the stack trace):

imagesnap[9714:10b] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Error (1002) creating CGSWindow’

It’s on Leopard, not Snow Leopard. Does that make a difference?

8. Robert Harder - February 10, 2010

This seems to be a Leopard/Snow Leopard thing. One technique works in L and not SL, and the other technique is the opposite. -Rob

9. KD - February 28, 2010

In order to prevent this “CGSWindow” thing, you need to call NSApplicationLoad() in main().

10. Robert Harder - March 1, 2010

Need some beta testers to try out the version with NSApplicationLoad(). It doesn’t crash 10.6 (as the sharedApplication call did), but I don’t have 10.5 to test on, so I need some help. Thanks.



11. JBL - March 3, 2010

Just letting you know that the Beta 0.2.4 did work on 10.5.8.

12. Robert Harder - March 4, 2010

OK, the ImageSnap home page now links to v0.2.4 (no longer beta). Hope it works for everyone! -Rob


13. Syl - June 27, 2010

I’m having a strange issue with ImageSnap. When executing it over ssh, it will work the first one or two times, but thereafter the saved image consists solely of uniform green pixels. The light on the iSight does blink, so it does seem to be accessing the camera.

14. Robert Harder - June 30, 2010

@Syl That does seem strange. Nothing comes to mind that mind account for it. -Rob

15. James - March 14, 2011

I too am seeing the green snapshot on some machines – although most iMacs work. I have not found a pattern to it except every machine showing the error below. (Snow Leopard 10.6.6)

svr:~ root# ssh admin@ imagesnap /tmp/snap.jpg
Tue Mar 15 13:32:14 iMac.local imagesnap[721] : kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
Capturing image from device “Built-in iSight”…/tmp/snap.jpg
svr:~ root#

16. Robert Harder - March 15, 2011

@James That’s pretty weird. I can’t duplicate it. The window server error reminds me of errors I used to get trying to run X11 apps on a headless Solaris box — their was a mismatch between the windowing environment that was present (or not present) and what the app expected. I’m just not sure.

17. James Seigel - April 27, 2011

Thanks for keeping up your responses to this lovely piece of code. I had a question about where I should/could put a delay in to give my camera more of a chance to auto adjust for brightness. On my old machine it seemed to take great pictures, now when it is too bright out it it just a white canvas. The laptop it is on now is significantly faster.

g4 -> 2.3 intel dual core

The camera is a usb Microsoft Lifecam HD-6000

Any help would be awesome!


18. Robert Harder - April 29, 2011

@James I should be able to add a warmup delay. Will see what I can do…

19. Rabhoabesat - February 9, 2012

They are created up of low-priced materials and therefore are inadequately place together.You must learn the way to spot fake Chanelabsolutely among the better Chanel handbags that help in retaining a lot of things within the handbag inside a additionalfactors are checked, you’ll be able to preserve your funds and obtain applied bags in place of original kinds.So ladies, the subsequentmanage to get new bags, 2nd hand bags are without a doubt a very smart alternate. The trick simply just lies inauction web-sites. Inside the sites when your bid would be the highest, it is possible to nonetheless acquire the Chanel purse at awfully beats by dre shop every now and then. For example, you’ll find deals around 75% to the Memorial Day sale. You’ll find evenand is also at no cost. Besides, you can find a ensure of complete satisfaction to you personally, having a facility of moneyphysical shop which has fixed timings. Therefore, for all those who have been on the lookout for handy alternatives to getand irrespective of whether or not it’s garments, sneakers, bags, components, or perfumes, all that originates fromtowards the world-wide-web for some on-line Chanel looking.What waits in your case there is certainly a Chanel bags online store, and

20. Mark - July 9, 2013

Running on 10.7 and target as well is..
Getting this error on the .25 install…

imagesnap[1096] : kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
No video devices found.

21. http://www.windshieldreplacement-coloradosprings.com - July 18, 2013

you are in reality a just right webmaster. The site
loading velocity is incredible. It seems that you are doing any unique trick.
Also, The contents are masterwork. you have done a fantastic job on
this matter!

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: