Motion/Image recording action - handoff movie/image to script
  • Hello, I have a request regarding SecuritySpy image/motion recordings and Actions.

    As I understand it, when motion is detected, Actions are triggered immediately. Actions seem geared towards real-time triggering of relays and so forth, which makes sense.

    SecuritySpy has an 'upload to' option for uploading a movie *after completion*, but there doesn't seem to be easy way to run a script or Action on a recorded movie or image *after* completion (independent of the camera global action).

    So, for example, I want to use a script to post-process a motion capture movie so I can encrypt it and move it to a file server or S3. To do this, I have to know when the movie is done writing and the file is closed before the script can commence. The dumb way to do this is to use Actions and wait an arbitrary amount of time based on the movie capture duration, but that would mean delaying all actions (you can only specify a single global delay value for actions per camera) and I don't want to do that - it's kind of a mis-use of the Actions feature.

    What would be very useful, and I think it would not be so hard to add to SecuritySpy, would be if there was a feature to simply send a completed movie's path as an input arg to a selected script once the file is written, ie, in the Motion Capture tab, under 'Motion Capture' and 'Image Capture', beneath the 'Upload to' checkbox/script selector, add a 'File action' (or 'Movie Action' or 'Image Action') checkbox and a popup menu to select a script (essentially identical to the 'upload to' checkbox configuration). When enabled, after a movie or image is written (completed, file closed), SecuritySpy would simply call the selected script, with the movie/image path sent as an input arg. Doesn't have to do anything else, just call the script, send the path as an arg.

    Then I could use a python script or applescript to do whatever I need. As I said, in my case, I want to first encrypt the motion capture movie file, then I want to upload it to AmazonS3.

    Yes, I imagine there's a way I could pull this off now, by triggering an action script which then parses a folder for new movies, tests that the files are closed/and or waits for a certain amount of time to pass since the latest file was added to know it is closed, then proceed with encryption/upload business logic, etc...and I imagine I'll probably end up writing something like that if I have to, but that's quite a lot of work just because I need to test when a movie/image is done being written. It would be great if Security Spy made this a little easier by offering a little more flexibility for the handoff of its movie/image files to a script.

    Please consider adding something like what I'm describing. Hopefully I've explained it clearly. I was really hoping something like this would be included in SecuritySpy v5.

    Thank you!
  • I notice now that when a movie file recording is in progress, the file extension is ".unf", so that's good - it makes the logic of determining whether a file is finished/closed easy enough, but it still leaves other problems. I can definitely write a script that essentially runs as a 'watch script' on the capture path and deals with parsing and keeping track of what needs to be encrypted and uploaded, but its still a bit messy to have to do all that work when all I really need is the path to the latest image/movie handed directly to a script so I can process the file.

    Also, there is another issue (something I requested a long time ago) that image and movie files all get stored in the same path, so the image files really pile up throughout the day (my camera prefs capture one image every 5 seconds continuous, plus the motion capture movies which pre-roll 1 minute and post-roll 2 minutes), making parsing a directory for movies to process a lengthier operation as the daily folder fills up with images. It would be nice if separate paths could be specified for images vs motion capture movies.

    I really think it would be useful for SecuritySpy to be able to hand off image/movie paths directly to a script as I mentioned above. Thanks!
  • SecuritySpy does in fact have the functionality you describe - please see the ProcessCapturedFile example at the bottom of the SecuritySpy AppleScript Examples page for details.

    Does this do what you want?
  • Ok! That's a bit of a hidden feature the way you've implemented it. ;)

    After doing some testing, my thoughts are - yes, it will work, but is there any chance of modernizing this functionality in the near future?

    1) It would be great if SecuritySpy could invoke python (and bash) directly. It's a waste of system resources to have to spin up applescript as an intermediary (and in my experience, sending a lot of rapid calls to applescript can lead to problems - memory leaks, OS sluggishness, crashes, etc).

    2) The ProcessCapturedFile solution is implemented globally for all SecuritySpy files that are written. I have 4 cameras. Each camera writes a JPG (capture image continuously) every 5 seconds, and captures an m4v only upon motion detection. I only want to process the m4v files. This means every 5 seconds, SecuritySpy is going to spin up 4 instances of the ProcessCapturedFile script. So then my applescript business logic executes the handoff to python only when the file path ends with 'm4v', otherwise, it just returns. 4 cameras every 5 seconds, excluding any motion capture events = 69,120 applescript launches per day. It would be great if, as I mentioned above, I could specify that a script of my choosing is run only upon motion detection, and on a per camera basis.

    3) Going a bit beyond the above suggestions, how about if SecuritySpy transmitted messages/notifications (JSON perhaps) on a specified port? Then there would be none of this overhead of spinning up scripts to process files; the user could just write a script that listened continuously for SecuritySpy messages and responded accordingly.

    Thank you!
  • Coming back to my thread from the other thread...

    I'm playing with reading eventStream via python.

    I trigger recording on a camera:

    The event stream outputs something like:
    20190715183529 508 CAM2 MOTION

    A file starts recording:
    2019-07-15 18-35-23 M CAM003.unf

    Rather oddly, the time stamp on the event stream appears to be several seconds later than the time stamp in the file name. I was thinking maybe I would be able to infer the file name via the time stamp in the event stream, but they don't line up, so that's a no-go.

    SecuritySpy is making this a challenge :-/

    Would be very useful to add the filename being recorded/finished to the event stream as I suggested in the other thread. Seems like it would fit the spec [INFO].

    Even better would be if the events were structured data (json or xml).

  • I understand your reservations about the AppleScript solution.

    We could make some changes to the event stream to make this work for you.

    The file name of the recorded file could be a few seconds before the actual motion, because SecuritySpy may have to start the capture earlier for two reasons. One is the pre-capture feature. The other is that recordings have to start on I-frames, so if the trigger occurs between I-frames, SecuritySpy has to go back to the previous I-frame, which could be several seconds before.

    So how about we add a new FILE event to the event stream, to notify whenever a new file is created, with the file path also supplied. Would that work for you?
  • Yes, a FILE event with path sounds good! Thank you very much! On the subject of paths, one other minor point - it would be helpful if the SecuritySpy file names did not contain any spaces, to eliminate some of the complexity of URL escape character complexity (spaces %20 in the domain vs '+' in the path). Underscores_should_rule_the_universe! ;-)
  • I've considered this a bit more, and I'm not sure that a new FILE event would really do the trick. What you need is some notification when a file has finished capturing, not when it has started capturing, right? Or, are you planning to use these FILE events to then monitor the file and take some action in the future when they are finished (e.g. when the file extension changes from .unf to .mov/.m4v)?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!