OGeek|极客世界-中国程序员成长平台

标题: IOS8:录制到文件并使用 AVCaptureSession/commitConfiguration 时相机预览闪烁 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 12:17
标题: IOS8:录制到文件并使用 AVCaptureSession/commitConfiguration 时相机预览闪烁

自从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 startRecordingToOutputFileURLutputUrl recordingDelegate:self];
  } 



Best Answer-推荐答案


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

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

关于IOS8:录制到文件并使用 AVCaptureSession/commitConfiguration 时相机预览闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26573580/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4