IpCamera: New IP Camera Binding

@matt1 ok soooo

given my NVR doesnt do Mjpeg, (*h264). & it doesnt do port fw
I need ffmpeg installed, a thing for each camera and I should be able to use the camera oh3 - habpanel json to view cameras on request.

The on request minimizes the impact on processor usage even when hls is always on.

If this is correct I think i got it.
Last question (promise) the binding doesnt actually store stuff right? dont need recording so it wont do naything like that

I have no idea what your nvr offers so it makes it hard to really comment. Does it have RTSP for each camera in h264 format? Does it have snapshot ability?

Hls does not use cpu. It can leave some files behind on your disk as that is how hls works. Other than this it does not store on the disk anything unless you record.

1 Like

it only offers two types of encoding. H264 and H265. so yes I would guess the rtsp is in this encoding and per camera - correct. (i.e. i can access via the isapi link)

thanks! I will work on this plan now to set things up - appreciate your time a lot!

I’m currently running snapshots:

runtimeInfo:
  version: 3.2.0
  buildString: "Build #2529"
locale: en-US
systemInfo:
  configFolder: /etc/openhab
  userdataFolder: /var/lib/openhab
  logFolder: /var/log/openhab
  javaVersion: 11.0.13
  javaVendor: Azul Systems, Inc.
  javaVendorVersion: Zulu11.52+13-CA
  osName: Linux
  osVersion: 5.4.0-89-generic

The INFO line repeats every second or so.

I’m happy to switch back to milestones if needed. Will have to figure that out, but I’m sure it can be done.

I successfully added a Reolink camera.
But having problems adding my doorbell with only a rtsp stream and no username and password.


Enabled tracing and this what I get with no username and password:

2021-10-23 14:05:35.305 [DEBUG] [pcamera.internal.StreamServerHandler] - Stream Server recieved request 	GET:/ipcamera.mjpeg
2021-10-23 14:05:35.306 [DEBUG] [hab.binding.ipcamera.internal.Ffmpeg] - Starting ffmpeg with this command now:********-********r********t********s********p********_********t********r********a********n********s********p********o********r********t******** ********t********c********p******** ********-********h********i********d********e********_********b********a********n********n********e********r******** ********-********l********o********g********l********e********v********e********l******** ********w********a********r********n********i********n********g******** ********-********i******** ********r********t********s********p********:********/********/********1********9********2********.********1********6********8********.********0********.********2********5********1********:********5********5********4********/********o********n********v********i********f********1******** ********-********q********:********v******** ********5******** ********-********r******** ********2******** ********-********v********f******** ********s********c********a********l********e********=********6********4********0********:********-********2******** ********-********u********p********d********a********t********e******** ********1******** ********h********t********t********p********:********/********/********1********2********7********.********0********.********0********.********1********:********9********0********2********0********/********i********p********c********a********m********e********r********a********.********j********p********g********

Somehow the FFMPEG parameters are completely garbled. Not sure if this caused by the binding or some other problem in OpenHab

I fixed a bug that does that when there is no user/ password. It is fixed it the jar you can download in this thread.

1 Like

Regarding the error that occurs as a result of trying to “Scan” for cameras, I have multiple network interfaces connected to my OpenHAB machine. I run OpenHAB on a VM and I have an interface for “normal” LAN traffic and I have an additional interface dedicated to a “Camera” LAN.

Could this be causing the errors? It does mention something about “…@Sharable…”

Also, I just installed the latest snapshot of your IpCamera binding dated Oct 24, 2021.

There is a problem then and my first guess is that you have not turned on the CGI/API in the cameras setup. Hikvision cameras come with the API disabled and no ONVIF user/pass setup so both of these are needed to be done. See the documentations steps on how to setup Hikvision.

There is an update in the latestest snapshot, can you update to it and retest? The sharable thing is new to me and if it is still occuring, then I will have to look into to see if it can be reproduced here… You dont need to scan and find cameras, manually adding them is more than fine and wont be causing the info log problem.

@matt1 thank you for this incredible binding. I have just started working on it. I can confirm it works with the Wainsview line of cameras using ONVIF.

I have done some reading on motion and object detection and must admit I am confused about where to begin. The Wainsview cameras do not seem to have very good detection (or it detects everything that moves).

I would like to be able to detect people, faces if possible, car and license plates if possible. Does the binding do that or do I need a third party application and something like google coral?

I don’t know much on object detection yet, but it would be an idea to weigh up the cost of a camera that has it built in. The CPU load to process multiple cameras means that you are best looking at coral or a GPU to offload the processing otherwise your looking at 1 FPS rates at detecting the objects which is OK for sensing objects to use in rules, but if your also wanting to see realtime boxes around the objects you may want a higher rate which the coral is good for. Then there is the issue of network traffic, your best to run multiple cameras and a 3rd party app on a separate switch to keep this traffic away from your openHAB server. For a low number of cameras that is less important to do.

If you want to get started, then there are these ways which I have not tried.

1 Like

