nodejs ONVIF camera framework
While working with regular streaming on OBS and Restream, I found that WiFi cameras could be a good use for streaming tasks. You can power them up with powerbank and drop to any location of the room, you can then easily move their position or rotate them remotely.
The only problem is that you need ONVIF camera interface. While working with OBS (openbroadcaststudio) software it's uncomfortable to switch windows just to control the camera and you actually don't need additional view window because you already have one in OBS. So I though of creating hotkeys so I could move my PTZ-enabled WiFi ONVIF camera without switching a desktop or window and without any actual interface for that.
So I found ONVIF node sources, checked and re-written them so they could use single config file (one-time setup) and now they can be easily runned like scripts from the system hotkey setup.
It's easy now to use this repo as a basis for your own online service or desktop app.
Node ONVIF
This source code repository helps you to write own nodejs-based ONVIF camera application or set up system hotkeys to use the camera. This repository aims to make super-easy, basic camera controls with NodeJS.
Technology stack
This is minimal node framework so it uses solo node(js) and 3 node modules.
Dependencies & requirements
- node
- node modules: xml2js, html, node-onvif
- npm
- any camera that supports ONVIF
Github repo link
https://github.com/sxiii/node-onvif
Functions
- Find cameras over the network
- Identify their UID, IPC and IP (onvifcamtest.js)
- Get information on found camera: manufacturer, model, firmware, serial number, id (caminfo.js)
- Find real RTSP stream address (streaminfo.js)
- Turn the camera left, right, up, down; zoom in & out (files: turnleft.js, turnright.js, turnup.js, turndown.js; zoomin.js, zoomout.js)
- Get snapshot from the camera (getsnapshot.js)
Notes
- Not all PTZ functions work with all PTZ cameras (for example, zoom functions may absent)
- Not every camera has the same snapshot functionality (so, the getsnapshot might return 404 error)
- There might be some errors worth noting or fixing (if you find them, please create an issue here)
How to use
- Install dependencies (npm, git and then npm modules): ubuntu sample -
sudo apt install npm git; npm install xml2js html node-onvif
- Clone this repository:
git clone https://github.com/sxiii/node-onvif
- Enter the repo directory:
cd node-onvif
- Run the detection JS node script to find IP of the camera:
node onvifcamtest.js
- Copy the IP & Port address to clipboard or remember them.
- Open the config.js file and replace the IP & Port with yours. Save & close the file.
- Now you can run any .js file in the folder like:
node streaminfo.js
Using options
You can use this script to make an instant camera snapshot, or, for example, control the camera while streaming from it with OBS (OpenBroadcastStudio). For this usecase (eg.: turn the camera right), just create keyboard shotcut with the following command: node /home/username/node-onvif/turnright.js
and then arrange the hotkey. You could set up keys for rotating the camera to all directions, taking the snapshot, etc etc.
Example of config.js file
Please replace the IP, port and user/pass combination according to found information (onvifcamtest.js output) and/or the datasheet of the camera. The file should look like this:
module.exports = {
xaddr: 'http://192.168.1.100:5000/onvif/device_service',
user : 'admin',
pass : '123456'
};
All other scripts (except onvifcamtest.js) takes camera configuration from this file.
Sample output of onvifcamtest.js
Start the discovery process.
1 devices were found.
- urn:uuid:2419d68a-2dd2-21b2-a205-000C437D0EF6
- IPC 10704807
- http://192.168.1.100:5000/onvif/device_service
Sample output of caminfo.js
{
"Manufacturer": "Technology",
"Model": "IPC",
"FirmwareVersion": "21.00.00.35",
"SerialNumber": "10704807",
"HardwareId": "Ver 2.1"
}
Sample output of streaminfo.js
rtsp://192.168.1.100:554/onvif1
Sample output of getsnapshot.js
Look for file saved in the directory: snapshot.jpg
Done!
Sample output of any rotation or zoom files
Done!
Further development, community help, issues etc.
I would like to improve this repo but not making it monstrous. If you have your commits for better ONVIF snapshot features or some other useful (but still small) functions, please add them. Found a bug? Make an issue in this repo. You can support my work - contact me on telegram @fakesnowden for details.
Additional info
- NodeJS website: https://nodejs.org
- Credits to the samples from https://github.com/futomi/node-onvif
Hope this repository will be useful for your camera and ONVIF tasks.
Independent steemit & golos author,
Den Ivanov aka @sxiii
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Hey @sxiii I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x