在iOS 5中使用AVFoundation设置最大帧速率 [英] Set maximum frame rate with AVFoundation in iOS 5
问题描述
我相信这曾经用 captureOutput.minFrameDuration
完成。但是,这在iOS 5中已被弃用。
I believe this used to be done with captureOutput.minFrameDuration
. However, this is deprecated in iOS 5.
相反,我显然需要使用 AVCaptureConnection
的 video.minFrameDuration
。所以我有输入,我的输出,我将它们添加到捕获会话 - 我在哪里可以访问捕获连接?我认为它是由会话创建的,但在哪里?
Instead I apparently need to use AVCaptureConnection
's video.minFrameDuration
. So I have my input, my output, I add them both the the capture session - where can I get access to the capture connection? I think it is created for me by the session, but where?
我可以尝试使用 addInputWithNoConnections $ c $添加I / O c>和
addOutputWithNoConnections
然后可能手动创建连接。但是,设置最大帧速率似乎有点麻烦。另外,Xcode抱怨这些方法不存在。
I could try adding the I/O using addInputWithNoConnections
and addOutputWithNoConnections
and then maybe creating the connection manually. But this seems like a bit of hassle just to set a maximum frame rate. Plus, Xcode complains that these methods don't exist.
推荐答案
克里斯,我想我已经解决了这个问题:
Chris, I think I have solved this problem:
(编辑 - 请参阅下面的Tomas Camin评论关于是否支持videoMinFrameDuration videoMaxFrameDuration的正确方法,尽管以下代码在发布时工作正常)
以下行可以访问与 AVCaptureVideoDataOutput
AVCaptureConnection 对象> object:
The line below gives access to the AVCaptureConnection
object associated with the AVCaptureVideoDataOutput
object:
AVCaptureConnection *conn = [output connectionWithMediaType:AVMediaTypeVideo];
CMTimeShow(conn.videoMinFrameDuration);
CMTimeShow(conn.videoMaxFrameDuration);
if (conn.isVideoMinFrameDurationSupported)
conn.videoMinFrameDuration = CMTimeMake(1, CAPTURE_FRAMES_PER_SECOND);
if (conn.isVideoMaxFrameDurationSupported)
conn.videoMaxFrameDuration = CMTimeMake(1, CAPTURE_FRAMES_PER_SECOND);
CMTimeShow(conn.videoMinFrameDuration);
CMTimeShow(conn.videoMaxFrameDuration);
如果您正在使用(我是), didOutputSampleBuffer
委托,您可以确认传入代理的 fromConnection
AVCaptureConnection *值中的视频帧速率已正确设置并由上述记住码。
If you're using (as I am), the didOutputSampleBuffer
delegate, you can confirm that the video frame rate in the fromConnection
AVCaptureConnection * value passed in to the delegate has been correctly set and "remembered" by the above code.
请注意,您需要设置 videoMinFrameDuration
和 videoMaxFrameDuration
以相同的值成功锁定帧速率 - 在iPhone 4s上测试时,设置min本身似乎不起作用。这似乎没有记录。
Note that you need to set both videoMinFrameDuration
and videoMaxFrameDuration
to the same value to successfully clamp the frame rate -- setting min on its own did not seem to work when testing on an iPhone 4s. This doesn't seem to be documented.
Josh
这篇关于在iOS 5中使用AVFoundation设置最大帧速率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!