Record a video based on Switch value

Hello,

I have IP Camera and I can record the rstp stream with avconv.

avconv -rtsp_transport tcp -i rtsp://username:password@10.0.0.7/live/ch0 -r 30 -vcodec copy -an -t 5 /alarm/video/frontcamera’date +%Y-%m-%d-%H-%M-%S’.mp4

This command will record a 5 sec clip from the camera.

I’m calling this from rule when motion sensor says that there is movement and we are not at home.

I would like to change this so that camera will record when ever I want as long as it is feasible.

I was thinking to have a Switch FrontCameraRecord and when ever this switch was on there would be avconv running and recording. And when FrontCameraRecord goes off I would stop recording.

Is this doable?

–Ari

Is there for example way to make avconv a service and then I would start and stop the service from openhab based on switch?

Hey @Ari_Hagman,
I thing this really depends on the behavior of avconv. Currently you have the “-t 5” parameter which I guess are your 5 seconds.
What would happen if you ran avconv without this parameter and then killed the process with Ctrl+c? Do you get a valid video file?

Now try the same thing with first executing in the background and then kill using SIGTERM

If you were successful so far, start getting this procedure into your openhab rule.

Ah and to answer your second question, the described procedure is how a service would accomplish something like this. So yes, you could turn the whole thing into a service and only call this one from openHAB.

Thanks,

I will try to make service out of this.

–Ari

This is the way I solved this

Created a service /init/etc/camera-front-record.conf, with following:

start on filesystem
exec avconv -rtsp_transport tcp -i rtsp://user:password@10.0.0.7/live/ch0 -c copy -map 0:0 /alarm/video/front-camera’date +%Y-%m-%d-%H-%M-%S’.mp4

With sudo visudo added a line (So that openhab can start and stop a service)

openhab ALL = NOPASSWD: /usr/sbin/service camera-front-record *

Added an item

Switch  CameraFrontRecord

Added a rule

rule "Camera Front Start Recoring"
when 
   Item CameraFrontRecord changed to ON
then
executeCommandLine("sudo@@service@@camera-front-record@@start")

rule "Camera Front Stop Recoring"
when 
  Item CameraFrontRecord changed to OFF
then
  executeCommandLine("sudo@@service@@camera-front-record@@stop")

And in my Motion detection rule

rule "Motion Front"
when 
  Item MotionFront changed to OPEN
then
  sendCommand(CameraFrontRecord,ON)
end

rule "Motion Front"
when 
  Item MotionFront changed to CLOSED
then
  sendCommand(CameraFrontRecord,OFF)
end

Next thing to solve is how to show these recording from openhab UI.

1 Like