IpCamera: New IP Camera Binding

Thanks for reply. I have NVR at remote location. I dont have openhab at this location. At my home i have openhab. Want to connect to remote location nvr from openhab so that i can see cameras and other smart devices at one place. Today i m using nvr provided mobile app.

I m aware how opehab can be exposed to internet.

Hope this explains my use case to connect to remote cameras or nvr.

Are the remote camera and openhab both behind separate routers? If so, I’d recommend setting up a site-to-site VPN so the camera appears to be on the same LAN as openhab.

1 Like

Yes both are on different router. Actually cameras are are more than 1000 miles away.

Let me check VPN solution.

Thanks

You do not need to include the user:pass in the rtsp url with this binding.

Can you enable DEBUG level logs and see what happens when you open and close the strreams? It should give you a count of how many streams are in use. If it never goes back to 0 streams it will not stop creating it. Some browsers will not close the stream even when you navigate away until you press the refresh or stop button of the browser.

Here is the DEBUG log:

2022-12-25 19:32:15.195 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:32:23.203 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:32:31.150 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:32:39.160 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:32:47.195 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:32:55.142 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:33:03.153 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:33:11.201 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:33:19.235 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:33:27.195 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:33:35.196 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:33:43.152 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:33:51.169 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:33:59.131 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:34:07.164 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:34:15.162 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:34:23.157 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:34:31.174 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:34:39.194 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:34:47.142 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:34:55.216 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:35:03.159 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:35:11.133 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:35:19.141 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:35:27.135 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:35:35.215 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:35:43.169 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:35:51.193 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:35:52.352 [DEBUG] [amera.internal.servlet.CameraServlet] - GET:/ipcamera.mjpeg, received from 192.168.0.131
2022-12-25 19:35:52.354 [DEBUG] [amera.internal.servlet.CameraServlet] - First stream requested, opening up stream from camera
2022-12-25 19:35:52.356 [DEBUG] [hab.binding.ipcamera.internal.Ffmpeg] - Starting ffmpeg with this command now:-rtsp_transport tcp -hide_banner -i rtsp://USERNAME:********@192.168.0.138:88/videoSub -q:v 8 -r 5 -vf scale=1024:-2 -update 1 http://127.0.0.1:8080/ipcamera/001/ipcamera.jpg
2022-12-25 19:35:59.210 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:36:04.764 [DEBUG] [amera.internal.servlet.CameraServlet] - Now there are 0 ipcamera.mjpeg streams open.
2022-12-25 19:36:04.767 [DEBUG] [hab.binding.ipcamera.internal.Ffmpeg] - Stopping ffmpeg MJPEG now when keepalive is:8
2022-12-25 19:36:04.771 [DEBUG] [amera.internal.servlet.CameraServlet] - All ipcamera.mjpeg streams have stopped.
2022-12-25 19:36:07.033 [DEBUG] [era.internal.handler.IpCameraHandler] - MJPEG was not being produced by FFmpeg when it should have been, restarting FFmpeg.
2022-12-25 19:36:07.038 [DEBUG] [hab.binding.ipcamera.internal.Ffmpeg] - Starting ffmpeg with this command now:-rtsp_transport tcp -hide_banner -i rtsp://USERNAME:********@192.168.0.138:88/videoSub -q:v 8 -r 5 -vf scale=1024:-2 -update 1 http://127.0.0.1:8080/ipcamera/001/ipcamera.jpg
2022-12-25 19:36:08.208 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:36:15.181 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:36:23.166 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:36:31.182 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:36:39.262 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:36:47.191 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:36:49.089 [DEBUG] [amera.internal.servlet.CameraServlet] - GET:/ipcamera.mjpeg, received from 192.168.0.131
2022-12-25 19:36:49.092 [DEBUG] [amera.internal.servlet.CameraServlet] - First stream requested, opening up stream from camera
2022-12-25 19:36:55.223 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:37:03.183 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:37:08.931 [DEBUG] [amera.internal.servlet.CameraServlet] - Now there are 0 ipcamera.mjpeg streams open.
2022-12-25 19:37:08.934 [DEBUG] [hab.binding.ipcamera.internal.Ffmpeg] - Stopping ffmpeg MJPEG now when keepalive is:8
2022-12-25 19:37:08.936 [DEBUG] [amera.internal.servlet.CameraServlet] - All ipcamera.mjpeg streams have stopped.
2022-12-25 19:37:11.050 [DEBUG] [era.internal.handler.IpCameraHandler] - MJPEG was not being produced by FFmpeg when it should have been, restarting FFmpeg.
2022-12-25 19:37:11.056 [DEBUG] [hab.binding.ipcamera.internal.Ffmpeg] - Starting ffmpeg with this command now:-rtsp_transport tcp -hide_banner -i rtsp://USERNAME:********@192.168.0.138:88/videoSub -q:v 8 -r 5 -vf scale=1024:-2 -update 1 http://127.0.0.1:8080/ipcamera/001/ipcamera.jpg
2022-12-25 19:37:11.190 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:37:19.229 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:37:27.245 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:37:35.207 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:37:43.190 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:37:51.241 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:37:59.203 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:38:07.346 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:38:15.223 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now
2022-12-25 19:38:23.233 [DEBUG] [era.internal.handler.IpCameraHandler] - End of FOSCAM handler reached, so closing the channel to the camera now

