IpCamera: New IP Camera Binding

So the binding does properties read only at initialization stage and never-ever tries to re-read them? Think there must be some kind of very rare poll - like once an hour, just in case the camera will change it’s settings after reboot or firmware update (Dahua cameras do like to reboot, there is an “Auto-maintain” option for this).
Another question regarding adding additional channels to binding - they could be grouped, then the look like that:


But in this case IpcameraHandler must use getIdWithoutGroup instead of getId for channels, which will add 1 step to every call - Channel ID will be parsed to remove group from ID, or binding constants rework. Should I address this issue, or you don’t care?

Yes that is how the openHAB framework works, you could suggest it be changed to accept a hostname then all bindings can take advantage of the change. My own opinion is that it is better to display all the possible choices and a user selects one to eliminate any typo errors that users make and then blame us for. If you are going to suggest the change be made, you should explain why you NEED this, vs it is a LIKE to have feature that is not needed to get the job done.

People that code do not always think of every use case and NEED, this is why it needs to be outlined even if it seems obvious to yourself.

You should discuss this in its own thread and not connect it to this binding if you want more users to comment and join in.

Do you mind stating if you’re looking at making changes to the binding and submitting your changes to the project? I do not want to go in depth if a simple answer is all you need.

That is hard to answer as each brand can and is handled differently. Instar will send 1 request every 8 seconds and cycle through a list checking if a control has changed. This means it takes 50 seconds or more to get around all controls and update them. I do not like this approach of polling and am looking at removing this at the moment, as many users prefer the network traffic to be kept at a bare minimum at all times.
The goal is to only send the requests at init. and then you can trigger a REFRESH by sending that as a command to some of the channels and the binding will fetch and update the status of the control. You then get to choose how often it updates, or if it never does if you do not want the extra traffic. You can add a rule that sends this once an hour if you wish, that is up to you and it keeps the http traffic low. Not all channels have that implemented, so if you want one then you can request it gets added in a github issue and that is simple and quick to do.
Some parts of the binding I have not checked in a long time and there are parts that are in need of updating and improving to make it more readable and easier to maintain, this area is one that needs a fresh look for sure.

I like that, is that something that you can do and contribute? I am looking at trying to automate the removal of channels that the cameras do not support so the list of channels is smaller and less confusing.

I do not understand this issue you have raised as I do not know how everything works in the framework, sounds like you know it better then me. I am happy for you to make a choice and submit a change. If it has a chance of breaking something then it would need to be merged after the next stable build is made in a few weeks time.

Since last updates of OH I am observing that ffmpeg process is constantly working in the backgroud. When OH starts it is not running. But after first view of any camera thas uses ffmpeg it is running in the backgroud. Even when I try to kill it it is restarted. And it is using lot of CPU. In earlier versions ffmpeg process was exited (stopped/terminated) when camera preview was closed or browser tab with OH was closed.
Was something changed? Am I missing something? Is it by design now?

edit:
I think this change came with 13896

Hi,

I have a dahua NVR. Is it possible to connect to it remotely (over internet) using this binding?

I need more info, what do you open that starts ffmpeg? Is it ipcamera.mjpeg or something else if so what exactly? Also the json code on how your camera is setup would be helpful to reproduce the same settings. Lastly what version did you upgrade from?

You need to read the docs on openhab and remote access. This binding just let’s openhab use cameras, other methods are then used to do remote access.

Yes it is ipcamera.mjpeg. It is foscam camera just for streaming the video. It is configured in text file:

Thing ipcamera:foscam:001 [
    ipAddress="192.168.0.138",
    password="PASSWORD",
    username="USERNAME",
    port=88,
    onvifPort=8885,
    pollTime=2000,
    updateImageWhen="0",
    snapshotUrl="http://192.168.0.138:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture&usr=USERNAME&pwd=PASSWORD",
    mjpegUrl="ffmpeg",
    mjpegOptions="-q:v 8 -r 5 -vf scale=1024:-2 -update 1",
    ffmpegOutput="/tmpfs/foscam/",
    ffmpegInput="rtsp://USERNAME:PASSWORD@192.168.0.138:88/videoSub",
    ipWhitelist="DISABLE",
    ptzContinuous="TRUE"
]

I am on Milestone build so lately it was upgraded to MIlestone 5 and 6 and finally to openHAB 3.4.0 - Release Build

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