IpCamera: New IP Camera Binding

hello people, I asked this in Sep but the problem is still here despite updates and testing

when i did the transition from 3.X to 4.0 i had some issues on logging etc which i corrected - but what seems to be consistently problematic is that my 20 cameras (RSTP) which are also displayed on habpanel/with the clickable widget (but this doesnt seem to be the issue) are causing memory issues / resources usage issues.

Basically, when i install the binding (having added ffmpeg) over time the memory as observed via system info binding decreases slowly. It eventaully reaches a point where the system hangs and i get alerts on resource errors/availability. Rules fail.

I tried uninstalling the binding and reinstalling
Removing the things and recreating them.

My current test incase it is a upgrade issue is that I just setup a clean install only with IPcamera to see if it is something else on the system and am waiting a few days. but first signs is that the memory is dropping by .1% every 1hour or so. I will leave it to see if it hangs

Has anyone had a similar experience?

thanks for your time!
@matt1

Dear all, i bought myself a Instar IN9008 FullHD camera and integrated it to Openhab today.
I installed ffmpeg on my RPI with Openhabian by sudo apt install ffmpeg showing now:

openhabian@openhabian:~ $ ffmpeg -version
ffmpeg version 4.3.6-0+deb11u1+rpt5 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 10 (Raspbian 10.2.1-6+rpi1)
configuration: --prefix=/usr --extra-version=0+deb11u1+rpt5 --toolchain=hardened --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-mmal --enable-neon --enable-rpi --enable-v4l2-request --enable-libudev --enable-epoxy --enable-pocketsphinx --enable-libdc1394 --enable-libdrm --enable-vout-drm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared --libdir=/usr/lib/arm-linux-gnueabihf --cpu=arm1176jzf-s --arch=arm
libavutil      56. 51.100 / 56. 51.100
libavcodec     58. 91.100 / 58. 91.100
libavformat    58. 45.100 / 58. 45.100
libavdevice    58. 10.100 / 58. 10.100
libavfilter     7. 85.100 /  7. 85.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  7.100 /  5.  7.100
libswresample   3.  7.100 /  3.  7.100
libpostproc    55.  7.100 / 55.  7.100

Under /usr/bin there is now a file called ffmpeg. I hope this is okay …

Then i configured the ip camera thing:

UID: ipcamera:instar:980dac2114
label: Instar Camera with API
thingTypeUID: ipcamera:instar
configuration:
  mjpegOptions: -q:v 5 -r 2 -vf scale=640:-2 -update 1
  ipAddress: 192.168.0.221
  updateImageWhen: "0"
  gifPreroll: 0
  onvifPort: 8080
  ffmpegLocation: /usr/bin/ffmpeg
  ipWhitelist: DISABLE
  mp4OutOptions: -c:v copy -c:a copy
  pollTime: 1000
  password: PASSWORD
  port: 80
  snapshotOptions: -an -vsync vfr -q:v 2 -update 1
  ptzContinuous: true
  onvifMediaProfile: 0
  username: USERNAME
  hlsOutOptions: -strict -2 -f lavfi -i aevalsrc=0 -acodec aac -vcodec copy
    -hls_flags delete_segments -hls_time 2 -hls_list_size 4
  gifOutOptions: -r 2 -filter_complex
    scale=-2:360:flags=lanczos,setpts=0.5*PTS,split[o1][o2];[o1]palettegen[p];[o2]fifo[o3];[o3][p]paletteuse

Now i am a little bit lost.
What i want to do is to have a PIR trigger and a video stream on a openhab page.
But channel Motion alarm stays OFF all the time. I have to PIR enabled in the web UI and its also triggering in mqtt. As a backup i can use the mqtt channel …
Then i put a item to MJPEG URL Image URL and HLS URL. They all have a URL now. MJPEG URL is showing a good stream in the browser, Image URL and image only. HSL URL wants to download something. Now i put the MJPEG item into a video card in a openhab page but the card shows No compatible source was found for this media. The Image Card Image URL is showing the camera image, i can set the refresh rate to 500 ms but below this the image does not refresh. Using the HLS URL in the video card is resulting in a very delayed video (~30sec). What is the best way to do this? Can someone give me a hint? (Sorry for the long text)

edit: Ok managed to fix it. There is another PIR channel which is working. And for the MJPEG i also have to use the image card :smiley:

I want to setup something like a event historie to show the last 3 motion triggered pictures / short videos in the UI. I managed to save the gif files on my raspberry pi with the date ans time as file name. Does someone know how to show them on a openhab page? I only do have the path and file name.

There is a widget in the marketplace for doing exactly that.

Hi, thank you for your answer. This sounds good. I checked all the widgets in the marketplace but didnt find something which may help for this. Which exactly do you mean?

