Himanshu Joshi
Himanshu Joshi

Reputation: 3399

Unexpected behaviour of AVCaptureMovieFileOutput

I am making a movie of screen using AVCaptureMovieFIleOutput, but it is showing unexpected behaviour.

Like, if I am sending the cropRect parameter the movie captured is fine, but if I making the movie of whole screen instead of movie file it is showing a folder. How can I get rid of that?

Code is :

    // Create a capture session
    mSession = [[AVCaptureSession alloc] init];

    // If you're on a multi-display system and you want to capture a secondary display,
    // you can call CGGetActiveDisplayList() to get the list of all active displays.
    // For this example, we just specify the main display.
    CGDirectDisplayID displayId = kCGDirectMainDisplay;

    // Create a ScreenInput with the display and add it to the session
    input = [[AVCaptureScreenInput alloc] initWithDisplayID:displayId];

    [input setCropRect:rect];

    if (!input) {
        mSession = nil;
        return;
    }
    if ([mSession canAddInput:input])
        [mSession addInput:input];

    // Create a MovieFileOutput and add it to the session
    mMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
    if ([mSession canAddOutput:mMovieFileOutput])
        [mSession addOutput:mMovieFileOutput];

    // Start running the session
    [mSession startRunning];

    // Delete any existing movie file first
    if ([[NSFileManager defaultManager] fileExistsAtPath:[destPath path]])
    {
        NSError *err;
        if (![[NSFileManager defaultManager] removeItemAtPath:[destPath path] error:&err])
        {
            NSLog(@"Error deleting existing movie %@",[err localizedDescription]);
        }
    }

    // Start recording to the destination movie file
    // The destination path is assumed to end with ".mov", for example, @"/users/master/desktop/capture.mov"
    // Set the recording delegate to self
    [mMovieFileOutput startRecordingToOutputFileURL:destPath recordingDelegate:self];

Upvotes: 1

Views: 236

Answers (1)

Himanshu Joshi
Himanshu Joshi

Reputation: 3399

Have to use setSessionPreset property.

Default value of sessionPreset is AVCaptureSessionPresetHigh and it does not work with the full screen capture. Will have to provide any other preset for that.

Upvotes: 1

Related Questions