Setting high frame rate recording in Swift - iphone

i'm trying to create an app to record video at 120fps but i'm having troubles.
First, when print(device.activeFormat), i get this in the logs
AVCaptureDeviceFormat: 0x13fe49890 'vide'/'420v' 1920x1080, { 2- 30 fps}, fov:58.080, supports vis, max zoom:104.38 (upscales #1.55), AF System:1, ISO:34.0-544.0, SS:0.000024-0.500000
but my device is an iPhone 5s which supports 120fps, don't know why the range here is 2-30fps.
Second, when i do device.activeVideoMaxFrameDuration = CMTimeMake(1, 120) to change the max frame rate to 120 fps, i get this error in the logs:
[AVCaptureVideoDevice setActiveVideoMaxFrameDuration:] - the passed activeVideoMaxFrameDuration 1:120 is not supported by the device.
What am i doing wrong?
Thanks!

As you can see from your print(device.activeFormat), the max support fps is 30 given {2- 30 fps}. Therefore, setting 120 fps with device.activeVideoMaxFrameDuration = CMTimeMake(1, 120) is not supported.

Related

Lock fps of the ARKit

I want to take an snapshot from ARKit view (ARSCNView) 30 times per sec, and since the CPU usage is so important in my case, I try to not use Timer or displaylink and instead run the taking image function inside session(_ session: ARSession, didUpdate frame: ARFrame) .
But it normally run in 60 fps and then come to 30 fps after a while.
So I try to lock it on 30 fps
sceneView.preferredFramesPerSecond = 30
But looks like it's not working and it is still doing it in 60 fps. Is there any way to lock it on 30 fps all the time ( 30 ps or lower ). If not, there is any way that we can find out its fps in the first 1-2 sec to modify the taking image function base on it ( run in every frame in 30 fps or run in every 2 frame in 60 fps)
Thank you so much

Scene background from camera - FPS

I can use AVCaptureDevice as background.contents of SCNScene. And it works, but there is one problem with it. I would like to use video format that has resolution 1920x1080, and 60 FPS. But I can clearly see, that different format is used, it is 30 FPS. I am configuring used device before applying it to background, but somehow SCNScene is changing it. SceneView itself works in 60 FPS, but camera preview is a different story. Can I somehow force SCNScene to use video format I choose?
I know I could just add layer with camera preview under SceneView, but I have reasons why this approach is not working correctly, so I need to use this background property od the scene.
Sample project is here: https://www.dropbox.com/s/b820wxlg8voya58/SampleApp.zip?dl=1
In terminal you can clearly see, that after starting SceneView active format for device changes:
Selected format is:
<AVCaptureDeviceFormat: 0x282d58d00 'vide'/'420v' 1280x 720, { 3- 60 fps}, HRSI:4096x2304, fov:58.632, supports vis, max zoom:120.00 (upscales #2.91), AF System:2, ISO:23.0-736.0, SS:0.000013-0.333333>
2018-10-10 14:47:35.009890+0200 SampleApp[6799:1110910] [SceneKit] Error: Could not get pixel buffer (CVPixelBufferRef)
Format after 3 seconds is:
<AVCaptureDeviceFormat: 0x282d58fb0 'vide'/'420v' 1920x1080, { 3- 30 fps}, HRSI:4096x2304, fov:58.632, supports vis, max zoom:16.00 (upscales #1.94), AF System:2, ISO:23.0-736.0, SS:0.000013-0.333333>

How to find the start and end duration of "Selected frames" from Video using didFinishPickingMediaWithInfo?

I am doing slow motion in audio and video using AVFoundation(for Video) and Dirac(Audio).
As part of it, i will show the video as frames in which the user will select the frames to do slow motion. Eg: 5-6 min of 10 min video.
I have to show the users two kinds of videos 1. through the video recorder from my application itself. 2. from the gallery.
Case1: No problem
Now,i can record the videos though my video recorder and show the videos as frames to the user to select. Once the user selects some frames(Eg: 5 to 6 min of 10 min recorded video),
using the below code, i am able to find the start/end duration of the selected frames or video.
NSNumber *start = [info objectForKey:#"_UIImagePickerControllerVideoEditingStart"];
NSNumber *end = [info objectForKey:#"_UIImagePickerControllerVideoEditingEnd"];
int startMilliseconds = ([start doubleValue] * 1000);
int endMilliseconds = ([end doubleValue] * 1000);
Case2:
In this case, i am able to pick the video from the gallery and show them to the user in the form of frames to select. However, when i try to find the start/end duration of the video as i did in case 1 with the same code, its not working. I am always getting "0" for start/end duration.
Have a look at the new additions in AVFoundation in iOS 7 as it now natively supports slow motion video and audio auto-time stretching. This might change your approach, and a better solution.

FPS stabilization iPhone

I have, most of the time, 50+ FPS, but when I load resources(background tread) it drops to 30 FPS. I want to have constant FPS, 30 or even 20, it's not a problem for me. What is the best way to make FPS constant?
You should be using time-based redrawing, instead of frame based drawing. Michael Daley's book has some excellent info on this.
Also, try loading as many of your resources as possible in a spritesheet.
Not really sure if there is an established method, but frame rate in this case is the frequency at which you redraw. 20 FPS is a 50 millisecond redraw rate. One method would be to only redraw if the time between the last redraw and now is >=50 ms.

How to set the Video recording time limit in iPhone?

Is it possible to set the time limit for a video recording in the iPhone? I know the maximum limit is 10 minutes. But I want to reduce it to 5 minutes. If it is possible how can it be done?
You need to set the videoMaxiumDuration property on UIImagePickerController after configuring it for video recording.
The value is an NSTimeInterval which is specified in seconds, so you'll want to set it to 300 seconds if you want 5 mins of video.
You can set video Recording limitations using
[imgPickerCtrl setVideoMaximumDuration:30.0f];
Here it will limit video recording upto 30seconds also it will alert you when you select the video from library that it is beyond the limit and it will crop it automatically.
Swift 2.2:
let picker = UIImagePickerController()
let MAX_VIDEO_DURATION = 30.0 // note the .0, must be double, move this at the top of your class preferrebly
picker.videoMaximumDuration = NSTimeInterval(MAX_VIDEO_DURATION)
Swift 3.0 and Higher Version of Swift
Its Really Simple as you think.
let imagePicker = UIImagePickerController()
imagePicker.videoMaximumDuration = TimeInterval(30.0)