【问题标题】:Crash - AVCaptureSessionPresentMedium in the iPhone XS崩溃 - iPhone XS 中的 AVCaptureSession 预设中
【发布时间】:2018-10-01 14:12:05
【问题描述】:

我在成功捕获图像后尝试捕获视频并且我的应用程序崩溃了。

if (iSRecordVideo) {
        DLog(@"iSRecordVideo");
        //ADD AUDIO INPUT
        AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
        NSError *error = nil;
        AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioCaptureDevice error:&error];
        if (audioInput)
        {
            [[self captureSession] addInput:audioInput];
        }

        //ADD MOVIE FILE OUTPUT
        self.videoOutput = [[AVCaptureMovieFileOutput alloc] init];

        Float64 TotalSeconds = 20;          //Total seconds
        int32_t preferredTimeScale = 20;    //Frames per second
        self.maxDuration = CMTimeMakeWithSeconds(TotalSeconds, preferredTimeScale); //<<SET MAX DURATION
        self.videoOutput.maxRecordedDuration = self.maxDuration;
        self.videoOutput.minFreeDiskSpaceLimit = 1024 * 1024;//<<SET MIN FREE SPACE IN BYTES FOR RECORDING TO CONTINUE ON A VOLUME


        if (IS_IPHONE_X_S_MAX)
        {
            [self.captureSession setSessionPreset:AVCaptureSessionPresetMedium];
        }
        else
        {
            [[self captureSession] setSessionPreset:AVCaptureSessionPresetMedium];
        }


        if ([[self captureSession] canAddOutput:self.videoOutput])
            [[self captureSession] addOutput:self.videoOutput];

        //SET THE CONNECTION PROPERTIES (output properties)
        [self CameraSetOutputProperties:audioCaptureDevice];
    }

Xcode 不会在控制台中显示任何错误消息。请查找图片以获取更多信息。

【问题讨论】:

    标签: objective-c iphone avcapturesession avcapturedevice


    【解决方案1】:

    文档说:

    如果 canSetSessionPreset(_:) 返回 true,您可以设置预设 为那个预设。

    你应该这样做

    if([self.captureSession canSetSessionPreset: AVCaptureSessionPresetMedium]){
          //set the medium preset
    }
    

    会话预设的默认值为高。

    也许对于 XS max,它不允许除高预设之外的任何值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-03
      • 1970-01-01
      • 2019-06-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多