Capture 60fps in iPhone app

元气小坏坏 提交于 2019-11-28 05:03:52

After some tinkering, this answer has split into two parts:

How to capture frames at 60fps

The AVCaptureSessionPreset1280x720 on the iPhone4s/5.1, with frame durations set to:

connection.videoMinFrameDuration = CMTimeMake(1, 60);*
connection.videoMaxFrameDuration = CMTimeMake(1, 60);

gives you a stable, super smooth capture.

How to capture frames into a file @60fps
Capturing frames is all very well, but presumably you want to keep them.
As Brad noted in the comments, writing those frames to a file is another story. Sadly, no matter what configurations I tried, encoding the frames via an AVAssetWriter caused the capture rate to drop to the observed ~37fps and no amount of fiddling with alwaysDiscardsLateVideoFrames could change it. However, in this approach every single frame is copied from AVFoundation to your app, and then back again, which is quite pointless and very wearing for the bus. Luckily, AVFoundation has a class that removes this round trip: AVCaptureMovieFileOutput.

If you let AVFoundation do the writing for you then the iPhone4S can capture and encode frames + audio to a .mov file at 60fps* without breaking a sweat (~25% CPU).

While 60fps video capture is great feature, I can't help but feel a little disappointed as AVCaptureMovieFileOutput rules out a lot of fun things (e.g. realtime effects with GL shaders, recording start/stop without frame loss).

cake/eat it

*59 if you're still running iOS 5.0.1

Hailei

I haven't try this before, maybe these are related:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!