I need to record the last 30 seconds BEFORE the camera detects a movement. I have an IP camera connected to the same switch as the raspberry and I know Python.
I have done this on a PC, where I set a 30-second buffer. When the camera senses movement, I copy the buffer, allowing me to capture the 30 seconds before the movement.
any idea how to do it with a Raspberry?
Are you after something that already does this for you ??
Or are you willing to write software to do it ??
Python is easy to use with the Pi OS and could be used to do something like this. I can think of a few ways this might be achieved but would need to know more of your setup, ie equipment and devices used. I have setup simple streaming of video to a web page, saving this video I have not investigated at this stage, also interaction with whatever detects the movement I have not done.
But the idea of recording continuously and then attaching the first few seconds to a movement detection is not new. Most likely someone has already done this with a Pi.
Unless you have a very very clever clairvoyant motion detector which somehow knows 30 sec in advance that something is going to move I think you will have to do as James implies and record continuously in a sort of loop maybe something like a dash cam.
I have never worked in Raspberry, as I said, I just made this in python in a PC just keeping a buffer of 30 seconds and when the camera detects something, I just copy the buffer which is going to be exactly the 30 seconds before the movement.
now, I have to apology because I didn’t know how powerful these little machines have become.
so, I change my question and I apologize again, what is the smallest (cheapest) raspberry that is capable of doing this?
You could buffer in memory. A Pi Zero 2 with 0.5 GB might work. I code in C, not Python. Otherwise a Pi 4 with 2 GB.
With almost no memory and fast storage, you could write 10 second blocks to disk. After 30 seconds, you delete the old unneeded file. Or you could open a file, write for a while then reset the file to the first block.
Buffering in memory is way faster and easier than fiddling with files. The continuous write wear on a microSD card would break most cards.
When I was looking at NVMe stuff I read that continually writing to a Micro SD card will cause it to fail after a year or so. Buffering in memory is best when you are only looking at 30 secs or so.
I have found that Pi OS can be a bit sluggish with less than 4GB. (comparing difference between Pi 5 2GB and Pi 5 8GB)