I think me means this one…
https://community.openhab.org/t/camera-live-mjpeg-view-with-a-mp4-recording-history/147009
Greets

FFmpeg stopped to give snapshot for generica RTSP camera.
I have such an EZVIZ C6N that worked for months:

Thing ipcamera:generic:sala “Webcam Sala” @ “Webcams”
[ ipAddress=“192.168.1.85”,
snapshotUrl=“ffmpeg”,
ffmpegInput=“rtsp://192.168.1.85:554/H.264”,
ffmpegOutput=“/TMPDIR/ezviz/sala/”,
snapshotOptions=“-an -vsync vfr -q:v 2 -update 1”,
polltime = 2000,
password=“*******”,
username=“admin”
]
//
Now it stopped to display the snapshot in my sitemap
Image url=“http://mhw.int.fmal.com:8080/ipcamera/sala/ipcamera.jpg” refresh=2000

I traced the log

2023-11-30 21:19:36.282 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'Webcam.things'
2023-11-30 21:19:36.339 [DEBUG] [hab.binding.ipcamera.internal.Ffmpeg] - Stopping ffmpeg SNAPSHOT now when keepalive is:8
2023-11-30 21:19:40.361 [DEBUG] [era.internal.handler.IpCameraHandler] - Binding has no snapshot url. Will use your CPU and FFmpeg to create snapshots from the cameras RTSP.
2023-11-30 21:19:40.363 [DEBUG] [hab.binding.ipcamera.internal.Ffmpeg] - Starting ffmpeg with this command now:-rtsp_transport tcp -threads 1 -skip_frame nokey -hide_banner -i rtsp://admin:********@192.168.1.85:554/H.264 -an -vsync vfr -q:v 2 -update 1 http://127.0.0.1:8080/ipcamera/sala/snapshot.jpg
2023-11-30 21:19:45.972 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - [rtsp @ 0x12369c0] decoding for stream 0 failed
2023-11-30 21:19:45.974 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - Input #0, rtsp, from 'rtsp://admin:WOAKEU@192.168.1.85:554/H.264':
2023-11-30 21:19:45.975 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] -   Metadata:
2023-11-30 21:19:45.976 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] -     title           : Media Presentation
2023-11-30 21:19:45.977 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] -   Duration: N/A, start: 144899.397000, bitrate: N/A
2023-11-30 21:19:45.977 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] -     Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 1920x1080, 12 fps, 12 tbr, 90k tbn, 24 tbc
2023-11-30 21:19:45.978 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] -     Stream #0:1: Audio: aac (LC), 16000 Hz, mono, fltp
2023-11-30 21:19:45.979 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - Stream mapping:
2023-11-30 21:19:45.979 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] -   Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
2023-11-30 21:19:45.980 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - Press [q] to stop, [?] for help
2023-11-30 21:19:46.067 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - Output #0, image2, to 'http://127.0.0.1:8080/ipcamera/sala/snapshot.jpg':
2023-11-30 21:19:46.067 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] -   Metadata:
2023-11-30 21:19:46.068 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] -     title           : Media Presentation
2023-11-30 21:19:46.069 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] -     encoder         : Lavf58.45.100
2023-11-30 21:19:46.069 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] -     Stream #0:0: Video: mjpeg, yuvj420p(pc), 1920x1080, q=2-31, 200 kb/s, 12 fps, 12 tbn, 12 tbc
2023-11-30 21:19:46.070 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] -     Metadata:
2023-11-30 21:19:46.070 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] -       encoder         : Lavc58.91.100 mjpeg
2023-11-30 21:19:46.071 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] -     Side data:
2023-11-30 21:19:46.072 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] -       cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
2023-11-30 21:19:46.552 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - frame=    0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A dup=0 drop=1 speed=   0x
2023-11-30 21:19:47.094 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - frame=    0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A dup=0 drop=1 speed=   0x
2023-11-30 21:19:47.631 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - frame=    0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A dup=0 drop=1 speed=   0x
2023-11-30 21:19:48.175 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - frame=    0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A dup=0 drop=1 speed=   0x
2023-11-30 21:19:48.676 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - frame=    0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A dup=0 drop=1 speed=   0x
2023-11-30 21:19:49.158 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - frame=    0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A dup=0 drop=1 speed=   0x
2023-11-30 21:19:49.673 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - frame=    0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A dup=0 drop=1 speed=   0x
2023-11-30 21:19:50.226 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - frame=    0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A dup=0 drop=1 speed=   0x
2023-11-30 21:19:50.768 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - frame=    0 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A dup=0 drop=2 speed=   0x
2023-11-30 21:19:51.263 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - frame=    0 fps=0.0 q=0.0

