Python_script to grab ffmpeg single frame

Tags: #<Tag:0x00007f326fe54dd8>

Hi everybody,

I have three cameras that do not play well with Home Assistant; while I can display their stream, it is impossible torun the camera.snapshot service.

These camera entities are webcams connected to raspberry pis (two PS2 USB cams, one PiCam) and broadcast their streams via motion.

I positively can grab a live still image by running this command ffmpeg -y -i http://ip:8081 -f image2 grab.png; this will create/overwrite grab.png and write the frame that is displayed at the moment to this file.

Unfortunately, I was not able to find a library for python so that I could trigger a python_script via HASS. The libraries that I found were for streaming via ffmpeg, not to utilize ffmpeg to do something else.

Though I could probably just use python to run this very bash command I posted above via os, I’d prefer a “cleaner” solution (or, a plain python solution, if you will).

Or is there a HASS native way to do this that I missed? I know that motion itself can also trigger snapshots, but I particularly do not want to do this. The entire logic should run on my Home Assistant server, so if I ever add another camera (perhaps one that does not even run on motion, so utilizing motion’s capture feature would not be available) it would still work just alike without changing things.

I need to grab multiple snapshots from these cameras when the linked motion sensors trigger and I am not at home.

Thank you in advance for your ideas :slight_smile:

If you can grab the pictures (a still) then you can put a copy in the local directory (www) and make a camera integration to look at the image then use a picture glance card to display the camera.

Or am I missing the point?

Sorry, I just realized there was a reply to this topic right now…

Well, I need to trigger this somehow. When Home Assistant detects motion (via zigbee2mqtt binary_sensor.motion), I want it to trigger a python script (ideally), that will grab the pictures.

But I don’t know how to get python to do this, other than via running the ffmpeg command via bash inside python, which seems to be the wrong way.