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

Can u please help me with ffmpeg & ffsever installation instructions. I tried various options but no luck .
I have raspberry pi 3b + with us boot for this setup and pi 3b for openhab

Please provide procedure or link on how to do it.

@JackNJack and @sujitrp
The instructions are in the first post of this thread, however I never bothered to write a guide on how to autostart it as I was planing what I will recommend you do instead. The Ipcamera Binding can now do ffmpeg conversions and serve the files. This works on all platforms not just Linux and is easier to setup. See the readme file for the binding.

1 Like

Thanks @matt1 for detailing this! I have 5 Dahua cams (6 m/pix each) to setup on my openhab panel.

1 Like

Hi Matt

Does this make use of Intel Quick Sync hardware decoding for H264/H265? Thx

@dastrix80
ffmpeg does use Quick Sync as well as many other forms of de/encoding. See their website for info on this… Most of the things that the ipcamera binding does not encode it only transforms the cameras packets into another package so it does not use much CPU. But if you are using this method in this thread to convert h264 into mjpeg then hardware de/encoding will help.

@OpenHabitat
if you have dahua then make sure you use the IpCamera binding by searching this forum as it give you the smart alarms and more…

IpCamera: New IP Camera Binding

Hi Matt

Cool. Wanting to display a number of streams in a widget without destroying the CPU of the OH2 box. Ill give it a go!

Im using your binding already to display a number of streams but its the older version without the ffmpeg

H264 turns into HLS streams with low cpu so try that format. Works great on apple browsers and app and it can work in other browsers if you google how to install a plugin for your browser. For cameras that only give low res mjpeg streams this allows high res via HLS format.

Also I will try a newer netty version for your errors in the next build. The mjpeg stream does not use ffmpeg.

I recommend using mpeg-dash (the w3c standardisation of HLS) since that will work on all browsers. Nginx also has full support for creating the dash segments. I’m doing that here https://github.com/imaginator/system/tree/master/salt/motion/files

That is what I am looking into at the moment, what browsers have u used it in and do they need a plugin for support?

As long as they support https://caniuse.com/#feat=mediasource you have no need for a plugin. See: https://github.com/Dash-Industry-Forum/dash.js/

Hi Matt

I no longer have the error since moving to a QNAP Virtual machine actually (or cpu issues that im aware of)
Cheers

1 Like

Successfully displaying rtsp video but if there are movements on the picture, the picture will pixelized. How to solve this?

Try adding an extra option to use tcp instead of UDP, it needs to be done BEFORE the -i like below…

ffmpeg -rtsp_transport tcp -i ...........normal command along here

There is an improvement but still the pixelized during movement. What must be the problem. Here is the log output:

