AVCapture capturing and getting framebuffer at 60 fps in iOS 7

前端 未结 3 930
無奈伤痛
無奈伤痛 2020-12-23 02:43

I\'m developping an app which requires capturing framebuffer at as much fps as possible. I\'ve already figured out how to force iphone to capture at 60 fps but



        
3条回答
  •  攒了一身酷
    2020-12-23 03:02

    Had the same problem. Fixed by using this function after [AVCaptureSession addInput:cameraDeviceInput]. Somehow I could not change the framerate on my iPad pro before capture session was started. So at first I changed video format after the device was added to the capture session.

    - (void)switchFormatWithDesiredFPS:(CGFloat)desiredFPS
    {
        BOOL isRunning = _captureSession.isRunning;
    
        if (isRunning)  [_captureSession stopRunning];
    
        AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        AVCaptureDeviceFormat *selectedFormat = nil;
        int32_t maxWidth = 0;
        AVFrameRateRange *frameRateRange = nil;
    
        for (AVCaptureDeviceFormat *format in [videoDevice formats]) {
    
            for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) {
    
                CMFormatDescriptionRef desc = format.formatDescription;
                CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(desc);
                int32_t width = dimensions.width;
    
                if (range.minFrameRate <= desiredFPS && desiredFPS <= range.maxFrameRate && width >= maxWidth) {
    
                    selectedFormat = format;
                    frameRateRange = range;
                    maxWidth = width;
                }
            }
        }
    
        if (selectedFormat) {
    
            if ([videoDevice lockForConfiguration:nil]) {
    
                NSLog(@"selected format:%@", selectedFormat);
                videoDevice.activeFormat = selectedFormat;
                videoDevice.activeVideoMinFrameDuration = CMTimeMake(1, (int32_t)desiredFPS);
                videoDevice.activeVideoMaxFrameDuration = CMTimeMake(1, (int32_t)desiredFPS);
                [videoDevice unlockForConfiguration];
            }
        }
    
        if (isRunning) [_captureSession startRunning];
    }
    

提交回复
热议问题