At first it was opened in android app and second is chrome browser.
Opening order in Chrome, Forefox or Android app does not change anything.
As you can see it restarts the stream (ffmpeg) all the time.

edit:
I was closing browser completey to perform the test.

OK I added a fix and made a build for you to try. Where to download and how to install it is found in this thread as I am in the middle of adding Reolink API to the binding but all untested code is only under the reolink thing type and wont affect other brands.

Adding Reolink API to the IpCamera Binding, Alpha and Beta testers needed - Add-ons / Bindings - openHAB Community

I have done some some tests and snapshot (ipcamera-2022-12-26-PM.zip) works perfect. It is closing mjpeg streams. Thank you for your hard work.

1 Like

I seem to have strange issue where MJPEG stream opened in browser “works” but when I am embedding it in sitemap it stops working after second or two.

I have MW Power IPC-D304F-I (its just some rebranded HikVision).

This is config:

Thing ipcamera:hikvision:podjazd "Podjazd"
[
  ipAddress="<camera ip>",
  username="<username>",
  password="<password>",
  onvifPort=8000, //normally 80 check what it needs
  port=80,
  nvrChannel=1,
  ffmpegOutput="/var/lib/openhab/ipcamera/podjazd/",
  ffmpegInput="rtsp://<camera ip>:554/ISAPI/Streaming/channels/401"
]

Sitemap:

Video url="http://127.0.0.1:8080/ipcamera/podjazd/ipcamera.mjpeg" encoding="mjpeg"

When I open stream in a browser (using openhab ip instead of localhost) the stream opens, it sometimes flickers (and sometimes goes all gray when web browser window loses focus) but overall it works.
In trace logs there is:

23:31:02.347 [DEBUG] [camera.internal.servlet.CameraServlet] - GET:/ipcamera.mjpeg, received from <my pc ip address>
23:31:02.351 [DEBUG] [camera.internal.servlet.CameraServlet] - Not the first stream requested but the stream from camera was closed
23:31:02.361 [TRACE] [mera.internal.handler.IpCameraHandler] - Sending camera: GET: http://<camera ip>:80/ISAPI/Streaming/channels/102/httppreview
...
23:31:12.120 [TRACE] [ng.ipcamera.internal.HikvisionHandler] - HTTP Result back from camera is  :--boundary
Content-Type: application/xml; charset="UTF-8"
Content-Length: 512

<EventNotificationAlert version="2.0" xmlns="http://www.std-cgi.com/ver20/XMLSchema">
<ipAddress>{camera ip}</ipAddress>
<portNo>80</portNo>
<protocol>HTTP</protocol>
<macAddress>10:12:fb:49:7e:7f</macAddress>
<channelID>1</channelID>
<dateTime>2023-01-04T23:21:07+01:00</dateTime>
<activePostCount>0</activePostCount>
<eventType>videoloss</eventType>
<eventState>inactive</eventState>
<eventDescription>videoloss alarm</eventDescription>
<channelName>Podjazd</channelName>
</EventNotificationAlert>
:

But if I open it in Openhab Android application it shows few frames and stream stops with some visible artifacts. In logs there is:

