ios,如何降低摄像机视频流的FPS

ios,如何降低摄像机视频流的FPS,ios,video,Ios,Video,我需要降低来自iPhone摄像头的视频流的帧速率 这是我使用的代码: [...] _captureSession = [[AVCaptureSession alloc] init]; if( [_captureSession canSetSessionPreset:AVCaptureSessionPreset640x480]) { [_captureSession setSessionPreset:AVCaptureSessionPreset640x480]; } else {

我需要降低来自iPhone摄像头的视频流的帧速率

这是我使用的代码:

[...]
_captureSession = [[AVCaptureSession alloc] init];
if( [_captureSession canSetSessionPreset:AVCaptureSessionPreset640x480]) {
    [_captureSession setSessionPreset:AVCaptureSessionPreset640x480];
} else {
    NSLog(@"Could not initialize 640x480 video stream");
    exit(EXIT_FAILURE);
}

AVCaptureDevice *videoCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;    

if ([videoCaptureDevice lockForConfiguration:&error]) {
    AVCaptureDeviceFormat *format =  [videoCaptureDevice activeFormat];
    NSArray *supportedFPS = format.videoSupportedFrameRateRanges;

    CMTime maxFrameDuration;
    float maxSeconds = FLT_MIN;

    for(AVFrameRateRange *fpsRange in supportedFPS) {
        float currentSeconds = CMTimeGetSeconds(fpsRange.maxFrameDuration);
        if(currentSeconds > maxSeconds) maxFrameDuration =fpsRange.maxFrameDuration;

        NSLog(@"Supported range. Max frame rate: %f (min frame duration %f) -  
                                 Min frame rate: %f (max frame duration %f)",
        fpsRange.maxFrameRate, 
        CMTimeGetSeconds(fpsRange.minFrameDuration),  
        fpsRange.minFrameRate,  
        CMTimeGetSeconds(fpsRange.maxFrameDuration));
    } // for

    NSLog(@"Setting min/max duration for frames to %f", CMTimeGetSeconds(maxFrameDuration));
    [videoCaptureDevice setActiveVideoMaxFrameDuration:maxFrameDuration];
    [videoCaptureDevice setActiveVideoMinFrameDuration:maxFrameDuration];
    [...]
 } // lockForConf
我们的想法是

  • 获取当前格式,一旦设置了视频流的大小
  • 获取具有帧速率可用范围的阵列
  • 查找帧持续时间最长的帧
  • 将捕获设备的最小/最大帧持续时间设置为最大值
for循环中打印的唯一日志消息是:

Supported range. Max frame rate: 30.000000 (min frame duration 0.033333) - 
Min frame rate: 2.000000 (max frame duration 0.500000)
尽管可以将FPS设置为每秒2帧,但相机每秒仍输出大量帧。我不知道如何获得视频流的FPS,但相机绝对不是每秒2次


您有什么建议吗?

您可以使用ACCaptureDevice的activeVideoMinFrameDuration和activeVideoMaxFrameDuration来更新会话的帧

比如:


您也可以参考:

您解决问题了吗?我没能解决。
[captureDevice setActiveVideoMaxFrameDuration:CMTimeMake(2, 1)];
[captureDevice setActiveVideoMinFrameDuration:CMTimeMake(2, 1)];