Tuesday 31 January 2012

UVC webcam exposure under Mac OS X

Apple's Mac OS X includes drivers for USB Video Device Class (UVC) cameras, which means that most webcams, including  the Xbox Live Vision, are just plug and play without needing to install any specialist drivers. However, the Apple provided webcam software Photo Booth doesn't allow any control over things like the exposure, gain, or frames per second (FPS), which are quite important in astrophotography. And it only captured at 640 × 426 pixels. So what can we do about this?

I would like to use a particular UVC webcam, the Xbox Live Vision, USB identifiers 0x045e 0x294, but most of the problems below are down to trying to use Mac OS X for webcam astrophotography.

Although not free, iUSBcam looked possible - but surprisingly it says it is not compatible with Snow Leopard or Lion. This company seems to have switched their efforts to iGlasses 3 which does support Snow Leopard and Lion. This does allow exposure control, but I suspect it is done with image processing rather than the camera settings which is what I want. I did contact their support for clarification, but heard nothing back.

Back in July 2009, Dominic Szablewski demonstrated it was possible to control the exposure, white balance and gain directly with a demo application using QTKit. I had a little play with it - it compiled fine with Xcode 4.2 on Lion after running the update project option, but I failed to get it to show any signal from any of the USB webcams I tried - it insisted on using the laptop's built in camera.

What I would like is either a more sophisticated web camera app for the Mac that allows access to these settings and record images or movies with them, or a way of changing the settings at the driver level for all applications. That seems to be what Max Grosse set out to do in Feb 2010, write an alternative Mac UVC camera driver, which he released in March 2010. The code is in his SVN repository, so I took a look:

svn co http://svn.ioctl.eu/mac_uvc/trunk/mac_uvc

The last revision was from Nov 2010, and there doesn't seem to be any instructions which would have been on Max's website but that page was lost in an upgrade. However, I could find a uvc_mac wiki snapshot from March 2010 which included important details like the code is released under the free zLib-License, was still considered unstable, and the API likely to change. Folder uvc/ contains the uvc.framework, while UVCCap/ contains a very basic sample application (Cocoa) that uses the framework to render the video stream. There is also a third folder, UVCCap_Old which I think we can ignore. I didn't get very far with this.

Where next? Perhaps macam will assist me - I had a look on the list of web cameras supported in macam for the Xbox Live Vision camera (which I'm hooking up to my telescope). Sadly the Xbox Live Vision isn't supported in macam, just via UVC. I tried anyway, but neither it nor two other USB webcams I had seem to show up in the macam v0.9.2 application. Issue logged.

Maybe I should just spend some more money tracking down a Phillips SPC900NC which should work in macam? It would probably make life easier as this is quite a popular webcam for astrophotography, so other people have posted recommended settings etc.

Reading the CloudyNights post on Webcam Astrophotography on the Mac there are also commercial webcam drivers from IOXperts, but they seem quite old - even support for Mac OS X 10.5 Leopard is currently in beta - and they don't seem to support the Xbox webcam anyway.

On the image capture side, I've downloaded Nebulosity 2 (free demo mode), but it doesn't seem to support any USB web cameras. Likewise their free mini-app, Craterlet for Mac only handles some firewire cameras.

I've also downloaded Equinox Pro 7 (free demo mode), which do a lot of stuff but go to the menu "Connect", "Webcam" (or Apple+Shift+W) and it seems to work with my webcam - and has some sort of exposure controls. This looks promising in that I could record some movies where Jupiter was not too washed out, which seemed to be the typical result using Photo Booth. Also it only recorded QuickTime movies at 640 × 480 pixels (VGA, better than just 640 × 426 with Photo Booth), both only managing up to 10 FPS at these light levels.

However, running under Linux on my elderly old laptop, wxAstroCapture version 1.8-1 (the 23 Oct 2010 beta) offers to connect to the Xbox Live Vision at resolutions of 320×240,  352× 288,  640 × 480,  960 × 720 and 1280 × 960 pixels (YUYV). It lets me turn off auto-exposure and set the gain and shutter speed manually. It lets me adjust the gamma, brightness and try to set the frames per second (FPS) - although unsurprisingly that seems to be limited according to the image size.

It looks like life would be easier for image capture if I switched to Windows or Linux... maybe there is a role for my elderly old Linux laptop yet?

Update

I found a nice little command line app for capturing webcam frames under Mac OS X called ImageSnap, but it doesn't seem to have any code for controlling the image settings.


I've since found other public grumbles about Apple crippling their camera capture API, e.g.
There currently is no way to change the exposure, gain, etc. ... via the QTKit Capture APIs (duplicate rdar://5760371 "Ability to set brightness, gain, etc. for cameras in QTKit Capture API" if you'd like this functionality). – Brad Larson, 15 March 2011
Also see this blog post on disabling auto-exposure and auto-whitebalance features of a UVC webcam, which would also be useful for astrophotography.

7 comments:

  1. Hi and thx for the helpful posts. I have a different need, but maybe similar solution. I purchased a 27 inch Asus monitor that has a built in webcam. The monitor came with software for windows but no support for Mac. Hard to believe the webcam is NOT UVC, but the Mac OSX just cannot see the camera properly. On some applications it can see the cam but picture is all black.

    I am looking for a "generic" driver that would allow the web cam to work. Do you think your work would help me? If so, pls let me know.

    I am not a techie, so if there is code to install, I'd need help.

    Best

    John

    ReplyDelete
  2. Hi John - I've not tackled drivers at all. Try opening the Mac terminal application (command line window) and running 'system_profiler SPUSBDataType' (no quotes, one command with a space then the argument) to see if you can get the USB identifiers for the webcam inside your Asus monitor (assuming it is USB). There may be a GUI way to do that but I've not checked. Then try Google searching with them. I'd guess drivers from the macam project will be your best bet.

    ReplyDelete
  3. Came across this trying to solve a similar problem, but had one slight thing to add…

    Dominic Szablewski's demo app is hardcoded to select the first video device, which is why it was always using your internal webcam. You can change this index by editing line 7 of CameraControlAppDelegate.m.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. Hi Peter

    I can confirm that "Webcam Settings", on the App store, works with the live cam and will adjust exposure correctly. Worth pointing out that the camera gets stupidly hot - it's worth heatsinking the microsoft chip on the back of the PCB. You can change the settings in the app and then take the image using photo booth - hacky, but works in a pinch.

    Clearly it's possible to fiddle these settings from within OS X, here's to open source drivers eventually. I'm working on finding a better solution too.

    Josh

    ReplyDelete
  6. Sadly, I am fighting to find a way to drive my Phillips SPC900 cam with my Mac running 10.7.5. I downloaded the MACAM app which seems to play nice with the camera, that is until I go to start recording. Then it deposits a ".mov" file on my desktop and promptly quits.

    So close, yet sooo far...

    ReplyDelete
  7. I have been trying to use an HP webcam for astro (& teaching) work, where I need to set the focus, and also the exposure. A command-line program called uvc-ctrl (http://www.dm9.se/?tag=uvc-ctrl) will actually set the params correctly for *some* recording programs, as long as they don't grab the camera with exclusive access. There is a gui, but it never worked for me. You do need a separate recording program, and I've been playing with variants on the Apple demo 'MyRecorder'. QuicktimeX doesn't work with uvc-ctrl, although PhotoBooth does.

    ReplyDelete