【问题标题】:AVCaptureVideoPreviewLayer from AVCaptureSession stops video stream randomly来自 AVCaptureSession 的 AVCaptureVideoPreviewLayer 随机停止视频流
【发布时间】:2016-03-30 16:30:39
【问题描述】:

我基于 AVCaptureSession 创建了一个简单的 AVCaptureVideoPreviewLayer,并将图层添加到 UIView。

AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetHigh;

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];

[session addInput:input];

AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
previewLayer.frame = self.cameraView.bounds;

[self.cameraView.layer addSublayer:previewLayer];

[session startRunning];

运行应用程序后,代码似乎运行良好 - 但一段时间后(大约 60. - 90. 秒)视频随机冻结!

我添加了一个按钮来停止和启动 AVCaptureSession,如果我在冻结后按下该按钮,视频将再次开始工作......

有人知道随机停止视频流的原因吗?

【问题讨论】:

    标签: ios objective-c avcapturesession


    【解决方案1】:

    尝试设置 AVCaptureMovieFileOutput 的 maxRecordedDuration添加在您的 AVCaptureSession,这是 5000 秒记录持续时间的示例代码

    AVCaptureMovieFileOutput *MovieFileOutput; =[[AVCaptureMovieFileOutput alloc] init];
    
    Float64 MaxRecordDuration = 5000;           //Maximum RecordDuration in seconds replace 5000 with YOUR_MAX_DURATION
    int32_t preferredTimeScale = 30;    //Frames per second
    CMTime maxDuration = CMTimeMakeWithSeconds(MaxRecordDuration, preferredTimeScale);    //<<SET MAX DURATION
    
    MovieFileOutput.maxRecordedDuration = maxDuration;
    MovieFileOutput.minFreeDiskSpaceLimit = 1024 * 1024;                        
    if ([session canAddOutput:MovieFileOutput])
    {
        [session addOutput:MovieFileOutput];
    }
    [session commitConfiguration];
    [session startRunning];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多