IpCamera: New IP Camera Binding

Yes not surprised as it will kill the ffmpeg that is fetching snapshots. If you use the snapshots.mjpeg it will probably work as you want. This area needs a tidy up by creating a new channel that makes sense, so expect a breaking change when it is done. A github issue is already open on it. Would you prefer two new channels added? One to stop the snapshots and the other for ipcamera.mjpeg?

edit:
@yfaway

That config should not change anything in relation to ffmpeg, leave it on default.

Yes it only fires up on demand when you open a stream with ipcamera.mjpeg and auto stops when it is not needed anymore. It is the snapshots that occur all the time unless you stop them with that channel.

I would think that a single channel makes more sense, as this specifically targets the spawn of ffmpeg. I would also suggest that if polImage is off than accessing all streaming or snapshot URL should generate an error. This shouldn’t affect existing users as most of them would unlikely set pollImage to off. If this is not done, pollImage would not be useful as the existence of a Video tag in the sitemap would spawn ffmpeg (even if its visibility is linked to the pollImage state).

What do you think about that?

Hi,

I’m wondering if channel for RTSP URL for reolink camers instead returning rtsp://IPNUMBER:PORT/ should return: rtsp://admin:PASSWORD@IPNUMBER:PORT/

Help! I have many http camera and they work well. Since two years I tried to have a RTSP camera and never I was able to have it working (crashes, loop, cpu stressed).
First attempt with an EZVIZ C6N that after firmware updates stopped to work in RTSP.
Now I try a cheap d-link DCS-6100HL and I’m becoming mad. I do not find any example about the config, and I’m reading a lot of posts, but I cannot figure how to have it working. The problem is that I always have two ffmpeg processes, one for the stream and one for the snapshot. The stream (or the snapshot) forw for a while, but soon I must restart openhab because the stream is freezed.
I’m sure that I miss osmething important in my configuration, because all the other 5 cameras (all http-only) are working perfectly:
This is my thing file

Thing ipcamera:generic:divano “Webcam Sala” @ “Webcams”
[ ipAddress=“192.168.1.87”,
updateImageWhen=0,
ipWhitelist=“DISABLE”,
snapshotUrl=“”,
mjpegUrl=“ffmpeg”,
password=“******”,
username=“admin”,
ffmpegInput=“rtsp://192.168.1.87:554/live/profile.0/video”,
ffmpegOutput=“/TMPDIR/divano/”
]
//

And these are the two ffmpeg processes I have:

root@mhw:/etc/openhab # ps -ef | grep ffm
openhab    900 29658 16 15:20 ?        00:00:03 /usr/bin/ffmpeg -rtsp_transport tcp -threads 1 -skip_frame nokey -hide_banner -i rtsp://admin:517764@192.168.1.87:554/live/profile.0/video -an -vsync vfr -q:v 2 -update 1 http://127.0.0.1:8080/ipcamera/divano/snapshot.jpg
openhab    994 29658 56 15:20 ?        00:00:05 /usr/bin/ffmpeg -rtsp_transport tcp -hide_banner -i rtsp://admin:517764@192.168.1.87:554/live/profile.0/video -q:v 5 -r 2 -vf scale=640:-2 -update 1 http://127.0.0.1:8080/ipcamera/divano/ipcamera.jpg

Hi @matt1,
I have a question about the MP4_recording timer.
I start my records with

getActions("ipcamera", thingid).recordMP4(name,20)

Then the MP4_recording timer is set to 20 seconds.
But the end of the timer is very variable. See below… How do you set the timer?
I need the finish of the record to do some ffmpeg converts…

