How to display RTSP streams from IP Cameras in Openhab and Habpanel (Linux only)

I have it working with my Hikvision cameras, when they have basic authentication allowed in the cameras settings…

To use the main stream if you lower the framerate down to 12 or less and use 1080p the arm processor can handle it. Better method is to use the substream which is outlined below so the main stream can stay in high res.

ffmpeg -rtsp_transport tcp -i 'rtsp://admin:password@192.168.1.2:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1' http://127.0.0.1:8090/camera1.ffm

I did some CPU load tests to compare as the settings for the main video profile effect the CPU load of the Openhab server. These were running on an Odroid C2 ARM64 based setup, any modern x86 system would have far better performance.

Test results of using a camera via different methods.

No video streamed = 8% CPU load
30fps 640*480 MJPEG created by the camera and streamed via Habpanel no ffmpeg involved = 12% Cpu load (Asks for user/pass)
6FPS 640*480 MJPEG converted with ffmpeg to 6fps 640x360 MJPEG = 17% CPU load when open in Habpanel.
6fps 1080p H264 converted with ffmpeg to 6fps 640x360 MJPEG = 24% CPU load when open in Habpanel.
12fps 1080p H264 converted with ffmpeg to 6fps 640x360 MJPEG = 33% CPU load when open in Habpanel.

So it is possible to keep the main stream for high res and to configure the substream to MJPEG format by the camera. To then use this substream as the source which saves CPU power I used this line…

Hikvision substream rtsp feed.

ffmpeg -rtsp_transport tcp -i 'rtsp://admin:password@192.168.1.2:554/Streaming/Channels/102?transportmode=unicast&profile=Profile_1' http://127.0.0.1:8090/camera1.ffm

I could not work out a way that worked to place the stream direct from the camera to Habpanel, my conclusion is that basic auth does not work (or has a compat/bug) in the habpanel frame widget hence why using the above method works as it (ffmpeg) strips off the authentication. By processing an incoming MJPEG stream the CPU load was minimal compared to trying it on a high res high frame rate source.

EDIT: Simply entering this into the habpanel frame widget gives the picture without any user or password prompt. It fails to work if the same URL is used with admin:pass@ in the correct place. At first I thought this was a bug with the cameras firmware but then I found this. Since I was logged on via another chrome tab the credentials were passed across and this article explains it in more detail…

Hikvision direct camera semi working link (if you save user and password in the browsers cache when asked) then you need to hit refresh a few times on my tablet before the picture finally displays. Via ffmpeg it works every time and if using the cameras MJPEG stream to start from the CPU load is minimal.

http://192.168.0.2/ISAPI/Streaming/channels/102/httppreview