ios capturing image using AVFramework

后端 未结 3 667
轻奢々
轻奢々 2020-12-04 11:20

I\'m capturing images using this code

#pragma mark - image capture

// Create and configure a capture session and start it running
- (void)setupCaptureSessio         


        
3条回答
  •  情书的邮戳
    2020-12-04 12:04

    Add the following line

    output.minFrameDuration = CMTimeMake(5, 1);
    

    below the comment

     // If you wish to cap the frame rate to a known value, such as 15 fps, set
     // minFrameDuration.
    

    but above the

    [session startRunning];
    

    Edit

    Use the following code to preview the camera output.

    AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
    UIView *aView = self.view;
    CGRect videoRect = CGRectMake(0.0, 0.0, 320.0, 150.0);
    previewLayer.frame = videoRect; // Assume you want the preview layer to fill the view.
    [aView.layer addSublayer:previewLayer];
    

    Edit 2: Ok fine..

    Apple has provided a way to set the minFrameDuration here

    So now, use the following code to set the frame duration

    AVCaptureConnection *conn = [output connectionWithMediaType:AVMediaTypeVideo];
    
    if (conn.supportsVideoMinFrameDuration)
        conn.videoMinFrameDuration = CMTimeMake(5,1);
    if (conn.supportsVideoMaxFrameDuration)
        conn.videoMaxFrameDuration = CMTimeMake(5,1);
    

提交回复
热议问题