2024-03-31 19:59:18 ReolinkRLC410WKeller_MotionAlarm changed to ON
2024-03-31 19:59:18 ReolinkRLC410WKeller_MP4_Recording changed to 20
2024-03-31 19:59:20 ReolinkRLC410WKeller_MotionAlarm changed to OFF
2024-03-31 19:59:43 ReolinkRLC410WKeller_MP4_Recording changed to 0
2024-03-31 20:04:44 ReolinkRLC410WKeller_MotionAlarm changed to ON
2024-03-31 20:04:44 ReolinkRLC410WKeller_MP4_Recording changed to 20
2024-03-31 20:04:45 ReolinkRLC410WKeller_MotionAlarm changed to OFF
2024-03-31 20:05:21 ReolinkRLC410WKeller_MP4_Recording changed to 0
2024-03-31 20:31:33 ReolinkRLC410WKeller_MotionAlarm changed to ON
2024-03-31 20:31:33 ReolinkRLC410WKeller_MP4_Recording changed to 20
2024-03-31 20:31:34 ReolinkRLC410WKeller_MotionAlarm changed to OFF
2024-03-31 20:31:58 ReolinkRLC410WKeller_MP4_Recording changed to 0

You can see the ffmpeg command that is used in the debug level log. Ffmpeg gets told how long to record for and it handles it, so your best to use Google and search using ffmpeg in your search term and read what is said that matches your symptoms. You could also try the command in a terminal and see what ffmpeg is telling you, it may be your cameras is using a variable frame rate or something that ffmpeg is not setup or detecting and it may be giving you hints. Not a lot to go on sorry.

Edit, if you mean the recording is correct and it is only the state of the channel you questioning I believe it just sets the state when the command terminates. I guess it could be varying if your camera drops out and does not provide the frames. Make sure the camera is using tcp and not udp for the stream.

Yes, the recording is correct and it’s 20 seconds long…
I tried and the mp4 recording timer resets to 0 when the ffmpeg process is finished… So it takes around double the time as the recording is…
Thx and Greets…

Edit: with another camera it last 5 seconds longer… (25 seconds till timer is 0)
With third camera it lasts 28 seconds…
I need to find out what’s going on here…
the settings are almost the same…

My guess is it has something to do with ffmpeg needing to convert the cameras format into what you are asking it to do with the ffmpeg command. Sounds like it is not a bug, just ffmpeg taking longer to close due to x reason.

I am using OH 4.1 with the IPcamera binding. Everything is working except the Motion Detection with the Foscam C5M camera. When enabling the channel “Enable Motion Alarm” it goes back automatically after about 5s and I have no idea why?!

When reading the CGI I get following output:

<CGI_Result>
    <result>0</result>
    <isEnable>1</isEnable>
    <linkage>0</linkage>
    <snapInterval>0</snapInterval>
    <sensitivity>0</sensitivity>
    <triggerInterval>0</triggerInterval>
    <isMovAlarmEnable>1</isMovAlarmEnable>
    <isPirAlarmEnable>0</isPirAlarmEnable>
    <schedule0>0</schedule0>
    <schedule1>0</schedule1>
    <schedule2>0</schedule2>
    <schedule3>0</schedule3>
    <schedule4>0</schedule4>
    <schedule5>0</schedule5>
    <schedule6>0</schedule6>
    <area0>0</area0>
    <area1>0</area1>
    <area2>0</area2>
    <area3>0</area3>
    <area4>0</area4>
    <area5>0</area5>
    <area6>0</area6>
    <area7>0</area7>
    <area8>0</area8>
    <area9>0</area9>
    <humanEnable>1</humanEnable>
    <carEnable>0</carEnable>
    <petEnable>0</petEnable>
    <crossLineEnable>0</crossLineEnable>
    <OnlyDtPed>0</OnlyDtPed>
    <isEnableLine0>0</isEnableLine0>
    <line0Direction>0</line0Direction>
    <line0StartX>0</line0StartX>
    <line0StartY>0</line0StartY>
    <line0EndX>0</line0EndX>
    <line0EndY>0</line0EndY>
    <isEnableLine1>0</isEnableLine1>
    <line1Direction>0</line1Direction>
    <line1StartX>0</line1StartX>
    <line1StartY>0</line1StartY>
    <line1EndX>0</line1EndX>
    <line1EndY>0</line1EndY>
    <isEnableLine2>0</isEnableLine2>
    <line2Direction>0</line2Direction>
    <line2StartX>0</line2StartX>
    <line2StartY>0</line2StartY>
    <line2EndX>0</line2EndX>
    <line2EndY>0</line2EndY>
    <isEnableLine3>0</isEnableLine3>
    <line3Direction>0</line3Direction>
    <line3StartX>0</line3StartX>
    <line3StartY>0</line3StartY>
    <line3EndX>0</line3EndX>
    <line3EndY>0</line3EndY>
