Comments (20)
I'll close this, we have the package up and running :-)
Thanks for the help @hawkeye64 !
from onvif.
Long time passed, I know, but I think this is useful. In some cases, when trying to get URIs from a remote camera, it returns an URI based on its local IP. In my case, after broke my mind a big bit, I discovered this. The solution is based on replace local IP with standard remote IP with a few lines of code.
// Function to search for index of nth occurrences
function getPosition(string, subString, index) {
return string.split(subString, index).join(subString).length;
}
this.getSnapshotUri({stream:'RTP-Multicast', protocol:'RTSP'}, function(err, stream) {
// these first three lines do the fix
let urii = stream.uri;
let ibar = getPosition(urii, '/', 3);
let fixedURI = 'http://' + HOST + ':' + PORT + urii.substring(ibar);
request({
method: 'GET',
uri: fixedURI,
...
from onvif.
Hi @cristhiangr - likely because you're using request without any authentication set. Try setting the username and password in the request library as well:
request.get(rutaOnvifImagen, {
'auth': {
'user': getUser(),
'pass': 'getPassword()
}
});
Let me know how you get on
from onvif.
Hi @chriswiggins Thanks for answering. I implemented what you indicate, but the result is the same.
I'm new in Node js, Until 2 days ago I didn't know what it was, but I'm looking for a solution to take images from Onvif and this looks good. I'm probably implementing something wrong
This is my code:
var http = require('http'),
Cam = require('onvif').Cam,
fs = require("fs"),
request = require('request');
init();
function init(){
if(checkIP() && checkUser() && checkPassword() && checkPort()){
new Cam({
hostname: getIP(),
username: getUser(),
password: getPassword(),
port: getPort()
}, function(err) {
if (err) {
console.log('Connection Failed for ' + getIP() + ' Port: ' + getPort() + ' Username: ' + getUser() + ' Password: ' + getPassword());
return;
}
console.log('CONNECTED');
this.absoluteMove({
x: 1
, y: 1
, zoom: 1
});
this.getSnapshotUri({protocol:'RTSP'}, function(err, stream) {
saveImage(stream.uri);
});
});
}
else
{
console.log("datos de inicio incompletos o no validos");
}
}
function saveImage(pathOnvifImage){
request.get(pathOnvifImage, {
'auth': {
'user': getUser(),
'pass': getPassword()
}
});
var file = fs.createWriteStream("miImagen.jpg");
request(pathOnvifImage).pipe(file);
}
Thanks,
from onvif.
Thanks, Chris, that you still reply for every message, I really appreciate you for that. @chriswiggins
from onvif.
@cristhiangr, JavaScript is an asynchronous language, so you should put your getSnapshotUrl under the callback, cause communication with camera is async.
You can try to cover it to promise with bluebird library and use async-await with the es7 features
I'll try to add this ASAP
This is all that I can see in your code, that you send
from onvif.
from onvif.
Thanks, I created a gist and put what the code there. This is the link https://gist.github.com/cristhiangr Thank you very much @agsh and @chriswiggins . I'm reading about bluebird, but I still don't know what I should do.
from onvif.
Hi @cristhiangr,
I think I've found the problem. Try this in your save image function:
function saveImage(pathOnvifImage){
var file = fs.createWriteStream("miImagen.jpg");
request.get(pathOnvifImage, {
'auth': {
'user': getUser(),
'pass': getPassword()
}
}).pipe(file);
}
What you were doing was making two requests to the same place, one with authentication and one without, and saving the one without authentication. Let me know if this works
from onvif.
@chriswiggins thank you very much for continuing to respond, I implemented the changes you suggest but I still have the same result
from onvif.
@cristhiangr, can you post here your pathOnvifImage
string?
Also please check the authorization headers of GET response.
from onvif.
hi @agsh ofcourse, this is the path onvif (stream.uri), http://192.168.1.251/onvif-cgi/jpg/image.cgi?resolution=1280x1024&compression=30 that I get with the getSnapshotUri method. If I public this code like a webserver effectively I see the image in that web path (in the web browser)
from onvif.
So you can open an image via this url in the browser?
Try this code
request('http://192.168.1.251/onvif-cgi/jpg/image.cgi?resolution=1280x1024&compression=30')
.pipe(fs.createWriteStream('miImagen.jpg'));
from onvif.
Hello @agsh , excuse the delay in replying, I implemented that, but I still have the same result. Yes I can open an image via this url in the browser. I'll record a video and upload it so you can see in detail what happens.
Thanks
from onvif.
@agsh, @chriswiggins , today I tested with a vivotek camera and a hikvision camera, and I was able to save the image without any problem. However, with the camera axis, which I have had all this time, I still have the problem of authorization to save the image.
from onvif.
In case anyone finds this based on an issue they are having I have written a gist. The issues you might encounter are:
- Connecting to a camera (how to use authorization)
- Getting the snapshotUri
- Getting a snapshot
a. How to get the raw data back using axios without any transformations (ie: line-feed conversions)
b. How to get the snapshot from a camera that is set up for Basic Auth
c. Base64 encode the raw data using Nodejs Buffer class
d. Write the data to a file, for testing purposes
Remember, this is only a Gist and is not the fully completed code that I use.
https://gist.github.com/hawkeye64/a30e43c8301626f7687b985b5e7b04bd
Btw, I use Hikvision, Pelco, TrendNET and Axis cameras.
from onvif.
If it helps, I have an updated gist using request as axios would not work with Digest Realm of an Axis camera.
https://gist.github.com/hawkeye64/e67cb5aae8f46d9c94ea2c9a4bb9247b
Someone should close this issue. @chriswiggins ?
from onvif.
We should probably include a method to return the image as a Buffer into the code. How would you feel about that @hawkeye64?
from onvif.
Yeah, I can add it. Look for it sometime after the weekend.
from onvif.
There is now an onvif-snapshot package. Found here: https://github.com/chriswiggins/onvif-snapshot
As soon as @chriswiggins takes the latest PR, you should be able use it with node (currently snapshot.js library path is incorrect in package.json).
I have a sample app based on onvif and onvif-snapshot that I'll be releasing soon.
from onvif.
Related Issues (20)
- D-Link DCS-8635LH not working HOT 3
- Non conform /onvif/media2_service response leads to Error: Unrecognized configuration HOT 2
- setOSD(): position can take effect, but plaintext does not HOT 1
- Question: I have a dvr/nvr dahua so the discover method retrieve me 1 record. Is there any other method that can tell me how many cameras the dvr has? HOT 2
- Error: GetRecordings
- Compatibility of Axis M5000-G PTZ Camera. HOT 4
- HikVision "Wrong ONVIF Soap Response" Error HOT 17
- Find recording from nvr within specific time HOT 4
- ONVIF SOAP Fault during connect with Vivotek camera's HOT 3
- Action string in Content-Type causes failures with Illustra cameras
- Discovery has been unable to search, how to debug it
- Discovery displays HTTP servers on local network
- Wrong ONVIF SOAP Response on AXIS Cameras
- NetworkInterfaceSetConfiguration documentation change
- feat req: custom position in createOSD HOT 1
- No events for TAPO C520 C510 HOT 1
- relativeMove documentation incorrect
- Unsubscribe: Triggers a second unsubscribe via _eventRequest
- getRecordingOptions not working with UNIVIEW Channels | brand issue | ONVIF SOAP Fault: Optional Action Not Implemented
- Add an option to set pull-request timeout
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from onvif.