PSA: Improve ESPHome FPS with Clock Rate (why?)

Hey everyone :wave: I’ve been reading posts for a few weeks now and I recently decided to finally sign in, so I could briefly share my experience setting up an ESP32 cam and see if anyone here knows why this happens.

I had bought a Cam S3 dev board and an OV3660 from AliExpress just to tinker around with and I started with what was pretty much a default ESPHome Camera config. I was disappointed with the frame rate (I could get 0.4fps or so on a good day)… right away, but I assumed it was just a cheap board thing . Then I did some more looking into ESPs, and I realized the S3 N16R8 with 8MB of PSRAM is actually pretty powerful.

So I started experimenting. I first changed the WiFi power. That helped, but it also made the ESP reconnect to the API every minute. Then I tried changing the resolution, and that helped (brought sizes down considerably in logs) but for some reason I still could not get it displaying well.

So I was about to give up and attribute it to ESPHome bloat or ESP32 lack of hardware encoding, when I suddenly remembered a single comment on Reddit about the clock rate. I tried 10MHz which was as low as ESPHome says it can go. This improved things by maybe 20%. I lived with that for a while and I remembered that the comment mentioned 8MHz, so I decided just to try inputting it. It worked!

I was expecting little to no difference, but the MJPEG camera stream is now pretty much 3-4fps and it’s 2 or so FPS through the API, and this is at JPEG 15 at 1600x1200.

So PSA - if you have a pretty fast ESP board but are getting slow camera performance, try changing the clock rate. It makes a massive difference, and at least for the OV3660, you need a low clock.

I looked online and even tried asking AI, and I can’t really understand / find a definitive answer about how exactly the clock rate could change it this much? Can anyone explain it to me?

Also, there is one major trade off/bug. Before, when I tapped the live feed in Home Assistant, my on_stream_start/stop automation to work the LED worked perfectly. Now, if I use Home Assistant to view the feed, it constantly triggers on and off. For my logs, configuration, and more details, check here on my GitHub issue.

Any ideas?