Old phones as home cameras
Three old Android phones record to a Raspberry Pi, a filter drops the minutes where nothing moved, and a small vision model on my own graphics card decides whether an alert is a person.
Three old Android phones from a drawer are now cameras. They record around the clock to a Raspberry Pi 4 with a 2 TB USB drive, a filter throws away the minutes where nothing moved, and when someone walks up to a camera that has alerts on, my own phone gets one within seconds. There’s no cloud account and no subscription, and no picture leaves the house.
A phone is a good camera with a battery that rides out a power cut. What it’s bad at is running a service for months: Android kills background apps, throttles when it’s hot, and a battery left on charge for ever can swell.
Getting the pictures off
I prepared each phone the same way over adb, as I did with the TV: no accounts, the bloat removed, stock firmware, bootloader left locked.
scrcpy has a camera source that needs no app on the phone at all:
scrcpy --video-source=camera --camera-size=1920x1080
It needs Android 12, which rules out the oldest phone, and an hour’s test at 1080p split the other two: one ran without a fault and one stalled for more than half a second 149 times. So two of the three run a camera app that encodes H.264 on the phone and serves its own stream. The third still goes through scrcpy, because the app can’t open its ultra-wide lens.
On the Pi, go2rtc pulls each stream once and everything else reads from it. Recording is ffmpeg copying the video untouched into one-minute Matroska files, cut on the clock:
ffmpeg -i "$STREAM" -map 0:v -map 0:a? -c:v copy -c:a aac -ac 1 -b:a 64k \
-f segment -segment_time 60 -segment_atclocktime 1 \
-segment_format matroska -reset_timestamps 1 ...
The sound is re-encoded because copying the phones’ AAC kept none of its packets. The video isn’t touched, and in a trial two recorders together cost between 6 and 12 per cent of one core.
What stopped it, and what I did
The app stopped serving. A watchdog restarts ffmpeg when the files stop growing, and after three failures in a row it runs a repair that restarts the whole chain for that camera. I tested that by force-stopping the app on a phone with its screen off: three failed reconnects, the repair, and it was recording again about three minutes after the kill.
One phone froze the app 45 seconds after its screen went off. The maker’s own battery manager does that, and it took the background-run permission and the active standby bucket, both set over adb, before the stream held with the screen dark.
Sound drifted. One camera’s source restarted while the recorder stayed on the old session, and for 26 hours every clip had its sound 5,982 seconds away from its picture. The recorder now reads the first video and audio timestamps of each file as it closes, with ffprobe, and restarts ffmpeg if they’re more than five seconds apart.
Power was the worst of it. A USB port on a computer gave 500 mA, and filming on battery cost one phone 17 points an hour and another 12. Then a phone that reported “charging” late one evening was flat before six the next morning, because its charger or cable couldn’t keep up with the camera. Each phone now has its own wall charger, and the check that used to ask “is it charging” alerts when a battery is under 60 per cent or has dropped 8 points in about an hour.
Screens heat a phone on a charger for no reason, so they’re off:
adb shell settings put global stay_on_while_plugged_in 0
adb shell settings put system screen_off_timeout 15000
One phone refuses both over adb and had to be done by hand in Developer options.
The Pi overheated too. On a board with no fan it sat at 82 to 84 C and throttled, so I moved the SD card and the drive to one with a fan, and it now runs at about 47 C.
Keeping less
For every finished minute, the filter decodes only the keyframes, shrinks them to 160 by 90 in grey, takes out the overall change in brightness (clouds, auto-exposure) and counts the pixels that changed. Still scenes scored between 0.0002 and 0.0024 and movement between 0.03 and 0.6, so the limit is 0.004. A still minute is deleted unless the minute before or after it has movement.
On one recent day that kept 440, 481 and 48 of the 1,440 minutes on the three phones: 7.5 GB, 12 GB and 0.7 GB. Each hour the kept seconds are cut into one short reel per camera, and each day’s reels are joined into a day file. Raw clips are only removed once a checked reel exists for their hour, oldest first, and only when the drive has less than a fifth free. It’s at 483 GB of 1.8 TB.
Is it a person
Movement isn’t a person. Before an alert goes out the Pi sends the frames over ssh to a small vision model on my own graphics card. The model takes about 12 ms a picture, and from the Pi the whole check takes 240 to 340 ms.
I measured it on 96 frames from my own recordings, labelled by eye: 28 with people and 58 empty, the rest unsure or left out. At a score of 0.6 it found 23 of the 28 and called nothing empty a person. The five it missed were small, far-off figures in one wide view. On real alerts it found 7 of 7 people. One frame I’d labelled empty had someone under an umbrella in the dark, and the model found them. It also finds every person on a television, 5 of 5, so a camera that can see a TV needs a zone that leaves the screen out.
If the box with the card is off or busy, the Pi tries my other Linux box, and if neither answers within three seconds the alert goes out anyway, marked “not checked”. Alerts go through ntfy on the Pi, with a five-minute gap before the same camera can alert again.
Featured projects
-
Apple News API
Publish articles and live coverage to Apple News from PHP, with the whole Apple News Format built from objects.
-
GitHub Auditor
Health, access and activity reports for more GitHub and Bitbucket repositories than you can keep in your head.
-
PrintMD
Markdown in, and a designed PDF, Word or PowerPoint file out. Its PDF service runs on your own computer.
-
Where Should I Live
Which city would leave you best off? Cities ranked by take-home pay, living costs, visas and the way you live.
-
Solar Calendar
Thirteen months of exactly four weeks, with the year starting on the first Monday on or after the spring equinox.
Latest writing
-
Many sessions at once, and what still needs me
Fifteen coding-agent sessions across two Linux boxes, one session that watches the rest, what it may answer for me, what it never may, and why a yes it passes on gets checked against what I typed.
-
61 public repos of agent tooling, none installed, six ideas kept
One author, 61 public repositories of coding-agent tooling: what I checked before any of it got near my Linux boxes, why none of it was installed, and the six ideas I built my own way.
-
Rules a coding agent cannot talk its way round
The hook that reads every command a coding agent wants to run on my Linux boxes: what it refuses, the 27 proofs that its tests fail when a rule is taken out, and the four lines every report opens with.
-
Dozens of repos, one person
46 repositories and two Linux boxes with nobody else on them: the diary, the decision table, the rebuild guide and the job that keeps both sets of clones in step.