ImageSnap: Capturing a Video Image with QTKit on Snow Leopard September 14, 2009
Posted by Robert Harder in : Utility , trackbackImageSnap 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.
Comments»
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 ?
That’s pretty big. Are you saving as an uncompressed image like TIFF or PNG?
Found and fixed a bug that caused images to save as TIFF. Probably explains problem above. Fixed in v0.2.3. -Rob
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
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
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
EHB, that’s good to hear. I wish we could figure out where these _NXCreateWindow errors are coming from. -Rob
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?
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
In order to prevent this “CGSWindow” thing, you need to call NSApplicationLoad() in main().
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
Just letting you know that the Beta 0.2.4 did work on 10.5.8.
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/
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.
@Syl That does seem strange. Nothing comes to mind that mind account for it. -Rob
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#
@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.
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.
@James I should be able to add a warmup delay. Will see what I can do…
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