Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on-camera motion detection with ONVIF #29

Open
scottlamb opened this issue Mar 9, 2018 · 4 comments
Open

on-camera motion detection with ONVIF #29

scottlamb opened this issue Mar 9, 2018 · 4 comments
Labels
enhancement rust Rust backend work required
Milestone

Comments

@scottlamb
Copy link
Owner

Realistically speaking any decent NVR must have motion detection. On-camera motion detection is one of the two paths forward. Marking milestone-1.0? accordingly.

Needs the signals schema (#28). Additionally, needs to speak SOAP in some way:

  • pure Rust SOAP library? raventid/soap-rs is the only one I've found; it's not usable yet.
  • C/C++ SOAP library? xris-hu/gsoap-onvif or xsmart/onvifcpplib?
  • just do the little bit of SOAP we need by hand? I noticed there's some node onvif library that does this, so maybe it's not so bad.

I'd also considered using Hikvision's simple non-SOAP/ONVIF proprietary protocol, but then Dahua came out with the Starlight camera series, and I bought one...I've even got some code to watch Hikvision camera motion events but it's much less appealing to me now.

@scottlamb
Copy link
Owner Author

I've been experimenting with this.

Good news: it's actually not so bad to hand-roll the SOAP/ONVIF bits I need in pure Rust.

Bad news: common vendors don't speak ONVIF very well. Dahua is particularly bad. See this thread for a summary.

@scottlamb
Copy link
Owner Author

scottlamb commented Jun 24, 2019

My playground for experimentation with this is here: https://github.com/scottlamb/moonfire-playground

I have toy code for Dahua and Hikvision's proprietary protocols. ONVIF PullMessages turned out to be kind of disappointing for my Dahua case as described in the thread linked in the previous comment. The Dahua supports the RTSP vnd.onvif.metadata stream with some setup (and the hand-rolled SOAP stuff for configuring it is bearable). The Hikvision doesn't. So there's no one approach that will work for all cameras, but maybe a handful of different ones should cover it.

[edit later: Hikvision does support the RTSP stream! It's just a little finicky, as described on the wiki.]

@scottlamb scottlamb added the rust Rust backend work required label Jul 11, 2019
@srd424
Copy link

srd424 commented Jul 1, 2020

I'm really interested in something like this for Reolink cameras as well... fwestenberg/reolink_dev#7 (comment) suggests it's possible, but I've not had much luck as yet trying to talk ONVIF to the camera in python ..

@scottlamb
Copy link
Owner Author

That screenshot looks promising. There are three ways to get ONVIF notifications:

  • The RTSP vnd.onvif.metadata stream, which you set up with some ONVIF (SOAP over HTTP) calls then get via RTSP.
  • ONVIF PullPoint notifications, which are buggy on Dahua cameras.
  • ONVIF Basic notifications, which are a pain firewall-wise, as described here.

I can't tell from skimming that thread which they're using. But I'm trying to get the RTSP method to work.

There's a Rust onvif library here. You could try cargo run --example camera enable-analytics --uri http://your/camera --username user --password pass which may or may not work. That library's a work in progress. The code here is supposed to:

  1. find the metadata service URL via GetServices on the device management service (which has a well-known URI)
  2. find a metadata configuration via GetMetadataConfigurations on the media service
  3. if that configuration doesn't have analytics and events turned on, toggle them via SetMetadataConfigurations
  4. list all the profiles via GetProfiles
  5. if any profiles don't have a metadata configuration, add this one via AddMetadataConfiguration

After that, the RTSP stream URIs returned by cargo run --example camera get-stream-uris ... should have include ONVIF metadata, so you can use an RTSP library to watch it. I hope to make a polished version of that here...

scottlamb added a commit to scottlamb/moonfire-playground that referenced this issue Jul 10, 2020
* use the same nvr client as nvr-motion rather than a separate file.
  This meant updating reqwest version. I ended up using blocking reqwest
  for the multipart stuff to avoid rewriting it. This is kind of silly;
  I'm creating a dedicated thread from a runtime, then it's creating its
  own runtime. But doing a nicer conversion of multipart.rs to async may
  not be worth it. I'm not sure I'll need it for long because rtsp
  metadata streams are looking promising. So just do the minimum so I
  can run them side-by-side if desired.

* update a couple things to newer version of my log crate

* add a rtsp watcher stream. It doesn't actually interpret the stream
  and send signals yet. And it doesn't do any of the setup, which
  is a multi-step ONVIF procedure, as mentioned here:
  scottlamb/moonfire-nvr#29 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement rust Rust backend work required
Projects
None yet
Development

No branches or pull requests

2 participants