ffmpeg version 3.2.12-1~deb9u1 Copyright © 2000-2018 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --prefix=/usr --extra-version=‘1~deb9u1’ --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 34.101 / 55. 34.101
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.101 / 57. 56.101
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libavresample 3. 1. 0 / 3. 1. 0
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
[mp3 @ 0x24016e0] Header missing
Input #0, rtsp, from ‘rtsp://192.168.1.36:8554/unicast’:
Metadata:
title : LIVE555 Streaming Media v2017.10.28
comment : LIVE555 Streaming Media v2017.10.28
Duration: N/A, start: 0.199689, bitrate: N/A
Stream #0:0: Video: h264 (Constrained Baseline), yuv420p(progressive), 1280x720, 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1: Audio: mp3, 44100 Hz, mono, s16p, 64 kb/s
Output #0, ffm, to ‘http://127.0.0.1:8090/camera1.ffm’:
Metadata:
title : LIVE555 Streaming Media v2017.10.28
comment : LIVE555 Streaming Media v2017.10.28
creation_time : now
encoder : Lavf57.56.101
Stream #0:0: Video: mjpeg, yuv420p, 640x360, q=2-31, 8192 kb/s, 25 fps, 1000k tbn, 10 tbc
Metadata:
encoder : Lavc57.64.101 mjpeg
Side data:
cpb: bitrate max/min/avg: 0/0/8192000 buffer size: 0 vbv_delay: -1
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
Press [q] to stop, [?] for help
frame= 9 fps=8.0 q=1.6 size= 268kB time=00:00:00.80 bitrate=2744.3kbits/s dup=6 drop=0 frame= 14 fps=8.6 q=1.6 size= 352kB time=00:00:01.30 bitrate=2218.1kbits/s dup=6 drop=3 frame= 18 fps=8.3 q=1.6 size= 428kB time=00:00:01.70 bitrate=2062.5kbits/s dup=6 drop=8 frame= 21 fps=7.7 q=1.6 size= 548kB time=00:00:02.00 bitrate=2244.6kbits/s dup=6 drop=13frame= 25 fps=7.7 q=1.6 size= 704kB time=00:00:02.40 bitrate=2403.0kbits/s dup=6 drop=19frame= 28 fps=7.4 q=1.6 size= 824kB time=00:00:02.70 bitrate=2500.1kbits/s dup=6 drop=23frame= 46 fps= 10 q=1.6 size= 1544kB time=00:00:04.50 bitrate=2810.8kbits/s dup=21 drop=2frame= 50 fps=9.9 q=1.6 size= 1700kB time=00:00:04.90 bitrate=2842.1kbits/s dup=21 drop=2frame= 53 fps=9.5 q=1.6 size= 1820kB time=00:00:05.20 bitrate=2867.2kbits/s dup=21 drop=3frame= 57 fps=9.3 q=1.6 size= 1980kB time=00:00:05.60 bitrate=2896.5kbits/s dup=21 drop=3frame= 60 fps=9.0 q=1.6 size= 2096kB time=00:00:05.90 bitrate=2910.2kbits/s dup=21 drop=4frame= 64 fps=8.8 q=1.6 size= 2256kB time=00:00:06.30 bitrate=2933.5kbits/s dup=21 drop=4frame= 68 fps=8.8 q=1.6 size= 2412kB time=00:00:06.70 bitrate=2949.1kbits/s dup=21 drop=5frame= 71 fps=8.6 q=1.6 size= 2532kB time=00:00:07.00 bitrate=2963.2kbits/s dup=21 drop=5frame= 73 fps=8.3 q=1.6 size= 2612kB time=00:00:07.20 bitrate=2971.9kbits/s dup=21 drop=6frame= 77 fps=8.2 q=1.6 size= 2772kB time=00:00:07.60 bitrate=2987.9kbits/s dup=21 drop=6frame= 81 fps=8.2 q=1.6 size= 2928kB time=00:00:08.00 bitrate=2998.3kbits/s dup=21 drop=7frame= 84 fps=8.1 q=1.6 size= 3048kB time=00:00:08.30 bitrate=3008.3kbits/s dup=21 drop=7frame= 88 fps=8.1 q=1.6 size= 3204kB time=00:00:08.70 bitrate=3016.9kbits/s dup=21 drop=8frame= 91 fps=8.0 q=1.6 size= 3324kB time=00:00:09.00 bitrate=3025.6kbits/s dup=21 drop=8frame= 95 fps=7.9 q=1.6 size= 3480kB time=00:00:09.40 bitrate=3032.8kbits/s dup=21 drop=9frame= 99 fps=7.9 q=1.6 size= 3640kB time=00:00:09.80 bitrate=3042.7kbits/s dup=21 drop=1frame= 102 fps=7.9 q=1.6 size= 3756kB time=00:00:10.10 bitrate=3046.5kbits/s dup=21 drop=1frame= 106 fps=7.8 q=1.6 size= 3916kB time=00:00:10.50 bitrate=3055.2kbits/s dup=21 drop=1frame= 110 fps=7.8 q=1.6 size= 4076kB time=00:00:10.90 bitrate=3063.4kbits/s dup=21 drop=1frame= 114 fps=7.8 q=1.6 size= 4236kB time=00:00:11.30 bitrate=3070.9kbits/s dup=21 drop=1frame= 119 fps=7.8 q=1.6 size= 4440kB time=00:00:11.80 bitrate=3082.4kbits/s dup=21 drop=1frame= 122 fps=7.7 q=1.6 size= 4564kB time=00:00:12.10 bitrate=3089.9kbits/s dup=21 drop=1frame= 127 fps=7.8 q=1.6 size= 4768kB time=00:00:12.60 bitrate=3100.0kbits/s dup=21 drop=1frame= 132 fps=7.9 q=1.6 size= 4964kB time=00:00:13.10 bitrate=3104.2kbits/s dup=21 drop=1frame= 139 fps=8.0 q=1.6 size= 5244kB time=00:00:13.80 bitrate=3113.0kbits/s dup=23 drop=1frame= 143 fps=8.0 q=1.6 size= 5408kB time=00:00:14.20 bitrate=3119.9kbits/s dup=23 drop=1frame= 147 fps=8.0 q=1.6 size= 5572kB time=00:00:14.60 bitrate=3126.4kbits/s dup=23 drop=1frame= 153 fps=8.1 q=1.6 size= 5820kB time=00:00:15.20 bitrate=3136.7kbits/s dup=23 drop=1frame= 157 fps=8.1 q=1.6 size= 5980kB time=00:00:15.60 bitrate=3140.3kbits/s dup=23 drop=1frame= 162 fps=8.1 q=1.6 size= 6172kB time=00:00:16.10 bitrate=3140.4kbits/s dup=23 drop=1frame= 167 fps=8.1 q=1.6 size= 6376kB time=00:00:16.60 bitrate=3146.5kbits/s dup=23 drop=1frame= 172 fps=8.1 q=1.6 size= 6592kB time=00:00:17.10 bitrate=3158.0kbits/s dup=23 drop=1frame= 175 fps=8.1 q=1.6 size= 6724kB time=00:00:17.40 bitrate=3165.7kbits/s dup=23 drop=1frame= 181 fps=8.2 q=1.6 size= 6980kB time=00:00:18.00 bitrate=3176.7kbits/s dup=23 drop=1frame= 186 fps=8.2 q=1.6 size= 7200kB time=00:00:18.50 bitrate=3188.2kbits/s dup=23 drop=1frame= 191 fps=8.2 q=1.6 size= 7396kB time=00:00:19.00 bitrate=3188.8kbits/s dup=23 drop=1frame= 196 fps=8.3 q=1.6 size= 7592kB time=00:00:19.50 bitrate=3189.4kbits/s dup=23 drop=1frame= 200 fps=8.2 q=1.6 size= 7752kB time=00:00:19.90 bitrate=3191.2kbits/s dup=23 drop=1frame= 205 fps=8.3 q=1.6 size= 7956kB time=00:00:20.40 bitrate=3194.9kbits/s dup=23 drop=180 speed=0.823x

Your CPU can not reach realtime aka 1x speed. You will need to do one or more of the following…

  1. Buy bigger CPU
  2. Enable hardware acceleration for ffmpeg instead of a bigger CPU, see their website, google and faq pages.
  3. Lower the framerate from 25fps to a lower value in the cameras setup and make sure it is a round multiple of what ffmpeg is trying to create.
  4. Make the FPS the same in the camera as to what the ffmpeg is trying to create.
  5. Get a camera that can create mjpeg streams natively.
  6. Use HLS streaming instead as it does not transcode the h264. The ipcamera binding creates a HLS stream.
2 Likes

Thank you matt1, solves my problem. Just lowered my FPS to 5. Everything is normal now.

Hello again matt1,
I have persistent error after running successfully for about some time. Here is the log:

[rtsp @ 0x5d75d0] CSeq 8 expected, 0 received.

At ffserver:
[GET] “/camera1.mjpg HTTP/1.1” 200 108

please help.

I’m trying to do this with a hacked Dafang camera but I’m getting this error. Any ideas?

HTTP error 503 Server too busy
http://127.0.0.1:8090/camera1.ffm: Server returned 5XX Server Error reply

I had the same problem.

For me worked increasing the MaxBandwidth to 10000