I have a security camera running Linux (busybox 1.32.0) which I can set to record video continuously in (configurable) 30 seconds chunks in a folder structure:
recording/2022/04/26/15/2022-04-26-15-30-00.mp4
In another folder, static images are recorded only when motion is detected:
stills/2022/04/26/15/2022-04-26-15-30-05.jpg
This is a workaround I made up to get videos even before a motion is detected.
Since the space available is limited, I would like to delete any video which is started more than 60 seconds before motion, and 120 seconds after motion, so that I keep some pre- and post-video for each still image.
Still images can be as frequent as every 5 seconds, since they are based on triggers by motion and not on a predefined interval.
Of course, with one single image it's a matter of running "find" with the appropriate options, but what about my more complex use case?
I thought about some possible ways but I'm not sure how to proceed.
I thought about running a script every day which lists the elements (recordings and stills) from the previous day, converts from filename to timestamp each one of them, then iteratively compares timestamps with the timestamps for the still images.
This would involve 4 lists (filenames, timestamps, for both recordings and stills) and seems to me quite involved (maybe because I'm not familiar with shell scripts), so is there an easier way to do it?
Solutions involving python or perl would require compiling it for the platform, and may impose a too high load on the CPU, not to mention that the free space on the device is already limited and a samba 4.x executable already couldn't fit.
The tools available are those available as part of busybox plus the binaries listed in the project website.