It looks as noting is captured from ffmpeg…
TY for advices

More testing. I see two ffmpeg processes active, one for mjpeg stream when I watch the Video, and one for the snapshot, always active, but I have no snapshot defined in things file:

Thing ipcamera:generic:sala "Webcam Sala" @ "Webcams"
        [       ipAddress="192.168.1.85",
                ipWhitelist="(127.0.0.1)(192.168.1.11)",
                mjpegUrl="ffmpeg",
                ffmpegOutput="/TMPDIR/sala/",
                ffmpegInput="rtsp://192.168.1.85/H.264",
                mjpegOptions="-q:v 5 -r 2 -vf scale=640:-2 -update 1",
                snapshotUrl="",
                snapshotOptions="",
                password="*****",
                username="admin"
        ]

 # ps -ef | grep ffm
openhab  20122 14907  1 10:14 ?        00:00:11 /usr/bin/ffmpeg -rtsp_transport tcp -threads 1 -skip_frame nokey -hide_banner -i rtsp://admin:******@192.168.1.85/H.264 http://127.0.0.1:8080/ipcamera/sala/snapshot.jpg
openhab  22546 14907 20 10:23 ?        00:00:32 /usr/bin/ffmpeg -rtsp_transport tcp -hide_banner -i rtsp://admin:******@192.168.1.85/H.264 -q:v 5 -r 2 -vf scale=640:-2 -update 1 http://127.0.0.1:8080/ipcamera/sala/ipcamera.jpg

Hi there :slight_smile:
I got a new INSTAR camera 9420 - which is the successor of the 9020.

Now I am facing an issue with sending ONVIF commands.
With 9020 camera the ONVIF commands for PTZ control were working - the same commands with camera 9420 are showing the following error (ipcamera binding trace log level):

Camera did not report any ONVIF preset locations, updating preset tokens now.
IndexOutOfBoundsException occured, Index: 1, Size: 0
ONVIF reply is: <?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s=„http://www.w3.org/2003/05/soap-envelope“ xmlns:tt=„http://www.onvif.org/ver10/schema“ xmlns:ter=„http://www.onvif.org/ver10/error“><s:Body><s:Fault><s:Code><s:Value>s:Sender</s:Value><s:Subcode><s:Value>ter:UnknownAction</s:Value></s:Subcode></s:Code><s:Reason><s:Text xml:lang=„en“>Unknown Action</s:Text></s:Reason><s:Node>http://www.w3.org/2003/05/soap-envelope/node/ultimateReceiver</s:Node><s:Role>http://www.w3.org/2003/05/soap-envelope/node/ultimateReceiver</s:Role><s:Detail><s:Text>An unknown Action is specified</s:Text></s:Detail></s:Fault></s:Body></s:Envelope>

Is this something related to new ONVIF T-Profile?
Is this already implemented into openHAB binding?

Any ideas, why ONVIF commands are not working anymore are highly appreciated.
regards, Kai

EDIT: running on OH4.1M3 and since today OH4.1

Short answer is I suspect that yes this is the reason.

I did take a look 12 months ago and came to the conclusion that the binding probably would work if SSL support was added, or if the camera allowed non SSL communications. The only downside to not having SSL support, was that the PTZ features would not work, so it was a low priority to look into as I did not know of any cameras that had PTZ with only Profile T and requires SSL. It is possible for a camera to support both Profile S and Profile T at the same time. They appear to be same/similar as T is a more secure version of S. The binding already does the DIGEST auth method that Profile T mandates, so the only known issue is the missing SSL support. I course I can not be 100% sure of this as you have only post a single line of the trace logs from when the camera first connects to ONVIF it may give more info then.

Also there are 3 to 4 different ways to move a PTZ camera, it’s possible one of the other methods will work, however if the camera does not response that it supports PTZ the channels may get removed so you can not use them. The handshake trace logs would show more info and if this was the case.

Is it possible to move the camera using the MQTT methods? Just be sure to use the MQTT ports for SSL when setting up the camera as it is likely it only supports SSL to the MQTT broker as well.

1 Like

Thanks for your detailled answer!
I do have the debug-level log file availabe and will send it via PM to you - I don’t want to spam the forum here with long logfiles…

The cam does support ONVIF and ONVIF (SSL) on two different ports. I changed in OH to the SSL-port but this didn’t change anything.

And because I don’t have a MQTT broker yet, I cannot test MQTT yet :innocent:
I will think about testing MQTT…

Happy Christmas!

The binding does not support SSL so if the logs you sent were from the SSL port of the camera that is why they held no replies. There is also ways to move the camera using the Api methods if you do not have MQTT setup.

