Capturing iSight from Macbook

Posted in Mac, Programming on Nov 04, 2008

Lately I’ve been writing Objective-C/Cocoa code, and lately I’ve learned how-to capture video from an iSight on a Macbook. It’s actually easy. Here is the code. and I’ve also attached the example application I was writing so you can take a look at it.

[Download Source]
[Download Application]

#import <Cocoa/Cocoa.h>
#import <QTKit/QTKit.h>

@interface MyRecorderController : NSObject {
  IBOutlet QTCaptureView * mCaptureView;
  QTCaptureSession       * mCaptureSession;
  QTCaptureDeviceInput   * mCaptureDeviceInput;
}

- (IBAction)startRecording: (id)sender;
- (IBAction)stopRecording: (id)sender;

@end

@implementation MyRecorderController

- (IBAction)startRecording: (id)sender
{
  // Create a new Capture Session
  mCaptureSession = [[QTCaptureSession alloc] init]; 

  //Connect inputs and outputs to the session
  BOOL success = NO;
  NSError *error;

  // Find a video device
  QTCaptureDevice *device = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeVideo];
  if(device) {
    success = [device open:&error];
    if(!success) {
      // Handle Error!
    }
    // Add the video device to the session as device input
    mCaptureDeviceInput = [[QTCaptureDeviceInput alloc] initWithDevice:device];
    success = [mCaptureSession addInput:mCaptureDeviceInput error:&error];
    if(!success) {
      // Handle error
    }

    // Associate the capture view in the UI with the session
    [mCaptureView setCaptureSession:mCaptureSession];

    // Start the capture session runing
    [mCaptureSession startRunning];

  } // End if device
}

- (IBAction)stopRecording: (id)sender
{
  if([mCaptureSession isRunning]) {
     [mCaptureSession stopRunning];
     [mCaptureSession release];
     [mCaptureDeviceInput release];
  }
}

@end

Trackback URI | Comments RSS

2 Responses to “ Capturing iSight from Macbook ”

  1. # 1 DennisBB Says:

    That’s kool d00d

    Haven’t tried it yet, but once I’ll have time

  2. # 2 Deeann Tonsil Says:

    OK! Perfect spill. I place these the most power for the cost Lighting units for indoor marijuana growing ever. I’ve never heard indoor plants take growth like this.

Leave a Reply

  • Recent Comments

    • tory burch canvas tote: Incredible, I actually better begin saving this money. Really like a lot of these kind of...
    • Kostenloser Stromanbieter Vergleich online: A truly gripping article. I leave maintain to supervise it.
    • a4928971: I’ve said that least 4928971 times. SCK was here
    • Jennifer Youns: Many thanks to you for sharing these kind of wonderful content. In addition, the optimal travel plus...
    • Alonzo Williams: Thanks for your write-up on the travel industry. We would also like to add that if you’re a...

    Recent Listened to Tracks

    Loading...

Bad Behavior has blocked 192 access attempts in the last 7 days.

eastern-avalanche
eastern-avalanche
eastern-avalanche
eastern-avalanche