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

One Response to “ Capturing iSight from Macbook ”

  1. # 1 DennisBB Says:

    That’s kool d00d

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

Leave a Reply

  • Recent Comments

    • Ahmed: @fernyb.. Thanks man! I forked the project, but I am newbie in open source, and don’t know where to...
    • fernyb: @Ahmed, yeah you can help. It’s hosted on (http://github.com/fernyb/Cupc ake) so you can also fork it...
    • Ahmed: And hey! Can I help with your new PHP framework? plssssssssss :( (
    • Ahmed: hmmmmm I just wanna ask you about something… did you ever create API for Craigslist? I am thinking of...
    • Matt James: Same here… amazing project that I have been very happily using for a while. Sadly it seems to be...

    Recent Listened to Tracks

    Loading...


My blog is worth $1,693.62.
How much is your blog worth?


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

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