【问题标题】:ios, how to decrease the FPS of the video stream from the cameraios,如何降低来自相机的视频流的FPS
【发布时间】:2014-07-01 16:11:54
【问题描述】:

我需要降低来自 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 个。

你有什么建议吗?

【问题讨论】:

  • 您的问题解决了吗?
  • 我无法解决。

标签: ios video


【解决方案1】:

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

喜欢:

[captureDevice setActiveVideoMaxFrameDuration:CMTimeMake(2, 1)];
[captureDevice setActiveVideoMinFrameDuration:CMTimeMake(2, 1)];

您也可以参考:https://developer.apple.com/documentation/avfoundation/avcapturedevice/1389290-activevideominframeduration

【讨论】:

    猜你喜欢
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    • 2018-09-18
    • 2020-05-29
    • 1970-01-01
    • 2015-05-29
    • 2014-03-20
    • 1970-01-01
    相关资源
    最近更新 更多