Engineering
How Kamo's automatic zoom works
From raw mouse clicks to a camera that glides. The grouping rules, the timing and the spring physics behind every zoom.
· 5 min read · By Doug Siqueira
Every click in a Kamo recording turns into a zoom that feels like someone was operating a camera. There's no AI involved, just a few simple rules and some physics. Here's the whole recipe.
1. What counts as a click
While you record, Kamo writes the mouse's movement, clicks and scrolls to a file, on the same clock as the video. When the project is first opened, Kamo reads those events and looks only at left-button presses inside the recorded area.
- Right and middle clicks never zoom.
- Scrolling and plain movement never create a zoom.
- Clicks outside the recorded window or area are ignored.
2. Grouping clicks into shots
If every click got its own zoom, filling a form would shake the camera like a handheld phone. So Kamo groups clicks into shots. A click joins the current shot when both of these are true:
- it comes less than 1.5 seconds after the previous click was released, and
- it lands within a quarter of the screen's diagonal from the shot's first click (about 550 px on a 1080p screen).
Measuring from the first click, not the last one, matters: otherwise a chain of small steps could walk the shot all the way across the screen.
3. Timing
Each shot starts 0.3 seconds before its first click, so the viewer is already looking at the right spot when the click lands, and holds 1 second after the last release. A shot lasts at least 0.6 seconds. When two shots would overlap, they merge into one.
The camera zooms to 2× by default, aimed at the average position of the shot's clicks, and nudged inward at the edges so it never shows anything outside the video. Inside a zoom, the camera gently follows the cursor and drags.
4. The spring
Zooms never use linear easing. The camera is a damped spring (stiffness 170, damping 26), the same kind of motion you feel in a good phone animation: it starts quickly, slows down smoothly and settles without wobbling.
Two details make it feel right:
- The spring is solved exactly, in closed form, instead of being simulated step by step. Every frame rate gets the same curve, so the preview and the 60 fps export match.
- The spring takes about 0.6 seconds to arrive, so the camera starts moving before the click and lands on it within a frame. Back-to-back zooms go straight from one target to the next, without zooming out in between.
5. The cursor rides the same spring
Kamo records the screen without the Windows cursor and draws its own from the mouse path. It uses the same spring on each axis. Because the whole path is known in advance, the cursor can look about 150 ms ahead, so it glides without lagging behind your hand. At every click, the remaining error is faded out so the cursor sits exactly on the click point on the frame of the click.
6. You always have the last word
Every zoom shows up as a block on the timeline. Drag it, stretch it, change its scale, delete it, or double-click to add your own. Any block you touch becomes manual, and Regenerate zooms only ever replaces the automatic ones.
The whole thing is deterministic (same recording, same zooms) and fast: the zooms for a 10-minute recording are generated in under a second.
The code is open source if you want to read it, and you can try the zoom in your browser right now.