Updating to this version and forcing the transport to UDP worked to successfully generate images from the rtsp stream. Thanks for making this binding.
Should the selection of transport al be part of the UI options? (I personally don’t have a big problem with adding the argument manually (-rtsp_transport udp))

@matt1 hi Matt,

have you come across a case when adding cameras that it causes issues with other bindings?
I have this case where i have added something like 20 cameras via the RTSP protocol (Hikvision didnt work). they appear on the clickcamera widget. but after finishing and runnign a reboot, the zwave binding has gone offline (and it wont come back online)

almost as if i used up too many system resources - does this make sense?
would it be the habpanel json or the number of rtsp cameras you think that causes it?

(i should add that if i reflash the sd card to prior to adding cameras it is back to normal)
If I remove the ipcamera binding - reboot - it is back to normal. then if I add the binding everything is ok (i guess until next reboot)

Alex

Yes there is a whole thread on this. Milestone 3 fixes this for most people but the latest jar and milestone 4 (due out in 1-2 weeks) should have it resolved.

@alexkarageorgis
This post should have all the info in it that you need.

IpCamera binding - Breaking changes and new features in 3.2 Milestone 3 and newer - Add-ons / Bindings - openHAB Community

1 Like

@JimT, I made rules for my Dahua and Hikvision cameras to change the switch times based on the Astro binding. Let me know if you’d like to see how I did it.

I’d love to see your code. I just use Sun elevation (also from astro). I’d like to also do it based on light level, e.g. when it’s very overcast / raining during the day, switch it to night profile too. I haven’t figured out how to determine the light level. I’d like to do it based on the camera / camera feed itself, and not have to use extra external lux sensors.

Here’s my current code, written in JRuby OpenHAB Rules System

require 'openhab'
require 'net/http'
require 'net/http/digest_auth'

SUN_ELEVATION_THRESHOLD = 5 # Threshold for switching camera profile to day/night

def http_digest_get(url, user:, pass:)
  digest_auth = Net::HTTP::DigestAuth.new

  uri = URI(url)
  uri.user = CGI.escape(user)
  uri.password = CGI.escape(pass)

  h = Net::HTTP.new uri.host, uri.port

  req = Net::HTTP::Get.new uri.request_uri

  res = h.request req
  # res is a 401 response with a WWW-Authenticate header
  auth = digest_auth.auth_header uri, res['www-authenticate'], 'GET'

  # create a new request with the Authorization header
  req = Net::HTTP::Get.new uri.request_uri
  req.add_field 'Authorization', auth

  # re-issue request with Authorization
  h.request req
end

def dahua_set_profile(ip, profile, user, pass)
  profile = { day: '0', night: '1' }[profile]
  http_digest_get("http://#{ip}/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=#{profile}",
                  user: user, pass: pass)
end

rule 'Dahua: Profile switch to day' do
  changed Sun_Elevation
  on_start
  run do |event|
    if Sun_Elevation > SUN_ELEVATION_THRESHOLD && (event.nil? || event.was <= SUN_ELEVATION_THRESHOLD)
      profile = :day
    elsif Sun_Elevation < SUN_ELEVATION_THRESHOLD && (event.nil? || event.was >= SUN_ELEVATION_THRESHOLD)
      profile = :night
    else
      next
    end
    logger.info("DAHUA PROFILE switched to: #{profile}")
    dahua_set_profile(CAMERA_IP['Street'], profile, CAM_USER, CAM_PASS)
  end
end

Thanks Matt,

I am going to have a look at Frigate

hi matt1, I am on milestone3 actually already.
For now I am ok after the unistall/re-install of the binding. Reading up on the link TY and waiting on m4.

the only thing which is strange (besides +10C temp on the RPI) is that the HLS stream isn’t consistent on my Amazon Firehd tables/Habpanel. It is better on my mobile phone (samsung note10).

so I have this

but some streams work better/appear and some just stay blank like below. (same setup ofcourse and all from the same NVR)

Is there some way to make the HLS stream faster to load?
Snapshots work ok every 5 seconds (question 2 - do snapshots keep getting “taken” even when the clickable widget isnt the active window?)

This is covered in the documentation here
IP Camera - Bindings | openHAB

With 20 cameras yes I am not surprised that M3 is still an issue, I have not tested that many before but you do not need to wait for M4 as I have uploaded the jar if you wish to try it out.

That is difficult to answer as it depends on the browser and the widget. You can easily check yourself by using DEBUG log output. Sometimes it is needed to press refresh on a browser after you leave the page to stop some streams.

Your streams not starting whilst others do, are any of them hikvision with digest? if so see here…

IpCamera binding - Breaking changes and new features in 3.2 Milestone 3 and newer - Add-ons / Bindings - openHAB Community

@matt1 I read that part - but I assumed that given I am talking to all cams through an NVR - same ip of NVR for all 20 cams/RTSP/different channels it isnt relevant to me? Should either work or not.

will try the new jar and revert after I read the debug info also.
thanks

Newer jar just uploaded for the hik digest bug. I have fixed a lot of bugs since M3 so you may find it now works with the newer jar. A NVR can be setup to allow each camera to be accessed via its own port, in that case it would depend on the cameras settings.