bitluni / ESP32CameraI2S

169 stars 61 forks source link

Frames per second quantized by VSYNC #7

Open cspwcspw opened 6 years ago

cspwcspw commented 6 years ago

I'm trying to understand and hack the code. I'm using an OV7670 without fifo, My experiments show up the following behaviour:

If I arrange to call newframe() 15 times per second, I get about 15fps. If I call it 25 times per second, I get 25fps. So far, :-) But if I want 22 fps, I get only 15-16fps.

The reason: VSYNC runs continuously, clocked so that it occurs about once every 40ms (25 frames per sec). My simple analogy is a train that runs every hour.

When we call newframe(), it waits for the next train on a 40ms boundary when VSYNC happens, and captures the frame.

So when my grab rate is "easy:", i.e. I ask for the next frame "close" to when the next VSYNC train pulls into the station, I get my expected framerates. But if I ask for frames at a rate that just misses the train that has left, I have an extra delay before I can start grabbing the frame.

Is there any suggestion to hack this code so that when I ask for a new frame, the camera sends VSYNC almost immediately. Would it help to reset the camera before every frame? (Wouldn't it be nice to always arrive at the station and immediately summon the next train?)

Thanks Peter