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.
2022-04-26-15-30.mp4
the video started at 2022-04-26 15:30:00? Then how is the one started at 15:30:30 named? – Stéphane Chazelas Apr 26 '22 at 15:00perl
available? This is fiddly to do withsh
- butIFS="\0" for still in $(find stills/ -name *.jpg -print0); do
would be your starting point there. You'll probably need two separate loops: one to build a list of what you're keeping, and the other to delete everything else. – OrangeDog Apr 26 '22 at 16:02date
could be used to create patterns. it's limited syntax also. Without any date at all, we could blindly keep N videos before and M after a string comparison matches, (not necessarily) assuming all recordings exist (no useful data would be lost if they don't). – thanasisp Apr 28 '22 at 09:10