slopswap / photography

DeskLapse

1 November 2026 · Kevin Cappuccio · live doc on claude.ai · spun off from the 4K capture card thing

I wanted a time-lapse of my bench that just runs. All day, every day, no shutter sound, no remembering to hit record, and nothing that dies and takes the day with it when I close the laptop. The capture card from the other writeup was already pointed at the desk and doing 4K, so the obvious move was a tiny menu bar app that eats frames from it. It turned out to be about 600 lines of Swift and three problems that were harder than they looked, so here's all of that.

TL;DR

Here's the whole UI:

The DeskLapse menu bar panel: a preview of the latest capture, status line, timing sliders, output options
Latest capture on top with a scrubber to go back through the day, then status, the three timing sliders, and the output switches. The 180° is because the camera is mounted backwards and I'm not moving it.

Why not just use OBS?

OBS has no interval capture, the macOS screenshot command plays a shutter sound every single time, and I wanted the thing to notice when I'm actually doing something versus when I've wandered off. The only way to do that last part is to look at the frames yourself, so it's its own AVFoundation session on the card. Which raised a question I didn't know the answer to: can two programs read the same USB camera on a Mac? Turns out yes, with a catch. Whoever opens it first gets to pick the format and everyone else rides along on that. So the app watches for OBS launching, lets go of the card, waits a few seconds, and reattaches without trying to change anything. When OBS quits it grabs the card back and sets it to 4K.

How the auto interval works

Every frame, it samples a 240×135 grid of luma values and counts how many moved by more than 12 levels since the previous frame. Not the average difference, which was my first attempt, because the A7S is a real sensor with real noise and the average difference never goes to zero. A "how many pixels changed a lot" fraction ignores noise and lights up for hands, tools, and parts being moved around. That fraction gets smoothed over five seconds and mapped onto the three sliders like so:

activity ≤ 0.3%   →  max interval   (nobody's here)
activity = 3%     →  average interval
activity ≥ 30%    →  min interval   (hands everywhere)
in between        →  log-log interpolation

So the "average" slider is literally the interval you get during normal desk work, and busy or dead stretches slide toward the other two. Those three thresholds are constants at the top of the file, and if your camera is further from the action than mine they're the first thing to tune.

The crash-safe video trick

JPEGs are trivially crash-safe, each file is its own thing, lose power and you lose the one being written. A video file is not. A normal MOV is unreadable until the writer finalizes it, so a crash at 4 pm loses the whole day. The fix is QuickTime movie fragments: tell AVAssetWriter to write a fragment after every frame and the file on disk is always playable up to the last fragment, with a repair step that turns the leftovers into a normal file next time the app launches.

Three things bit me on the way there, and all three are the kind of thing you only find out by killing the process and looking at what's on disk:

One more: fragmented movies are a thing Premiere handles badly, and it turns out finishWriting leaves the fragments in even on a clean close. So every segment gets losslessly remuxed into a flat MOV when it closes, and anything a crash left behind gets the same treatment on the next launch. Segments roll over every hour or 2 GB so that remux never needs much free disk.

Odds and ends

Build it yourself

It's one Swift file plus a 15 line build script. Edit main.swift, run build.sh, and it compiles, bundles, signs, and relaunches. Tune the constants at the top for your camera and your bench. The source isn't on GitHub yet; ask me and I'll send it.

swiftc -O -swift-version 5 -parse-as-library -target arm64-apple-macos14.0 main.swift -o DeskLapse
codesign -s "Developer ID Application: …" --force DeskLapse.app

To turn a day of JPEGs into a movie: ffmpeg -framerate 30 -pattern_type glob -i '*.jpg' -c:v prores_videotoolbox out.mov. In video mode you don't need to do anything, the segments are already movies.


Spun off from the 4K capture card project, October 2026.