iOS digicam preview is unstable

Apple supplies a pattern iOS venture referred to as AVCamFilter the place they use an MTKView to render the digicam preview to the display screen. The issue is that the body period – the period of time every particular person digicam body spends being displayed on the display screen – isn’t secure. The digicam stream is working at 30 FPS, that’s one body delivered each 33.3 milliseconds, so it stands to motive that we must always have the ability to show these frames one after one other with a body period of 33.3 ms. In actuality the body period is unstable – more often than not it’s about 33.3 ms however generally it’s roughly 16.7 or 50.1 ms.

Based on documentation the default habits for MTKView is to attract to the display screen at 60 FPS, that’s one body each 16.7 ms, so every digicam body could be drawn twice earlier than it’s changed by the following one. The truth that MTKView’s draw loop and the digicam’s seize loop aren’t synchronized explains the issue – the time elapsed between a draw and a seize will regularly drift inflicting frames to go from being captured simply earlier than a draw to only after a draw and so forth and so forth leading to some frames being displayed for 3 attracts or one draw as an alternative of the anticipated two. The MTKView draw loop could be synchronized with the digicam by disabling the default habits and manually calling draw each time a brand new digicam body arrives, however all of that is nonetheless not synchronized with the gadget show itself which is rendering at 60 FPS in its personal loop. So, we nonetheless have the identical basic timing downside. I do know CADisplayLink is supposed for synchronizing issues to the show however there isn’t a method for the seize stream to make use of it.

So how will we render the digicam preview with a secure 33.3 ms body period? Is the instability an anticipated habits with no workaround?

Leave a Reply