</CGI_Result>

In the event log I see:

Item 'IP_Kamera_OG__Foscam_Camera_with_API_Enable_Motion_Alarm' updated to OFF
Item 'IP_Kamera_OG__Foscam_Camera_with_API_LED_Controls' updated to 0

Here I see “1”. So what I am doing wrong here? Do I need to update something or.? Please help

Thank you

@matt1
I have started to get some problems with the alarmstream, it does not work any longer.

2024-04-09 09:05:31.029 [WARN ] [netty.channel.DefaultChannelPipeline] - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
        at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) ~[?:?]
        at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) ~[?:?]
        at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266) ~[?:?]
        at java.util.Objects.checkIndex(Objects.java:361) ~[?:?]
        at java.util.ArrayList.set(ArrayList.java:441) ~[?:?]
        at org.openhab.binding.ipcamera.internal.HikvisionHandler.channelRead(HikvisionHandler.java:181) ~[?:?]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) [bundleFile:4.1.104.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) [bundleFile:4.1.104.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) [bundleFile:4.1.104.Final]
        at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93) [bundleFile:4.1.104.Final]
        at org.openhab.binding.ipcamera.internal.handler.IpCameraHandler$CommonCameraHandler.channelRead(IpCameraHandler.java:297) [bundleFile:?]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) [bundleFile:4.1.104.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) [bundleFile:4.1.104.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) [bundleFile:4.1.104.Final]
        at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93) [bundleFile:4.1.104.Final]
        at org.openhab.binding.ipcamera.internal.MyNettyAuthHandler.channelRead(MyNettyAuthHandler.java:182) [bundleFile:?]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) [bundleFile:4.1.104.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) [bundleFile:4.1.104.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) [bundleFile:4.1.104.Final]
        at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) [bundleFile:4.1.104.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) [bundleFile:4.1.104.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318) [bundleFile:4.1.104.Final]
        at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) [bundleFile:4.1.104.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) [bundleFile:4.1.104.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) [bundleFile:4.1.104.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) [bundleFile:4.1.104.Final]
        at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) [bundleFile:4.1.104.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) [bundleFile:4.1.104.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) [bundleFile:4.1.104.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) [bundleFile:4.1.104.Final]
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) [bundleFile:4.1.104.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) [bundleFile:4.1.104.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) [bundleFile:4.1.104.Final]
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) [bundleFile:4.1.104.Final]
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) [bundleFile:4.1.104.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) [bundleFile:4.1.104.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) [bundleFile:4.1.104.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) [bundleFile:4.1.104.Final]
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) [bundleFile:4.1.104.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) [bundleFile:4.1.104.Final]
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [bundleFile:4.1.104.Final]
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [bundleFile:4.1.104.Final]
        at java.lang.Thread.run(Thread.java:840) [?:?]

This is my things

Thing ipcamera:hikvision:front "Front Camera" @ "Cameras"
[
    ipAddress="192.168.192.82", password="X",
    username="admin",
    serverPort=50001,
    ffmpegOutput="/tmpfs/front/",
    ffmpegInput="rtsp://admin:X@192.168.192.82/Streaming/channels/102",
	  hlsOutOptions="-strict -2 -acodec aac -vcodec copy -hls_flags delete_segments -hls_time 1 -hls_list_size 4"
//"-acodec aac -vcodec copy -hls_flags delete_segments"
]
Thing ipcamera:hikvision:pool "Pool Camera" @ "Cameras"
[
    ipAddress="192.168.192.86", password="X",
    username="admin",
    serverPort=50002,
    ffmpegOutput="/tmpfs/pool/",
	  ffmpegInput="rtsp://admin:X@192.168.192.86/Streaming/channels/102",
	  hlsOutOptions="-strict -2 -acodec aac -vcodec copy -hls_flags delete_segments -hls_time 1 -hls_list_size 4"
]
Thing ipcamera:hikvision:terrace "Terrace Camera" @ "Cameras"
[
    ipAddress="192.168.192.84", password="X",
    username="admin",
    serverPort=50003,
    ffmpegOutput="/tmpfs/terrace/",
	  ffmpegInput="rtsp://admin:X@192.168.192.84/Streaming/channels/101",
	  hlsOutOptions="-strict -2 -acodec aac -vcodec copy -hls_flags delete_segments -hls_time 1 -hls_list_size 4"
]
 Thing ipcamera:group:OutsideCameras "Group Display" @ "Cameras"