23:30:18.817 [DEBUG] [camera.internal.servlet.CameraServlet] - GET:/ipcamera.mjpeg, received from 127.0.0.1
23:30:18.819 [DEBUG] [camera.internal.servlet.CameraServlet] - First stream requested, opening up stream from camera
23:30:19.246 [DEBUG] [camera.internal.servlet.CameraServlet] - Now there are 0 ipcamera.mjpeg streams open.
23:30:19.248 [DEBUG] [camera.internal.servlet.CameraServlet] - All ipcamera.mjpeg streams have stopped.
23:30:19.276 [DEBUG] [camera.internal.servlet.CameraServlet] - GET:/ipcamera.mjpeg, received from 127.0.0.1
23:30:19.278 [DEBUG] [camera.internal.servlet.CameraServlet] - First stream requested, opening up stream from camera
23:30:19.285 [TRACE] [mera.internal.handler.IpCameraHandler] - Sending camera: GET: http://<camera ip>:80/ISAPI/Streaming/channels/102/httppreview
23:30:19.291 [WARN ] [.ipcamera.internal.MyNettyAuthHandler] - 403 Forbidden: Check camera setup or has the camera activated the illegal login lock?
23:30:19.295 [TRACE] [ng.ipcamera.internal.HikvisionHandler] - HTTP Result back from camera is  :<?xml version="1.0" encoding="UTF-8"?>
<ResponseStatus version="2.0" xmlns="http://www.std-cgi.com/ver20/XMLSchema">
<requestURL>/ISAPI/Streaming/channels/102/httppreview</requestURL>
<statusCode>4</statusCode>
<statusString>Invalid Operation</statusString>
<subStatusCode>invalidOperation</subStatusCode>
</ResponseStatus>
:
23:30:20.969 [TRACE] [ng.ipcamera.internal.HikvisionHandler] - HTTP Result back from camera is  :--boundary
Content-Type: application/xml; charset="UTF-8"
Content-Length: 512

<EventNotificationAlert version="2.0" xmlns="http://www.std-cgi.com/ver20/XMLSchema">
<ipAddress>{camera ip}</ipAddress>
<portNo>80</portNo>
<protocol>HTTP</protocol>
<macAddress>10:12:fb:49:7e:7f</macAddress>
<channelID>1</channelID>
<dateTime>2023-01-04T23:20:16+01:00</dateTime>
<activePostCount>0</activePostCount>
<eventType>videoloss</eventType>
<eventState>inactive</eventState>
<eventDescription>videoloss alarm</eventDescription>
<channelName>Podjazd</channelName>
</EventNotificationAlert>
:

To make things more fun if I open it in the browser first and then in Openhab Android app it will work.

The illegal login lock option is disabled in camera.

What version of openhab and binding are you using?

1 Like

openHAB 3.2.0

The only binding version I could find is that its the same as openHAB version:

/var/lib/openhab/tmp/mvn/org/openhab/addons/bundles/org.openhab.binding.ipcamera/3.2.0/org.openhab.binding.ipcamera-3.2.0.jar
cat /var/lib/openhab/tmp/mvn/org/openhab/addons/bundles/org.openhab.binding.ipcamera/3.2.0/org.openhab.binding.ipcamera-3.2.0.jar.sha1
0461cbb07623d59dff9aca1aa9b33c1e803b6c5b

Ah, I see there were multiple fixes in 3.3

ipcamera Enhancements 11921 Fix multiple mjpeg issues and allow stream to stay alive
Bug Fixes 12399 Fix Digest bug and Doorbird fixes.
12814 Doorbird online/offline bug fix
12964 Fix multiple parts handling for Dahua events

Can I install this update without updating entire openHab?

Looks like it works after update. Thank you!

is there any possibilty to overwrite the -c:a parameter from copy to aac ?

y -t 10 -hide_banner -loglevel warning -c:a aac -i rtsp://:***@...:554/stream0/mobotix.mjpeg -c:v copy -c:a copy /openhab/userdata/ipcamera/cam_door/ipcamera.mp4

for the mobotix I need to convert the audio to aac for the mp4.generation

Is it expected for the binding to update the motionalarm item multiple times every second?

