My wife and I have two cats: Necco, who is thin, elderly and living with bowel cancer; and Sienna, who is heavyset and middle-aged, and recently we had to implement a system to monitor their feeding habits. Here's how I did that with Linux, an old laptop, and a cheap used webcam.
TL;DR? This post shows you how to set up Linux, fswebcam and v4l-utils to configure and operate a USB webcam as a somewhat clumsy surveillance device.
Necco is on a low-residue, high-protein diet, and Sienna is on a food restriction diet. Both are rescue cats, and when we got Sienna she had food anxiety, frequently wolfing down a normal morning feed so fast it made her sick to her stomach. Sienna still has food anxiety because she has so much extra weight she's on a slightly limited diet, and because we reduced the amount of food we give her at any feeding but increased the number, to prevent her from eating so much in one sitting she throws up. But we suspect that Sienna was eating out of Necco's bowl when we weren't watching.
Cracked!
There's a store in my city called Re-PC which takes in old hardware and either resells or recycles it. I bought a Logitech C310 web camera from them for about $25. The C310 has a maximum resolution of 1280x720 and is considered "well-supported" under Linux.
My travel laptop is a Surface Pro 6. I have another Surface Pro 6 with a badly cracked screen that usually sits in a drawer. The screen still works, but not as a touch screen, and the shattered corner means it shouldn't leave the house, but it's perfect for this job.
My tools of choice for this job are:
- v4l-utils: to find the damned camera
- guvcview: to calibrate the web camera
- fswebcam: to do the actual watching the cats
- imagemagick: to process the images into a smaller format for storage
- inotify-tools: to handle updates to the cache of image frames
- feh: to display the progress
I chose to use the Logitech webcam because it was easier to set that up than to use the cameras on the Surface Pro. Surface Pro cameras are notoriously hard to use under Linux, and I should know since I'm the one who diagnosed why Surface Pro kernels started failing to build the Video-4-Linux module a few years ago.How to spy on your cats all night long.
I connected the camera's USB cable to my laptop and started guvcview. It
offered me a choice of three cameras and one of them was the C310! That was
reassuring. I checked to get the identity of the C310 and wrote down a long
identifier string.
fswebcam is the program I wanted to use; it is tunable and has an option to
"take one photo every n seconds and save it as a JPEG," where n is just a
number. But it wanted a standard Linux device ID, and what guvcview gave me
was definitely not that.
After much searching and getting absolutely no help from Google's idiot AI, I
stumbled on someone mentioning v4l-utils. I installed it and ran v4l2-ctl --list-devices, and it told me that there was a USB-based camera sitting on
/dev/video14.
While that's a peculiarly high device number, I ran:
fswebcam --device /dev/video14 --loop 10 --resolution 1280x720 \
--timestamp '%a, %b %m, %Y %H:%M:%S (%Z)' 'cats-%Y%m%d-%H%M%S.jpg'
That worked! The camera was now dumping one JPEG every ten seconds to the working folder. It was just... a little too yellow.
I discovered that it's possible to tune the C310, a little, but you have to know
the names of the controls. Reading the man page, I discovered, v4l2-ctl --device /dev/video14 --list-ctrls will give me that, and I remembered seeing
the names it now displayed in guvcview.
Running guvcview again, I found the "automatic device correction" tab and ran
it, writing down the adjustments I had to make. I then applied those to my
command to the webcam:
fswebcam --device /dev/video14 --loop 10 --resolution 1280x720 \
--set white_balance_temperature=0 --set brightness=183 \
--set contrast=50 \
--timestamp '%a, %b %m, %Y %H:%M:%S (%Z)' 'cats-%Y%m%d-%H%M%S.jpg'
The timestamp argument puts a little timestamp in the lower right-hand corner
of each frame, letting you know when it was taken, while the same date format in
the last argument creates files with those specific timestamps. Very nice.
But even JPEGs are pretty big, and I've become a WEBP partisan. So I wrote a very short shell script that monitors the folder for when something dumps a JPG into it, attempts to convert that image to WEBP and, if successful, delete the JPG. This got me about at 30% savings on disk usage.
I have to admit I was being paranoid; eight hours at one frame every ten seconds was only about 70MB, and my junk laptop has a 256GB hard drive only half-full. If I'd used JPGs, that would have been around 300MB for an entire day's take, and I could have let the damn thing run all year before having to worry about my OS complaining, "Your storage space is 90% full."
And finally, I wanted to know if it was working. So I wrote another, slightly longer shell script that monitors the folder for new images and, when one shows up, running a program to show it. If it was previously running a display, it kills the other one gracefully, providing just about the silliest screen saver I've ever written.
But it worked. And we did indeed catch Sienna eating out of Necco's bowl at 5am.

Busted!
It's grainy and dim because even with all the settings, these cameras really are meant for video conferencing in reasonably well-lit rooms. We left only one light on, and turned it down as far as we could with a dimmer switch. For the cats, having the lights on all night is unusual, and we were worried even that much light would change their patterns, it it only took them one night to adjust. The second night we got the evidence we expected, and it does look a little like one of the surveillance tapes from a true-crime show,
Cracked!
How to spy on your cats all night
long.