A Dashboard setup for video cameras

rtsp is very intensive for the receiver as it has to decompress every frame coming in even if it does not need intermediate ones. As you found you can decrease the overhead by reducing the image size coming from the camera. If you can also reduce the frame rate coming from the camera that will also help. Note that it is the image size and frame rate coming from the camera that is key.

sorry, i have a question.

how to implement this with usb camera(not webcamera, it's a industry camera with usb)?
in function updatePic():
document.getElementById('c51').src = "http://192.168.0.234:8081/1/stream";

the src section is not the http adrs for usb camera, how to fill the src argument with usb camera(industry camera DFK-33UX287)

Thanks so much for help...

I think the simplest way is to add a streaming service that captures your usb camera and then streams the video via a http server. It is rather simple

  1. Assuming you run this on a raspberry pi, install mjpg-streamer software
    https://github.com/jacksonliam/mjpg-streamer

  2. for each usb camera, start a mjpg-streamer, setting it with different ports and devices

As example, using this command
pi@Motion5:~/mjpg-streamer/mjpg-streamer-experimental $ sudo ./mjpg_streamer -o "output_http.so -w ./www -p 8888" -i "input_uvc.so -d /dev/video0"

For camera on device /dev/video0 will stream the camera video on port 8888

MJPG Streamer Version: git rev: 501f6362c5afddcfb41055f97ae484252c85c912
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: -1
i: Format............: JPEG
i: TV-Norm...........: DEFAULT

The url for this is in my case: http://192.168.0.234:8888/?action=stream

If I insert this url into the example above, I get the video nicely presented in the dashboard. So changing a line into this

document.getElementById('c54').src = "http://192.168.0.234:8888/?action=stream";

Remember to start one instance of mjpg-streamer for each camera and use different ports and devices

Finally, it is very convenient to let node-red start the mjpg-streamers, just using one exec node for each instance

2 Likes

The camera I have will not allow attaching to video without authentication. Are there any provisions for sending login credentials to camera?

It depends on your camera, for wifi/ip cameras several methods have been discussed in other threads in this forum, you need to do some searching, the board is not organized in enough subjects to make it easy to find such related postings

If you have usb cameras needing login and you decide to use mjpg-streamer as mentioned in previous posting, it also has support for camera login settings

If you decide to use Motion as a streaming service, it has support for login to ip cameras as well

its work!!!

thanks so much!!!!

Is it possible to select camreas with dropdown ui node instead of showing all of them at once?

If possible, yes, but it will require a different web page design. Some html and javascript editing needed, please feel free

@baha00

A little example to start from

[{"id":"924b99c4.f384a8","type":"comment","z":"41e2bf04.cbff6","name":"Just a live view of cameras","info":"","x":380,"y":220,"wires":[]},{"id":"dc120136.033da","type":"ui_template","z":"41e2bf04.cbff6","group":"380498f.f287668","name":"Just a view of cameras","order":1,"width":"7","height":"5","format":"<!DOCTYPE html>\n<html>\n<style>\nimg {\n    border: 1px solid #ddd;\n    border-radius: 8px;\n    padding: 2px;\n    width: 320px;\n}\n</style>\n\n<script type=\"text/javascript\">\nscope.$watch('msg', function(msg) {\n    inMessage(msg.payload);\n});\n\nfunction selectCam(url) {\n    document.getElementById('cX').src = url;\n}\n\nfunction inMessage(event) {\n    if (event.match('http://')) {\n        selectCam(event);\n    }\n}\n\n</script>\n<center>\n<table>\n    <tr><!-- Row 1 -->\n    \t\t<td style=\"text-align: center\"><img src=\"\" id=\"cX\" /></td>\n    </tr>\n</table>\n</center>\n</html>","storeOutMessages":false,"fwdInMessages":false,"templateScope":"local","x":580,"y":260,"wires":[[]]},{"id":"3ee5c335.84d9dc","type":"ui_dropdown","z":"41e2bf04.cbff6","name":"","label":"","tooltip":"","place":"","group":"380498f.f287668","order":2,"width":0,"height":0,"passthru":true,"options":[{"label":"Camera 1","value":"http://192.168.0.237:8081","type":"str"},{"label":"Camera 2","value":"http://192.168.0.237:8082","type":"str"}],"payload":"","topic":"","x":340,"y":260,"wires":[["dc120136.033da"]]},{"id":"380498f.f287668","type":"ui_group","z":"","name":"LiveVideo","tab":"73890071.f55b","disp":false,"width":"7","collapse":false},{"id":"73890071.f55b","type":"ui_tab","z":"","name":"LiveVideo","icon":"dashboard","order":2}]

You have to edit the camera ip-adresses in the dropdown to fit yours (and other stuff as you prefer)

Already dark here...

aa this is great much easier then my original idea. I just added to your template refresh function

Just tried you little example but does not work for me. Could it be a problem with authentication. I have a user name and password on my camera.

Possible yes
You may have to have a complete url incl user and passform
Try it out first in a normal browser lik chrome

Is it possible that I can stop the motion library (sudo service motion stop) from the dashboard by adding some switch?

Yes, you can use an exec node, but first you will have to use sudo visudo to allow the node red user use sudo with the service command without the need for entering a password.

Could you clarify some things first? When you say stop motion, I could assume several things.

  • I could assume yo want to terminate the motion process
  • I could assume you want to stop motion detect motions in the video

In any case, there are already url's available for both (where your_ip is the ip address of the computer where Motion is running)

to terminate motion:
http://your_ip:8080/0/action/end

to pause/stop motion detection:
http://your_ip:8080/0/detection/pause

to enable motion detection:
http://your_ip:8080/0/detection/start

To send those from Node-RED just use the http node like in this example

From Motion Web Control (depending on your version of Motion),

The following are the commands available. * {IP}:{port}/{camid}/config/list Lists all the configuration values for the camera.

  • {IP}:{port}/{camid}/config/set?{parm}={value1} Set the value for the requested parameter
  • {IP}:{port}/{camid}/config/get?query={parm} Return the value currently set for the parameter.
  • {IP}:{port}/{camid}/config/write Write the current parameters to the file.
  • {IP}:{port}/{camid}/detection/status Return the current status of the camera.
  • {IP}:{port}/{camid}/detection/connection Return the connection status of the camera.
  • {IP}:{port}/{camid}/detection/start Start or resume motion detection.
  • {IP}:{port}/{camid}/detection/pause Pause the motion detection.
  • {IP}:{port}/{camid}/action/eventstart Trigger a new event.
  • {IP}:{port}/{camid}/action/eventend Trigger the end of a event.
  • {IP}:{port}/{camid}/action/snapshot Create a snapshot
  • {IP}:{port}/{camid}/action/restart Shutdown and restart Motion
  • {IP}:{port}/{camid}/action/quit Close all connections to the camera
  • {IP}:{port}/{camid}/action/end Entirely shutdown the Motion application
  • {IP}:{port}/{camid}/track/center Send command to center PTZ camera
  • {IP}:{port}/{camid}/track/set?x={value1}&y={value2} Send command to PTZ camera to move to location specified by x and y
  • {IP}:{port}/{camid}/track/set?pan={value1}&tilt={value2} Send command to PTZ camera to pan to value1 and tilt to value2

Thanks for your kind reply. Actually, In my case, I wanna get an email with the attached picture when some motion in front of PIR motion sensor. And if necessary then I wanna have a look with live streaming.


To get an email with the attached picture I need to stop the motion library by using the following command in command prompt sudo service motion stop
Otherwise, I received email with a corrupted file.

So the camera is somehow shared by motion and the "take photo node" and you get a conflict??

As I can see, my camera always on, until I will stop the motion library from command prompt. I think that mean camera is always used by this library.

You know you can ask Motion to take snapshot?
You could then in NR

  • ask Motion to take snapshot
  • pick the file and send via email

I thought motion could detect motion and save stills. So why do you need the pir ?