[
    pollTime=2000, serverPort=50000, 
    ffmpegOutput="/tmpfs/OutsideGroup/",
    firstCamera="front",
    secondCamera="pool",
    thirdCamera="",
    forthCamera="",
    motionChangesOrder=true
]

Log before exception

2024-04-09 09:34:53.962 [TRACE] [g.ipcamera.internal.HikvisionHandler] - HTTP Result from /ISAPI/System/IO/capabilities contains        :<?xml version="1.0" encoding="UTF-8"?>
<IOCap  version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<IOInputPortNums>1</IOInputPortNums>
<IOOutputPortNums>1</IOOutputPortNums>
<isSupportStrobeLamp>false</isSupportStrobeLamp>
</IOCap>
:
2024-04-09 09:34:53.962 [WARN ] [netty.channel.DefaultChannelPipeline] - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0

and that gives

2024-04-09 09:30:24.478 [TRACE] [g.ipcamera.internal.HikvisionHandler] - HTTP Result from /ISAPI/Event/notification/alertStream contains        :--boundary
Content-Type: application/xml; charset="UTF-8"
Content-Length: 539

<EventNotificationAlert version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<ipAddress>192.168.192.82</ipAddress>
<portNo>80</portNo>
<protocol>HTTP</protocol>
<macAddress>a4:14:37:6e:94:28</macAddress>
<channelID>1</channelID>
<dateTime>2024-04-09T09:30:24+01:00</dateTime>
<activePostCount>22</activePostCount>
<eventType>IO</eventType>
<eventState>active</eventState>
<eventDescription>IO alarm</eventDescription>
<inputIOPortID>1</inputIOPortID>
<channelName>Camera 01</channelName>
</EventNotificationAlert>
:
2024-04-09 09:30:24.478 [DEBUG] [g.ipcamera.internal.HikvisionHandler] - Unrecognised Hikvision eventType=IO

Thank you for reporting this. I have found and fixed the bug (thank you the info you provided made it quick and easy to find) and will upload a new build with today’s date on the zip file here once I have made some changes to it for another user having issues. Should be in a few hours time so wait till the ZIP with today’s date gets uploaded.

http://pcmus.com/openhab/IpCameraBinding/

1 Like

Now it is working.

Hi @matt1, I have a question.
How can I see the ffmpeg log?
in trace log is see only

Starting ffmpeg with this command now: -hide_banner -loglevel warning -rtsp_transport tcp -i rtsp://ad...... 

but if it ended with error I don’t see the error.
how can I log the ffmpeg output?
Greets

First of all thank you for this great binding matt1.
I have still some problems with my Hikvision Cameras DS-2CD2346G2P-ISU/SL regarding switching on and off the field alarm or line crossing alarm during i´m home in openhab binding.
I have read the comments in the middle of the posts how to setup the user in hikvision setup but it is not working. Can someone help me out how to setup this in hikvision setup?
Maybe other users are also happy for this step by step setup.

  1. I have activated under “Integration protocol” ONVIF and activated Digest &ws username token in the hikvision setup.
  2. I added a user “xyz” as a role/user type “Betreiber/user”
  3. I added password and ticked all relevant items in the popup menu
  4. failed security logins are ticked off in hikvision setup
  5. I added in openhab binding the user “xyz” with the given passwd under onvif user.

Problem is that the camera is not switching on or off the alarm through openhab binding.
If field alarm happens open hab is showing this correctly under field detection alarm.
Also under hikvision setup the tick box is not following the switch under openhab if im setting the field alarm to on/off.

Maybe someone can give me a hint.
Thank you in advance.

log after on/off command:
11:15:54.943 [WARN ] [.ipcamera.internal.MyNettyAuthHandler] - 403 Forbidden: Check camera setup or has the camera activated the illegal login lock?