the log file contained two logs: the first part was ONVIF without SSL, the second part ONVIF with SSL.

Anyhow - your idea using other method worked for me :slight_smile:
I used cgi command to send command for PTZ movement.
INSTAR Cams can moved with e.g.:

sendHttpGetRequest("http://user:password@CAM_IP/param.cgi?cmd=ptzpreset&act=goto&index=1", 100)  // Move camera to PTZ Preset 1

Same result :smiley:
Thanks for the idea @matt1 to consider alternative to ONVIF :ok_hand:

1 Like

@matt1 thank you very much for this great binding. It works flawlessly. I know I asked already two/three years ago but would it not be great to have an another chanel like GotoPreset, a SetPreset? I think a lot of cameras use it to save PTZ positions, motion tracking on/off etc. All these outdated apps from the vendors would become obsolete if you can make little changes in openhab. Today I am using a python onvif commandline tool to execute this task in openhab. I would like to help you but I am not a programmer.

I think the ruling is that if a channel does not have a state, then it should be implemented as an ACTION. Channels need to have a state.

An action would allow a name for the preset to be specified. Something like createPreset(name Of Preset)

This is where a github issue for a suggestion is best. Multiple people may see it and implement it.

I don’t know how much easier it would make it as you probably need to create a rule to use the action when you fill in a string input. Unlike channels you don’t get the items automatically setup for you unless I am not up to speed which happens often.

For some special things with my Reolink cameras I use http api calls… Tracking on/off, ptz calibration, set Led light on/off…
Greets…

Hi everyone. I’m trying to integrate the following IP camera into Openhab:

Brand: Imou
Model: IPC-B32-V2

it is a battery powered model
I use Openhab version 4.1.0 on Raspberry Pi 4 with the OS installed Openahabian.
The camera does not support ONVIF protocol. Since IMOU is a sub-brand of DAHUA, I referred to the documentation relating to the latter’s REST APIs. Where the following URL for streaming via rtsp is indicated:

rtsp://username:password@ip:port/cam/realmonitor?channel=1&subtype=0

I then configured my things in the following way:

Thing ipcamera:generic:imou-ipc-b32v
[
    ipAddress="192.168.1.188",
    ffmpegInput="rtsp://admin:<pwd>@192.168.1.188:554/cam/realmonitor?channel=1&subtype=0"
]

However, the binding doesn’t work. This is the log:

==> /var/log/openhab/openhab.log <==
2024-01-05 01:06:16.672 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - [tcp @ 0x1357d30] Connection to tcp://192.168.1.188:554?timeout=0 failed: No route to host
2024-01-05 01:06:16.673 [TRACE] [hab.binding.ipcamera.internal.Ffmpeg] - rtsp://admin:L249B2A8@192.168.1.188:554/cam/realmonitor?channel=1&subtype=0: No route to host
2024-01-05 01:06:22.004 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'ipcamera:generic:imou-ipc-b32v' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): FFmpeg Snapshots Stopped: Check that your camera can be reached.
2024-01-05 01:06:26.002 [DEBUG] [era.internal.handler.IpCameraHandler] - Binding has no snapshot url. Will use your CPU and FFmpeg to create snapshots from the cameras RTSP.
2024-01-05 01:06:26.005 [DEBUG] [hab.binding.ipcamera.internal.Ffmpeg] - Starting ffmpeg with this command now: -rtsp_transport tcp -threads 1 -skip_frame nokey -hide_banner -i rtsp://admin:L249B2A8@192.168.1.188:554/cam/realmonitor?channel=1&subtype=0 -an -vsync vfr -q:v 2 -update 1 http://127.0.0.1:8080/ipcamera/imou-ipc-b32v/snapshot.jpg
==> /var/log/openhab/events.log <==
2024-01-05 01:06:26.006 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'ipcamera:generic:imou-ipc-b32v' changed from OFFLINE (COMMUNICATION_ERROR): FFmpeg Snapshots Stopped: Check that your camera can be reached. to ONLINE

I would like to add that the IP Camera works correctly from the Imou app and that it is possible to ping it from the Openhabian console. Any kind of help will be appreciated.

Thank you

I don’t think that a battery powered camera is a good choice with ffmpeg.
If it works it will empty your battery…
AFAIK connects battery powered cameras only to the stream if nessescery.
Greets.

For me it would be enough to stream for a few seconds or at most take a photo, as I can already do via the application

I took a quick look into Imou and found that you can use them via ONVIF, but your reporting your battery powered model does not have ONVIF support. This means you would have to control and communicate with them via their cloud based API.

There is a python library here

Possibly you could use wireshark to spy on the network traffic from the app and see if there are any local calls being made, but I suspect they are all routed via their cloud so it will work when your not on your home wifi.