AVCaptureMovieFileOutput的意外行为

时间:2014-01-06 07:30:37

标签: xcode macos

我正在使用 AVCaptureMovieFIleOutput 制作一部电影,但它显示出意想不到的行为。

就像,如果我发送cropRect参数,捕获的电影很好,但是如果我制作整个屏幕的电影而不是电影文件,它会显示一个文件夹。我怎么能摆脱它?

代码是:

    // 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];

1 个答案:

答案 0 :(得分:1)

必须使用setSessionPreset属性。

sessionPreset的默认值为AVCaptureSessionPresetHigh,它不适用于全屏捕获。将不得不为此提供任何其他预设。