Lock fps of the ARKit - swift

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

Related

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>

Setting high frame rate recording in Swift

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.

Stage FPS raises on preloading

I have separate manifest files for each level of my game. So when user is playing on Level #1, files for Level#2 are being preloaded at the same time using LoadQueue (PreloadJS).
I've noticed some strange behaviour. Stage FPS is set to 24. But FPS raises (it can be noticed visually) while its preloading next files. It comes to normal FPS when files are preloaded..
How do I fix it? FPS raises at least 1.5x times.
EDIT: I'm using Ticker (RAF activated) and its set to 24 frames per second. Also each sprite has its own 'framerate' property. In most cases its set to 24 as well, but sometimes it has 16 (every 3 frame has been cut and hence framerate set to 16).
EDIT2: Here is an example to check the issue. There are 2 manifest files (for Level1 and Level2). Level1 starts while level2 is being loaded in the background. You can notice that the sprite in Level1 played on higher FPS. It gets to normal FPS when Level2 loading is completed.
It's better to download it and test locally, otherwise FPS changes are less noticable when downloading speed is not as high as in local or on WiFi.
Link: http://www.filedropper.com/preloadjsfps

Check the audio player's current playback time every 0.1 seconds

How can i use the CurrentTime property in the AVAudioPlayerto check the audioplayer's current playback time every 0.1 second. and how i can synchronize it with the views in this fashion that after 11 seconds of audiofile first view loads then second view is loaded after 23 seconds third view is loaded after 27 sec fourth view is loaded after 24 secs and fifth view is loaded after 24 secs so that is how for each view timer varies.
So that when i pause the audio views update is also paused and when it is resumed views update begins from that point where it was paused.
Thanks for the answer.
set your timers NOT to repeat and just create a new instance of the timer each time the new view loads.

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.