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


  • I am Fernando Barajas. Mostly known as FernyB.

  • Recent Comments

    • carbonara72: Hi, This is a brilliant feature! I discovered LastBrigde.net a couple of days ago and was frustrated...
    • fernyb: @mike_rofone, I will kill your account, just a side note, I know it’s missing a feature to reset...
    • mike_rofone: Hey Dude, awesome work, it it’s set up it just works like a charm. Maybe I’m dumb but I...
    • mjm: Send me an invite? Thanx., mjm.ent -at- gmail
    • Steven Luscher: Awesome! Now what I’d really like is a way to scrobble tracks played on my SoundBridge…

    Recent Listened to Tracks

    Loading...


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


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

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