Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture 60fps in iPhone app

I am working on a project where we will be using iPhones as cameras for capturing a scene. When recording we need to record @60fps and not 30fps (as natively supported). So I am working on an app to do this as the iPhone 4S hardware supports 720p@60fps (if you jailbreak your phone you can achieve this).

Does anybody know how to do this in Objective-C on iOS? Today I saw an app out there (slopro) that can record 60fps on non jailbroken phones. Any advice or tips is much appreciated.

like image 558
Michel Avatar asked Apr 27 '12 04:04

Michel


People also ask

Can you record 60fps on iPhone?

Your iPhone 13, 12, 11, Xs, X, 8, 7 and 6s can Record Video in 60fps, Here's How to Enable the Feature. 60 frames per second, or 60fps, video recording has been around since the iPhone 6s days.

How do I get 60fps on my iPhone Camera?

In Video mode, use quick toggles at the top of the screen to change the video resolution and frame rates available on your iPhone. On iPhone XS, iPhone XR, and later, tap the quick toggles in the top-right corner to switch between HD or 4K recording and 24, 30, or 60 fps in Video mode.

How do I record 1080p/60fps on my iPhone?

To change the video format and frame rate: Go to Settings. Tap Camera, then tap Record Video. Select from the list of video formats and frame rates that your iPhone or iPad supports.


2 Answers

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

like image 158
Rhythmic Fistman Avatar answered Sep 21 '22 05:09

Rhythmic Fistman


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

  • Set maximum frame rate with AVFoundation in iOS 5
  • videoMinFrameDuration and videoMaxFrameDuration in AVCaptureConnection Class Reference
  • CMTime Reference (needed for setting videoMaxFrameDuration)
like image 39
Hailei Avatar answered Sep 24 '22 05:09

Hailei