3

I'm trying to build a simple app that captures video off of the built-in iSight camera of a MacBook. I've looked at a couple of example projects on the developer site and am following the tutorial here: Apple's AVFoundation Guide.

Each time I keep breaking on the AVCaptureMovieFileOutput, I get an uncaught exception - no active/enabled connections. I'm new to AV framework so I'm not sure why it recognizes the iSight, allows me to input it to the session, allows me to make a movie output for the session but then tells me there's no connections? What connections is it looking for? (Note: I do not have a QTMovieView in my viewcontroller yet but thought I would only need that for playback, not recording).

I know the iSight is working as I just used it recently with Skype.

Here's my relevant code:

thisSession = [[AVCaptureSession alloc] init];

//set presets for this session
if ([thisSession canSetSessionPreset:AVCaptureSessionPreset640x480]) {

    thisSession.sessionPreset = AVCaptureSessionPreset640x480;
    NSLog(@"Session Preset: OK");

    //capture a device - captures all the devices, microphone, camera, etc.
    NSArray *devices = [AVCaptureDevice devices];

    //this will hold our decvice
    AVCaptureDevice* iSightCamera;

    for (AVCaptureDevice *device in devices) {

        //we only want to work with the internal camera
        if ([[device localizedName] isEqualToString:@"Built-in iSight"]) { 

            iSightCamera = device;

            //creating an input of the device for the session
            NSError *error = nil;
            AVCaptureDeviceInput* iSightCameraInput =
            [AVCaptureDeviceInput deviceInputWithDevice:iSightCamera error:&error];
            if (!iSightCameraInput) {
                NSLog(@"Error creating device input: %@", error);
            } else { 
                NSLog(@"iSight device input created!");

                //adding the device input to the session
                if ([thisSession canAddInput:iSightCameraInput]) {

                    [thisSession addInput:iSightCameraInput];
                    NSLog(@"iSight input added to session!");

                    //add the output to the session
                    AVCaptureMovieFileOutput *movieOutput = [[AVCaptureMovieFileOutput alloc] init];

                    if ([thisSession canAddOutput:movieOutput]) {

                        [thisSession beginConfiguration];
                        [thisSession addOutput:movieOutput];
                        [thisSession commitConfiguration];

                        NSLog(@"Movie output added to the session!");

                        //start writing the movie
                        NSURL *movieFolder = [NSURL fileURLWithPath:[@"~/Movies" stringByExpandingTildeInPath]];

                        [movieOutput startRecordingToOutputFileURL:movieFolder recordingDelegate:self];
                    }
                    else {
                        NSLog(@"Error: Could not add movie output to the session.");
                    }
                }
                else {
                    NSLog(@"Error: Could not add iSight to session.");
                }

            }

        }

    }
PruitIgoe
  • 6,166
  • 16
  • 70
  • 137
  • Consider implementing this using AVFoundation API's. I was just reading [an opinion on the cocoa-dev mailing list](http://lists.apple.com/archives/cocoa-dev/2012/Jun/msg00163.html) that "the writing is on the wall for QTKit". Expect it to be deprecated pretty soon (I haven't checked to see if it's already been done in the 10.8 SDK). – Michael Dautermann Jul 19 '12 at 02:12
  • Did you try to download the sample code of MyRecorder and check if it works? – Avi Cohen Jul 19 '12 at 07:14

0 Answers0