IOS8:录制到文件并使用AVCaptureSession / commitConfiguration时,摄像头预览会闪烁

时间:2014-10-26 13:36:53

标签: ios ios8 avfoundation avcapturemoviefileoutput

自从IOS8以来,我在使用commitConfiguration时遇到了一个奇怪的问题 我们通过AVCaptureMovieFileOutput记录5秒文件。更改文件时,相机预览会闪烁并淡化为黑色一秒钟。缝合接收服务器上的文件时也会出现断断续续的情况。

// method that switches the output file
- (void) switchOutputFile {
    NSURL *outputUrl = [self getOutputFileUrl];
    NSLog(@"Switching to: %@", outputUrl);

    // begin configuration
    [self.captureSession beginConfiguration];

    // remove the current writer
    [self.captureSession removeOutput:self.fileOutput];

    // attach new writer
    self.fileOutput = [self attachFileWriter:self.captureSession];

    // commit configuration
    [self.captureSession commitConfiguration];

    // after this line the camera preview flickers.
    [self.fileOutput startRecordingToOutputFileURL:outputUrl recordingDelegate:self];
  } 

1 个答案:

答案 0 :(得分:2)

解决方案非常简单 - 不删除并添加编写器。感谢来自苹果的bford的解释! 这是更新的函数方法

// method that switches the output file
- (void) switchOutputFile {
    NSURL *outputUrl = [self getOutputFileUrl];
    NSLog(@"Switching to: %@", outputUrl);
    [self.fileOutput startRecordingToOutputFileURL:outputUrl recordingDelegate:self];
}