[2023-01-08 13:02:40,079] [          HABApp.EventBus]     INFO |   BS1_IPC1_Fe_Utside: <ItemStateEvent name: BS1_IPC1_Fe_Utside, value: OFF>
[2023-01-08 13:02:40,082] [          HABApp.EventBus]     INFO |   BS1_IPC1_Fe_Utside: <ItemStateEvent name: BS1_IPC1_Fe_Utside, value: OFF>
[2023-01-08 13:02:40,082] [          HABApp.EventBus]     INFO |   BS1_IPC1_Fe_Utside: <ItemStateEvent name: BS1_IPC1_Fe_Utside, value: OFF>
[2023-01-08 13:02:40,390] [          HABApp.EventBus]     INFO |   BS1_IPC1_Fe_Utside: <ItemStateEvent name: BS1_IPC1_Fe_Utside, value: OFF>
[2023-01-08 13:02:40,394] [          HABApp.EventBus]     INFO |   BS1_IPC1_Fe_Utside: <ItemStateEvent name: BS1_IPC1_Fe_Utside, value: OFF>
[2023-01-08 13:02:40,395] [          HABApp.EventBus]     INFO |   BS1_IPC1_Fe_Utside: <ItemStateEvent name: BS1_IPC1_Fe_Utside, value: OFF>
[2023-01-08 13:02:40,705] [          HABApp.EventBus]     INFO |   BS1_IPC1_Fe_Utside: <ItemStateEvent name: BS1_IPC1_Fe_Utside, value: OFF>
[2023-01-08 13:02:40,711] [          HABApp.EventBus]     INFO |   BS1_IPC1_Fe_Utside: <ItemStateEvent name: BS1_IPC1_Fe_Utside, value: OFF>
[2023-01-08 13:02:40,713] [          HABApp.EventBus]     INFO |   BS1_IPC1_Fe_Utside: <ItemStateEvent name: BS1_IPC1_Fe_Utside, value: OFF>

When you have multiple cameras it will be generating alot of load on the event bus …? :thinking:
Is it possible to tweak this somehow?
(This is a hikvision camera)

No, that would be a new feature request. You can change the ffmpeg options for GIF using the gifOutOptions config but not for the mp4 recordings.

Thats not normal. You have not given the basic info like camera model, openhab version etc. I would not be surprised if a firmware update for the camera or upgrading to a newer openHAB solves it for you.

What i did to make images work on my openhabcloud is to transform the image url from an absolute URL to an relative URL. This works on mainui widgets which open the image then relativly to their base URL (however you opened the UI).

To achieve this i set the Profile of the Image URL channel to “REGEX” with the following RegEx:

s/http\:\/\/192\.168\.xxx\.1[0-9][0-9]\:8080\//\//g

If the original image url was “http://192.168.xxx.123:8080/ipcamera/xxx/ipcamera.jpg” it should show now “/ipcamera/xxx/ipcamera.jpg”

(i can’t remember if i came up with this myself or someone posted this solution on this forum before if so credit to original)

Ok thanks, yeah I just wanted to check first. Heres the info I managed to gather:

Camera: Hikvision: DS-2DE3304W-DE (Fw: V5.4.8 build 170210) PTZ camera
Openhab: 3.4 Stable (fresh install)
Trace info (possibly event that seems to send the OFF command for motionalarm somehow?):

2023-01-09 22:15:33.220 [TRACE] [g.ipcamera.internal.HikvisionHandler] - HTTP Result back from camera is        :--boundary
Content-Type: application/xml; charset="UTF-8"
Content-Length: 479

<EventNotificationAlert version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<ipAddress>10.10.10.10</ipAddress>
<portNo>80</portNo>
<protocol>HTTP</protocol>
<macAddress>4c:bd:8f:f9:4f:61</macAddress>
<channelID>1</channelID>
<dateTime>2023-01-09T22:15:32+01:00</dateTime>
<activePostCount>0</activePostCount>
<eventType>videoloss</eventType>
<eventState>inactive</eventState>
<eventDescription>videoloss alarm</eventDescription>
</EventNotificationAlert>

This event is repeating itself continously, every 200-400ms or so.

Is that the newest firmware for the camera?

Probably not, its bought on Aliexpress but supposedly can be upgraded (english version, not multilang.) according to the ad. :laughing: Anywho if thats the problem i’ll try looking at upgrading it, just want to do that as a last resort so i dont brick it unnecessary

Took a leap of faith and upgraded to 5.5.2 and it instantly reduced the “spam” to every 10 seconds, now updates 3 times every 10 seconds but still…way better! :grinning:

That is the cause, so it is the firmware.

Thats very very old firmware from 2017 and its now 2023 so you should read this post and use the link to download the latest firmware. HIK has newer firmware, but they as a company are IMHO bad at updating the links to the firmware on a website so you need to download the firmware manually.

Hikvision cameras need urgent firmware update - Off-Topic - openHAB Community