Instead of sleeping 1000 / state.video_fpsms (e.g. 33 or 16ms) each frame after the prediction, sleep for the remaining allowed time.
For example, if we are running at 30 fps, the allowed time is approximately 33ms. If the frame fetching takes 2ms, and the prediction takes 10ms, only sleep for 33 - (2 + 10) = 21ms at the end of the loop.
Instead of sleeping
1000 / state.video_fps
ms (e.g. 33 or 16ms) each frame after the prediction, sleep for the remaining allowed time.For example, if we are running at 30 fps, the allowed time is approximately 33ms. If the frame fetching takes 2ms, and the prediction takes 10ms, only sleep for
33 - (2 + 10) = 21ms
at the end of the loop.