Home > Utility > ImageSnap: Capturing a Video Image with QTKit on Snow Leopard

ImageSnap: Capturing a Video Image with QTKit on Snow Leopard

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 28th, 2009 at 09:05 | #1

    Hi,
    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 ?

  2. September 28th, 2009 at 09:50 | #2

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

  3. October 13th, 2009 at 12:55 | #3

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

  4. Jesse Thouin
    December 11th, 2009 at 13:22 | #4

    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.

    Thanks,
    Jesse

    thouin @ verypopularemailthatstartswithG

  5. January 10th, 2010 at 16:05 | #5

    Hello.
    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)
    Error.
    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.

    JP

  6. EHB
    January 17th, 2010 at 10:52 | #6

    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

  7. January 18th, 2010 at 10:29 | #7

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

  8. Josh
    January 21st, 2010 at 22:06 | #8

    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?

  9. February 10th, 2010 at 16:09 | #9

    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

  10. KD
    February 28th, 2010 at 19:36 | #10

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

  11. March 1st, 2010 at 11:33 | #11

    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.

    http://dl.dropbox.com/u/4303707/ImageSnap-v0.2.4beta.tgz

    -Rob

  12. JBL
    March 3rd, 2010 at 15:53 | #12

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

  13. March 4th, 2010 at 11:04 | #13

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

    http://iharder.sourceforge.net/current/macosx/imagesnap/

  14. Syl
    June 27th, 2010 at 20:05 | #14

    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.

  15. June 30th, 2010 at 12:51 | #15

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

  16. James
    March 14th, 2011 at 20:50 | #16

    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@192.168.2.139 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#

  17. March 15th, 2011 at 00:36 | #17

    @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.

  18. James Seigel
    April 27th, 2011 at 21:09 | #18

    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!

    Cheers
    James.

  19. April 29th, 2011 at 08:31 | #19

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

  20. February 9th, 2012 at 19:23 | #20

    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

  21. Mark
    July 9th, 2013 at 21:21 | #21

    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.

  22. July 18th, 2013 at 18:11 | #22

    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!

  1. No trackbacks yet.