Discussion:
Display USB Video Camera output : AVFoundation?
Jerry Krinock
2015-09-10 04:22:15 UTC
Permalink
In a Mac app, I need to display real-time video (as in “movies”) from a USB camera on the screen. Can someone please confirm that AVFoundation the way to go?

I’ve read that QTKit is deprecated but, oddly, I cannot find any mention of deprecation here in the QTKit Programming Guide:

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/QTKitApplicationProgrammingGuide/

Thank you,

Jerry


_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

This email sent to ***@ml-i
Jens Alfke
2015-09-10 04:46:07 UTC
Permalink
Post by Jerry Krinock
In a Mac app, I need to display real-time video (as in “movies”) from a USB camera on the screen. Can someone please confirm that AVFoundation the way to go?
I can confirm that it’s easy to use AVFoundation to display live video from the built-in webcam on a MacBook Pro. I would guess that it also works for other cameras recognized by the OS; the standard live-video view has a control to switch the input source.

—Jens
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.n
Shane Stanley
2015-09-10 04:51:44 UTC
Permalink
Post by Jerry Krinock
In a Mac app, I need to display real-time video (as in “movies”) from a USB camera on the screen.
Have a look at the sample code AVRecorder.
--
Shane Stanley <***@myriad-com.com.au>
<www.macosxautomation.com/applescript/apps/>


_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

This email sent to g
Quincey Morris
2015-09-10 05:08:55 UTC
Permalink
The lack of a mention of deprecation isn’t so odd if you scroll to the bottom of the page and note that the last update was in 2009. It’s worth training yourself to check the update date before you believe anything you read in any of the programming guides. (And at the speed things change, I’d avoid believing any document that’s more than 2 or 3 years old. It’s getting to the point where the only trustworthy documents are those written in the future.)

If you follow the links through to specific QTKit classes, you’ll see that absolutely everything was deprecated in 10.9, except for the QTMovieModernizer class, which was added in 10.9.


_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.nar
Britt Durbrow
2015-09-10 06:53:37 UTC
Permalink
One of my projects (still on the back burner at the moment, but slowly progressing nonetheless) is a DIY pick-and-place machine for doing small-run electronics. It uses standard VGA-quality USB webcams (such as the type that you can get off of eBay for under $10 each… often under $4) to do the component-detection machine vision; and I do have the video input section of the project seeing the webcams with AVFoundation.

So if that’s the kind of camera in question… yeah, it works.

:-)
Post by Jerry Krinock
In a Mac app, I need to display real-time video (as in “movies”) from a USB camera on the screen. Can someone please confirm that AVFoundation the way to go?
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/QTKitApplicationProgrammingGuide/
Thank you,
Jerry
_______________________________________________
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
https://lists.apple.com/mailman/options/cocoa-dev/bdurbrow%40rattlesnakehillsoftworks.com
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

This email sent
Gordon Apple
2015-09-10 14:50:11 UTC
Permalink
First, yes, AVFoundation is the way to go.

Second, you can use AVCaptureView or AVCaptureVideoPreviewLayer. II
recommend that you don¹t subclass AVCaptureVideoPreviewLayer, but rather
embed it in your own custom CALayer. That gives you more freedom of control,
and if you want to do things like clipping and add shadows, you can do it.
Otherwise the capture layer will clip the shadows.

Our (still unreleased) application allows any number of cameras to be used
simultaneously, with individual display parameters. You can even (installing
their driver) use a $5 app, PocketCam, as a wireless remote video camera
input.
In a Mac app, I need to display real-time video (as in ³movies²) from a USB
camera on the screen. Can someone please confirm that AVFoundation the way to
go? I¹ve read that QTKit is deprecated but, oddly, I cannot find any mention
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/QTKitAp
plicationProgrammingGuide/ Thank you, Jerry
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

This email sent to ***@ml-in.narkive.n
Jerry Krinock
2015-09-11 05:38:33 UTC
Permalink
Post by Gordon Apple
Second, you can use AVCaptureView or AVCaptureVideoPreviewLayer.
Holy cow. I just instantiated an AVCaptureView in InterfaceBuilder, added AVKit.framework to the project, build, run and what to my wondering eyes did appear but my ugly face, live on my screen, via the FaceTime camera!!

I still have to figure out how to get rid of the little control strip which appears at the bottom of the view when you mouse over it, and how to programatically select an external USB camera, but considering that I have read zero pages of documentation so far, I have high hopes that these tasks will be straightforward.




_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narki
Jerry Krinock
2015-09-12 22:49:32 UTC
Permalink
Well, AVCaptureView is not very malleable. I needed to use an AVCaptureVideoPreviewLayer, which needed quite a few more lines of code than the zero I reported yesterday :( For the record, I have pasted in the working code below.

The only problem is that this silly warning prints to the console whenever my view loads:

CoreAnimation: Warning! CAImageQueueSetOwner() is deprecated and does nothing. Please stop calling this method.

I am doing no such thing. This is built with the 10.10 SDK, running in 10.11. Can anyone explain? Otherwise I’ll report as a bug in 10.11.

Jerry


*** Camera.h ***

@interface Camera : NSObject

+ (Camera*)sharedCamera ;

- (BOOL)startInView:(NSView*)view
error_p:(NSError**)error_p ;

@end


*** Camera.m ***

#import <AVFoundation/AVFoundation.h>

static Camera* sharedCamera = nil ;

@interface Camera ()

@property AVCaptureSession* session ;

@end

@implementation Camera

+ (Camera*)sharedCamera {
if (sharedCamera == nil) {
sharedCamera = [[self alloc] init] ;
}

return sharedCamera ;
}

- (BOOL)startInView:(NSView*)view
error_p:(NSError**)error_p {
BOOL ok = NO ;
NSError* error = nil ;

AVCaptureDevice* device = nil ;
for (device in [AVCaptureDevice devices]) {
/* We want an external video camera. Grab the first device which will
do video and is not vended by Apple Inc. This code could be improved
if more properties of the intended camera were available. */
if ([device hasMediaType:AVMediaTypeVideo]) {
NSString* modelID = [device modelID] ;
if ([modelID rangeOfString:@"VendorID_0x106B"].location == NSNotFound) {
ok = YES ;
break ;
}
}
}

if (!ok) {
NSDictionary* info = @{
NSLocalizedDescriptionKey
: NSLocalizedString(@"No external camera found", nil),
} ;
error = [NSError errorWithDomain:kMyErrorDomain
code:258740
userInfo:info] ;
}

AVCaptureDeviceInput* input = nil ;
if (device) {
input = [[AVCaptureDeviceInput alloc] initWithDevice:device
error:&error] ;
if (!input) {
ok = NO ;
}
}

if (ok) {
self.session = [[AVCaptureSession alloc] init] ;
[self.session addInput:input] ;

AVCaptureVideoPreviewLayer* layer ;
layer = [AVCaptureVideoPreviewLayer layerWithSession:self.session] ;
layer.contentsGravity = kCAGravityResizeAspectFill ;

view.layer = layer ;
[view setWantsLayer:YES] ;
layer.contentsGravity = kCAGravityResizeAspectFill ;
view.layerContentsRedrawPolicy = NSViewLayerContentsRedrawDuringViewResize ;
view.layerContentsPlacement = NSViewLayerContentsPlacementCenter ;

layer.frame = view.bounds ;

[self.session startRunning] ;
}


if (error && error_p) {
*error_p = error ;
}

return ok ;
}

@end


_______________________________________________

Cocoa-dev mailing list (Cocoa-***@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/gegs%40ml-in.narkive.net

This email sent to

Loading...