One Taken Every Second

In order to keep an eye on my garage I placed a Wyze camera in it. So when I noticed one day that somebody has swiped my tool bag, I thought I'll find the culprit quickly. Well, it was not meant to be.

I had recording turned on but only a 32 GB card in it. And I noticed tool bag missing only after two weeks or so. So any recording was already gone by the time I took a look. Since only other people that had access to the garage were Amazon delivery guys, I could narrow it down but not sufficiently to do anything about it.

So I went to look into a cheap solution to record images long term and RTSP immediately came to mind. Even better, Wyze cameras already support it (albeit via a special firmware).

My idea was to simply record an image every second and save it on my NAS using ffmpeg. While this was a simple task in theory, it proved to be a bit annoying to find parameters that would be stable enough. Most notably, sometime it would just stop ingesting new frames and thus require restart.

After testing a lot of different parameters, I came with the following code:

Script
while (true); do
ffmpeg \
-probesize 1000000 \
-analyzeduration 1000000 \
-flags low_delay \
-fflags discardcorrupt \
-re \
-rtsp_transport tcp \
-stimeout 10000000 \
-allowed_media_types video \
-i rtsp://${CAMERA_USER}:${CAMERA_PASS}@${CAMERA_IP}/live \
-f image2 \
-strftime 1 \
-vf fps=fps=1 \
-async 1 \
-vsync 1 \
-threads 1 \
-use_wallclock_as_timestamps 1 \
"${BASE_DIRECTORY}/${CAMERA_IP}~%Y-%m-%d-%H-%M-%S.jpg"
sleep 1
done

Using this setup ffmpeg will keep taking image every second. If it gets stuck, it will exit and then it's on while to restart the capture again. One can then use a separate process to convert these files into a mjpeg file but that's story for another day.

2 thoughts to “One Taken Every Second”

  1. I’ve done this in several configurations in the past. The easiest was to buy a Cisco camera which I’m sure they don’t make any more, and I don’t have it. (Loaned it to a friend who’s dad was in poor health so he could do exactly this) So I can’t give you the part number. I do remember that it was Wired/Wireless and could directly access FTP sites, and had an internal admin webpage so you could easily configure it to send a photograph to an FTP server.
    The harder way was to use any USB webcam or ISM/ISC to grab an image directly, using FFMPEG or other. In your case, you could use an RPi. I created a small RAMdisk to write the image to in order not to wear out my hard drive (in your case an SD card), and had the local computer take images constantly. Then I had a larger computer NSF/FTP/SCP/Other to the small computer and grab the image at whatever time interval I wanted.
    This is the type of thing you forget about after a few months, so I also wrote a script that would run daily and get rid of any files that were older than 6 months.

Leave a Reply

Your email address will not be published. Required fields are marked *