我需要降低来自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次。
你有什么建议吗?
答案 0 :(得分:0)
您可以使用ACCaptureDevice的activeVideoMinFrameDuration和activeVideoMaxFrameDuration来更新会话的帧。
像:
[captureDevice setActiveVideoMaxFrameDuration:CMTimeMake(2, 1)];
[captureDevice setActiveVideoMinFrameDuration:CMTimeMake(2, 1)];