我正在使用AV Foundation来处理来自摄像机(iPhone 4s,iOS 6.1.2)的帧。我正在根据AV Foundation编程指南设置AVCaptureSession,AVCaptureDeviceInput,AVCaptureVideoDataOutput。一切都按预期工作,我可以在captureOutput:didOutputSampleBuffer:fromConnection:
代表中接收帧。AV Foundation:AVCaptureVideoPreviewLayer和帧持续时间
我也有这样设置的预览层:
AVCaptureVideoPreviewLayer *videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_captureSession];
[videoPreviewLayer setFrame:self.view.bounds];
videoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self.view.layer insertSublayer:videoPreviewLayer atIndex:0];
事情是,我不需要每秒30帧的帧我处理,我不能够处理他们这么快呢。所以我使用此代码来限制帧持续时间:
// videoOutput is AVCaptureVideoDataOutput set earlier
AVCaptureConnection *conn = [videoOutput connectionWithMediaType:AVMediaTypeVideo];
[conn setVideoMinFrameDuration:CMTimeMake(1, 10)];
[conn setVideoMaxFrameDuration:CMTimeMake(1, 2)];
这工作得很好,并限制由captureOutput代表收到的帧。
但是,这也限制了预览图层上的每秒帧数,预览视频变得无法响应。
我从文档中了解到,帧持续时间是在连接上独立设置的,预览层的确有不同的AVCaptureConnection。在[videoPreviewLayer connection]
上检查混合/最大帧持续时间显示它确实设置为默认值(1/30和1/24),并且不同于连接AVCaptureVideoDataOutput时设置的持续时间。
那么,是否有可能仅限于帧捕捉输出限制帧持续时间,并且仍然在预览视频上看到1/24-1/30帧持续时间?怎么样?
谢谢。
“这并不容易。”夸张的 – aleclarson 2014-05-30 20:34:42
嗨@Wildaker你能帮忙解释一下帧持续时间以及在这个问题中使用不同值的含义吗?谢谢! http://stackoverflow.com/questions/34937008/exporting-videos-on-ios-understanding-and-setting-frame-duration-property – Crashalot 2016-01-22 00:36:21
对不起,但没有试验,我真的不能说,@Crashalot。这不是我所做的。 – Wildaker 2016-01-23 09:36:11