# How to display CCTV camera in dashboard (RTSP)

**URL:** <https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860>\
**Category:** General\
**Created:** [16 December 2018 23:37 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860 "2018-12-16T23:37:49Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 December 2018 16:36 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/41 "2018-12-23T16:36:02Z")

</div>

> [@krambriw](#):
>
> With NR and ffmeg sample project, the CPU load is around 99% and result is really not useable for live viewing unless you are fine waiting 15-20 seconds for movements to be visible

Are you running the browser on the pi or on another machine? If you are running it on the pi then try it on a different machine instead, it may well be the browser that is overloading it.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 December 2018 16:42 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/42 "2018-12-23T16:42:34Z")

</div>

> [@krambriw](#):
>
> Running Motion gives approx 17% CPU load (shown in top). The viewer is a Chrome browser, video stream via http. Picture shown is still useful == updated fast enough, movements are delayed about 1-2 seconds until they are visible in the browser
> 
> With NR and ffmeg sample project, the CPU load is around 99% and result is really not useable for live viewing unless you are fine waiting 15-20 seconds for movements to be visible

Open each stream in vlc and check that they are of the same type. Frame rate, image size, codec, bit rate etc. Is suspect that you will find they are not the same and that ffmpeg is doing more work in the NR case.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [23 December 2018 17:48 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/43 "2018-12-23T17:48:50Z")

</div>

Hey Colin,

If I run the test stream (with the rabbit) I see following in VLC:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/08ec5c89ef7daead8a4e764c02b7ae25fd27bc8e.png)

And my Raspberry is running smooth:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/200b5b2a2e4ddefb9fb9a864ee9fdb71092d277e.png)

But of course the resolution is **very** low ...

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [23 December 2018 21:07 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/44 "2018-12-23T21:07:17Z")

</div>

@krambriw: Would it be possible to test e.g. this public rtsp stream with Motion? Then we have a common reference to compare. In VLC you can see that this stream is much heavier compared to my original stream with the rabbit:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b8b7486d056fe9b4ba57d07d8f47db79ab17b2a9.png)

Now my Raspberry Pi 3 is getting loaded more heavily, but it is not exploding yet:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d089d85afd6d4db250e11064491d3bd741411ba9.png)

Red arrows is where the stream starts ...  
I have no clue whether this is acceptable for this kind of hardware...

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [24 December 2018 00:24 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/45 "2018-12-24T00:24:31Z")

</div>

Got a tip from my audio/video partner @btsimonh that I could check the GPU acceleration. So I builded ffmpeg with hardware acceleration enabled, and changed the URL to force ffmpeg to **use hardware decoding (in GPU) via h264\_mmal**:

```auto
-f rtsp -vcodec h264_mmal -i "rtsp://freja.hiof.no:1935/rtplive/_definst_/hessdalen03.stream" -f image2pipe -hls_time 3 -hls_wrap 10 pipe:1

```

However then I get an error about the hardware decoding:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/beedbcfa7e1feb826f4c4dd762d58f8c42683114.png)

The cause is (probably) that hardware MPEG2 decoding is not enabled on my Raspberry:

```auto
pi@raspberry-testboard:~ $ vcgencmd codec_enabled MPG2
MPG2=disabled

```

From this nice [article](http://what-when-how.com/Tutorial/topic-65614o158/Raspberry-Pi-Hacks-255.html) it seems that you need to buy (from the [Raspberry Pi Store](http://www.raspberrypi.com/mpeg-2-license-key/)) an MPEG2 license key, which is linked **unique** to the serial number of your Raspberry Pi. I really don't like this: have bought a Raspberry which includes a chip that I'm not allowed to use ... 😡

Will come back here after Christmas. See you guys !!

---

<div class="post-metadata">

**Author:** ![nygma2004](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nygma2004/32/1308_2.png) [@nygma2004](https://discourse.nodered.org/u/nygma2004)\
**Post date:** [25 December 2018 14:05 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/46 "2018-12-25T14:05:48Z")

</div>

Hi Mat,

I am a bit late responding to this thread, but I have done this some time ago. I am using avconv which is like ffmpeg in Linux (as far as I understood).  
I am using a simple exec command like this:  
avconv -i rtsp://user:pass@192.168.1.71:554/ch01.264 -frames 1 -qscale 1 -f image2 /home/pi/image.jpg

Works like a charm every time.

If you want to capture a video, that is also very similar:  
avconv -i rtsp://user:pass@192.168.1.71:554/ch01.264 -r 10 -t 30 -y -vcodec copy -an /home/pi/grab.mp4

This generates a 30 second clip from the RTSP stream.

I did a fairly long video on the subject, explaining in detail what I did: [https://www.youtube.com/watch?v=ihZWrJmbGFY&t=297s](https://www.youtube.com/watch?v=ihZWrJmbGFY&t=297s)

Regards,  
Csongor

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [26 December 2018 08:23 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/47 "2018-12-26T08:23:39Z")

</div>

Hi Csongor(@nygma2004),

Nice that you join the discussion. All ideas and proposals are welcome...

- Until now I considered the **Exec node** a bit too generic for doing specific ffmpeg stuff, so I have above only compared all existing Ffmpeg nodes. But I must admit that the code of [node-red-contrib-visio-ffmpeg](https://github.com/NGRP/node-red-contrib-viseo/blob/master/node-red-contrib-ffmpeg/node-ffmpeg-command.js) looks very similar to the [Exec node](https://github.com/node-red/node-red/blob/master/nodes/core/core/75-exec.js), so I assume it is derived from it some time ago ...

- Had never heard about **avconv** before. Seems that avconv is started as a fork from ffmpeg in 2011, based on internal conflicts in the team. But some years later it has been replaced by ffmpeg again in [Debian](https://lwn.net/Articles/650816/). Anyway I have tried both programs on the same rtsp stream, and in my test avconv was slower (20% more CPU usage):

- When I use the two streaming parameters from you youtube video, I only get 3 messages with buffers. And then the stream stops:

- And I payed Raspberry foundation for an MPEG hardware license, and now the hardware encoding is enabled:

Bart

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [26 December 2018 13:23 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/48 "2018-12-26T13:23:18Z")

</div>

> [@BartButenaers](#):
>
> Would it be possible to test e.g. this public rtsp stream with Motion?

Hello Bart, so nice to be back, even if xmas not really is over yet but it is more relaxed now, relatives left etc etc. And the dishwashing machine broke down, ordered a new one, are they factory programmed with a final destiny happening when they are needed at most???

Anyway, yes, those streams do work fine also in Motion. The cpu increases very much, depending partly on the in Motion configured fps.

(I'm always running my browsers on my MacBook, never on the Pi)

Top in RPi3 shows:

100 fps (well covering what the camera stream can deliver)  
CPU load varies in the range 100-300% out of 400%

5 fps (still good enough to detect movements)  
CPU load 100-200%

Reducing resolution to very low did not really reduce the CPU load significantly, still around 100-200% even with 352x288. Seems to be a pretty heavy task to decode/convert rtsp streams

Even if the GPU in the RPi3 is ready for mpeg-4 decoding, I do not think Motion is utilizing it. When I view the video output (from Motion via http) in VLC, it shows that the video is converted from mpeg-4 to motion JPEG Video (MJPG). This explains the high CPU load.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [26 December 2018 22:00 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/49 "2018-12-26T22:00:05Z")

</div>

> [@krambriw](#):
>
> so nice to be back

Hey Walter (@krambriw), I'm also glad you are back 😉

> [@krambriw](#):
>
> 100 fps (well covering what the camera stream can deliver)

Do you mean that setting 100 fps is equal to allowing the _ **maximum** _ fps that the rtsp source can deliver?

When I add the fabulous (🕶) _node-red-contrib-msg-speed_ and _node-red-contrib-image-info_ nodes to my flow:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6d4626b2477eb40f66d881e91107e833ab2d46a5.png)

```auto
[{"id":"66574007.74b0c","type":"exec","z":"18e47039.88483","command":"ffmpeg -f rtsp -i \"rtsp://freja.hiof.no:1935/rtplive/_definst_/hessdalen03.stream\" -f image2pipe pipe:1","addpay":false,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"Decode RTSP stream","x":1560,"y":820,"wires":[["2943cc00.7822e4"],[],[]]},{"id":"7d3aea16.d99b84","type":"inject","z":"18e47039.88483","name":"Start stream","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1090,"y":820,"wires":[["66574007.74b0c"]]},{"id":"d8cdbb87.676ab8","type":"image","z":"18e47039.88483","name":"","width":"200","x":2150,"y":840,"wires":[]},{"id":"e9cc38bc.4300b8","type":"inject","z":"18e47039.88483","name":"Pause all streams","topic":"","payload":"SIGSTOP","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1110,"y":860,"wires":[["53b625e3.eee7bc"]]},{"id":"4bdb02b2.c73efc","type":"inject","z":"18e47039.88483","name":"Resume all streams","topic":"","payload":"SIGCONT","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1110,"y":900,"wires":[["53b625e3.eee7bc"]]},{"id":"53b625e3.eee7bc","type":"change","z":"18e47039.88483","name":"","rules":[{"t":"set","p":"kill","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1330,"y":860,"wires":[["66574007.74b0c"]]},{"id":"c6743afd.82d568","type":"inject","z":"18e47039.88483","name":"Stop all streams","topic":"","payload":"SIGTERM","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1100,"y":940,"wires":[["53b625e3.eee7bc"]]},{"id":"c12393d5.0a2b2","type":"msg-speed","z":"18e47039.88483","name":"","frequency":"sec","estimation":false,"ignore":false,"x":1950,"y":820,"wires":[["4aa0ee29.c9164"],["d8cdbb87.676ab8"]]},{"id":"4aa0ee29.c9164","type":"ui_chart","z":"18e47039.88483","name":"","group":"94d2ac46.aad5d","order":0,"width":0,"height":0,"label":"fps","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"fps","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":2130,"y":800,"wires":[[],[]]},{"id":"2943cc00.7822e4","type":"image-info","z":"18e47039.88483","name":"","x":1770,"y":820,"wires":[["c12393d5.0a2b2"]]},{"id":"94d2ac46.aad5d","type":"ui_group","z":"","name":"Linear gauge widget test","tab":"76c22f9b.11403","disp":true,"width":"6","collapse":false},{"id":"76c22f9b.11403","type":"ui_tab","z":"","name":"Custom UI","icon":"dashboard"}]

```

Then I can see that the rtsp stream gives in my test case:

- Jpeg images of 1280x720 resolution
- Frame rate is \<= 16 fps

It isn't really clear to me anymore whether Motion is faster (compared to Ffmpeg directly), or it is just a difference in resolution/fps/... ? But I have learned that the Exec-node does the job pretty well.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [27 December 2018 10:45 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/50 "2018-12-27T10:45:22Z")

</div>

> [@BartButenaers](#):
>
> Do you mean that setting 100 fps is equal to allowing the _ **maximum** _ fps that the rtsp source can deliver?

Yes, that is the number of frames when Motion limits it's processing, "Maximum number of frames to be captured per second". If the camera stream delivers 60 fps, it would not be Motion that limits the processing. However, when I run this on the RPi3 I think I can see that there are other limitations that prevents the processing of 60 fps, could b the RPi itself, could be my internet network connection bandwidth. I only see that there are many frames captured during a second since the millisecond counter in the picture is updated very frequently during the same second

Anyway, I will try your flow with the exec node, looks nice

To take this further, what you really would like to do is to classify objects and you would most likely not push every single frame to be analyzed, it would overload the analysor. It is here Motion comes in and shines and makes it interesting, frames are only sent further when _motion_ is detected. So if you want to build a complete video analyze functionality in NR, you need to think about how to filter out those frames that should be further analyzed

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [30 December 2018 10:20 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/51 "2018-12-30T10:20:35Z")

</div>

Damn, I cannot get the hardware acceleration working on my Raspberry Pi 3.

- Have bougth a license key and installed it and checked whether it is activated (see how to [here](https://www.howtogeek.com/137654/how-to-add-mpeg-2-and-vc-1-video-codec-support-to-your-raspberry-pi/)). That is all OK.

- I have build Ffmpeg with hardware accelaration enabled (see how [here](https://github.com/e1ioan/RaspberryPi-AxisYoutubeStreaming/blob/f8a098eb3d54974c41fe29248236f474b2ebb09e/README.md)).
- I have an extra ' **-vodec h264\_mmal**' parameter in my ffmpeg command to tell him that the mpeg (that I receive via an rtsp stream) should be **decoded in hardware** :

```auto
 ffmpeg -vcodec h264_mmal -rtsp_transport tcp -i "rtsp://freja.hiof.no:1935/rtplive/_definst_/hessdalen03.stream" -f image2pipe pipe:1

```

- At the start you will see that I use the correct ffmpeg (with hardware acceleration enabled):

> ffmpeg version N-92794-g7d5bb3a Copyright (c) 2000-2018 the FFmpeg developers  
> built with gcc 4.9.2 (Raspbian 4.9.2-10)  
> configuration: --arch=armel --target-os=linux --enable-gpl **--enable-omx --enable-omx-rpi** --enable-nonfree **--enable-mmal**  
> libavutil 56. 25.100 / 56. 25.100  
> libavcodec 58. 42.104 / 58. 42.104  
> libavformat 58. 25.100 / 58. 25.100  
> libavdevice 58. 6.101 / 58. 6.101  
> libavfilter 7. 46.101 / 7. 46.101  
> libswscale 5. 4.100 / 5. 4.100  
> libswresample 3. 4.100 / 3. 4.100  
> libpostproc 55. 4.100 / 55. 4.100  
> Input #0, rtsp, from 'rtsp://freja.hiof.no:1935/rtplive/_definst_/hessdalen03.stream':  
> Metadata:  
> title : hessdalen03.stream  
> Duration: N/A, start: 35792.473322, bitrate: N/A  
> Stream #0:0: Video: h264 (High), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 59.94 fps, 59.94 tbr, 90k tbn, 119.88 tbc  
> Stream mapping:  
> Stream #0:0 -\> #0:0 (h264 (h264\_mmal) -\> mjpeg (native))  
> Press [q] to stop, [?] for help

- But then I get an error:

> [h264\_mmal @ 0x20db2b0] Did not get output frame from MMAL.  
> Error while decoding stream #0:0: Unknown error occurred  
> [h264\_mmal @ 0x20db2b0] MMAL error 2 on control port

Have been searching across the globe, but cannot find a solution. Perhaps this forum is not the best place to ask this question, but hopefully somebody with ffmpeg knowledge is reading ...

Perhaps I misinterpret the logging, but it seems to me (`h264 (h264_mmal) -> mjpeg (native)`) that he converts h264 to mjpeg? But I need at the end (`image2pipe`) a jpeg image to be piped (via stdout stream) to the Exec node. Could that be a problem i.e. that he cannot convert the mjpeg to jpeg somehow?

I don't know enough about ffmpeg to solve this on my own 🥴

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 December 2018 10:39 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/52 "2018-12-30T10:39:39Z")

</div>

Try it reading from an mp4 file rather than the stream to see if it is a problem with the stream or a more fundamental issue.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [30 December 2018 13:45 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/53 "2018-12-30T13:45:03Z")

</div>

Hey Colin (@Colin),

Thanks for the tip. Again a '_ **bit** _' closer to the thruth ...

I have downloaded two Big Buck Bunny [videos](https://peach.blender.org/download/) from there [download](https://download.blender.org/peach/bigbuckbunny_movies/) site:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/1fcd48fbf0dec5160ccef01bcad85f5864ce6a50.png)

- The **.mov** file gives me the **same error** as with the RTSP stream, although it is **h264** (as stated in the file name). So I assume the hardware decoder cannot handle my RTSP stream for a similar reason. _ **But I still don't know why this h264 doesn't work ...** _

- The **.mp4** file works fine. I get a nice speed of average 115 frames per second in two separate tests: one test with hardware acceleration (i.e. parameter ' **-vodec h264\_mmal**' added) and one without hardware acceleration (without that parameter). But I don't really see a difference in overall CPU performance between both tests:

---

<div class="post-metadata">

**Author:** ![Jaxn](https://avatars.discourse-cdn.com/v4/letter/j/f19dbf/32.png) [@Jaxn](https://discourse.nodered.org/u/Jaxn)\
**Post date:** [30 December 2018 14:02 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/54 "2018-12-30T14:02:03Z")

</div>

As far as i know you do not need to buy the mpeg2 license as long as you do not use mpeg2 videos. mpeg4 - which is h264 - should work out of the box.  
As i was playing around with videos on a raspberry i came to the conclusion that vlc does not use hardware acceleration but omxplayer does. It uses the [OpenMAX](https://en.wikipedia.org/wiki/OpenMAX) library.  
Your ffmpeg compiling options "--enable-omx" may also point to OpenMAX.  
But here my knowledge ends ☹

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [30 December 2018 16:59 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/55 "2018-12-30T16:59:32Z")

</div>

Hi @Jaxn, I have tested the same flow on a Raspberry where I haven't a license key and the performance is **equal**. So let's summarize:

- Like you say the license key is only required for MPEG2. I shouldn't have seen that when I ordered it from their [site](http://www.raspberrypi.com/mpeg-2-license-key/)...

- For playing h264 via hardware acceleration, ffmpeg needs to build with appropriate parameters.

- All tutorials (like e.g. [this](https://github.com/e1ioan/RaspberryPi-AxisYoutubeStreaming/blob/f8a098eb3d54974c41fe29248236f474b2ebb09e/README.md) one) say you need to specify **-vodec h264\_mmal** to instruct ffmpeg that it should use hardware acceleration. That is also explained in the [official docs](https://trac.ffmpeg.org/wiki/HWAccelIntro) for external decoders. However I don't see any difference in performance when I specify that parameter. And without that parameter I can also play the .mov file without problems ...

- And then there is the **"-hwaccel"** parameter for internal decoders, but I don't get that one working for some reason:

So I don't know now if it is playing via hardware or software.

P.S. For those using **VLC** : via Tools--\>Messages you can set the verbose level to 'debug' and then you can see if underneath **avcodec** (i.e. ffmpeg) uses hardware acceleration. Example on my portable:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/14cb8a29e5d17d7b298fb2ba67d5b991b1cfe26f.png)

---

<div class="post-metadata">

**Author:** ![wb666greene](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wb666greene/32/6534_2.png) [@wb666greene](https://discourse.nodered.org/u/wb666greene)\
**Post date:** [22 January 2019 16:10 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/57 "2019-01-22T16:10:45Z")

</div>

Replying to an old post in this thread, but I think its relevant.

> [@nygma2004](#):
>
> I am using a simple exec command like this:  
> avconv -i rtsp://user:pass@192.168.1.71:554/ch01.264 -frames 1 -qscale 1 -f image2 /home/pi/image.jpg
> 
> Works like a charm every time.

What rtsp sources are you capturing from?

With opencv rtsp stream capture (cv 3.3.0 and 3.4.2) I'm finding issues with many rtsp sources, no difference between the cv versions (on three different Linux systems).

errors/warnings like:

> Invalid UE golomb code  
> [h264 @ 0x30f6460] mb\_type 43 in P slice too large at 37 68  
> [h264 @ 0x30f6460] error while decoding MB 37 68

Running your command on one of my Onvif cameras on my i7 Ubuntu 16.04 desktop:

avconv -i rtsp://admin:admin@192.168.2.221/media/video1 -frames 1 -qscale 1 -f image2 /home/wally/image.jpg

> ffmpeg version 2.8.15-0ubuntu0.16.04.1 Copyright (c) 2000-2018 the FFmpeg developers  
> built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609  
> configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86\_64-linux-gnu --incdir=/usr/include/x86\_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --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-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv  
> WARNING: library configuration mismatch  
> avcodec configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86\_64-linux-gnu --incdir=/usr/include/x86\_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --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-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv --enable-version3 --disable-doc --disable-programs --disable-avdevice --disable-avfilter --disable-avformat --disable-avresample --disable-postproc --disable-swscale --enable-libopencore\_amrnb --enable-libopencore\_amrwb --enable-libvo\_aacenc --enable-libvo\_amrwbenc  
> libavutil 54. 31.100 / 54. 31.100  
> libavcodec 56. 60.100 / 56. 60.100  
> libavformat 56. 40.101 / 56. 40.101  
> libavdevice 56. 4.100 / 56. 4.100  
> libavfilter 5. 40.101 / 5. 40.101  
> libavresample 2. 1. 0 / 2. 1. 0  
> libswscale 3. 1.101 / 3. 1.101  
> libswresample 1. 2.101 / 1. 2.101  
> libpostproc 53. 3.100 / 53. 3.100  
> Invalid UE golomb code  
> Last message repeated 1 times  
> Input #0, rtsp, from 'rtsp://admin:admin@192.168.2.221/media/video1':  
> Metadata:  
> title : VCP IPC Realtime stream  
> Duration: N/A, start: 0.000000, bitrate: N/A  
> Stream #0:0: Video: h264 (High), yuv420p, 1280x720, 30 fps, 30 tbr, 90k tbn, 60 tbc  
> Stream #0:1: Data: none  
> Please use -q:a or -q:v, -qscale is ambiguous  
> [swscaler @ 0x17c7980] deprecated pixel format used, make sure you did set range correctly  
> Output #0, image2, to '/home/wally/image.jpg':  
> Metadata:  
> title : VCP IPC Realtime stream  
> encoder : Lavf56.40.101  
> Stream #0:0: Video: mjpeg, yuvj420p(pc), 1280x720, q=2-31, 200 kb/s, 30 fps, 30 tbn, 30 tbc  
> Metadata:  
> encoder : Lavc56.60.100 mjpeg  
> Stream mapping:  
> Stream #0:0 -\> #0:0 (h264 (native) -\> mjpeg (native))  
> Press [q] to stop, [?] for help  
> Invalid UE golomb code  
> frame= 1 fps=0.0 q=1.0 Lsize=N/A time=00:00:00.03 bitrate=N/A dup=1 drop=1  
> video:237kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

But it did capture an image.

To capture "snapshots" for my python AI I'm finding directly grabbing snapshots from the Onvif "snapshot http URL" works best for Onvif cameras.

For my Lorex DVR I'm finding pulling frames with openCV from rtsp streams works great, although the latency is several seconds. A net DVR I tried (Geovision SNVR0811) grabbing from its rtsp URL (rtsp://admin:admin@192.168.2.222:554/ch1) worked great until it detected motion then it locked up my code with one of those h264 errors. Using the camera directly (rtsp://admin:admin@192.168.2.221/media/video1) doesn't lock up my code, but the latency is horrible and some images have mosiac breakups especially with a lot of motion in the scene.

Right now I've three "front ends for my AI) ftp snapshots from a camera or DVR, image grabs from rtsp streams with openCV and http access from the Onvif snapshot URL ([http://192.168.2.221:85/images/snapshot.jpg](http://192.168.2.221:85/images/snapshot.jpg))

Which method works "best" seems to depend on the camera source and trying seems the only way to know ☹

---

<div class="post-metadata">

**Author:** ![wb666greene](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wb666greene/32/6534_2.png) [@wb666greene](https://discourse.nodered.org/u/wb666greene)\
**Post date:** [22 January 2019 18:47 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/58 "2019-01-22T18:47:03Z")

</div>

> [@BartButenaers](#):
>
> ![exec_rtsp](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/5fc5ea680839875bc4dacaa440c96a258ce5091f.gif)
> 
> ```auto
> 
> ```

I'm going through this thread again as I'm getting serious about getting some kind of web interface for my AI. The dashboard is working fine to mode setting etc. monitoring the cameras for setup (priority) or viewing (mostly useful for demos)

Playing your public rtsp stream in my opencv code I get ~25 fps. but is there a link with a more reasonable resolution like D1?

When I imported your flow into node-red it worked fine after I installed the image-output node. Is there some way to get the image-output node to display on a different page or is it confined to displaying in the node-red editor?

Pasting in the URL for one of my Lorex DVR channels it showed the same "image caching" issue I mentioned in this thread: [dashboard caching](https://discourse.nodered.org/t/dashboard-caching-images-how-to-stop-it/7112)

It seems to choke on the HD image although I can see flashes with smooth movement as a car happened to be driving by. This may be that UDP buffer size issue that has been mentioned earlier. I need to investigate this image-output node more thoroughly.

Changing the rtsp URL to use a substream from my Lorex DVR it plays fine but still is "blocky" compared to when viewed in my openCV test code. I think its like 352x240. The Lorex streams this to my phone fine with their "app" but its resolution is not good enough to focus the cameras.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [22 January 2019 19:37 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/59 "2019-01-22T19:37:43Z")

</div>

> [@wb666greene](#):
>
> Is there some way to get the image-output node to display on a different page or is it confined to displaying in the node-red editor?

Nope, it is purely designed to display in the Node-RED flow editor. It just adds some svg content to the svg of the flow editor.

I'm going to create something similar for the dashboard, to have some PTZ controls on top of the camera view. I started to create a [repository](https://github.com/bartbutenaers/node-red-contrib-ui-video/) already last weekend, but it contains nothing useful yet!!!! Just need some free time to spend on it 🥴

> [@wb666greene](#):
>
> avconv -i rtsp://user:pass@192.168.1.71:554/ch01.264 -frames 1 -qscale 1 -f image2 /home/pi/image.jpg

Correct me if I'm mistaken but it seems to me that this command writes all images to a temporary file?? If so, I would suggest to use the stdout stream (via image2pipe) to keep everything in memory only.

> [@wb666greene](#):
>
> It seems to choke on the HD image although I can see flashes with smooth movement as a car happened to be driving by. This may be that UDP buffer size issue that has been mentioned earlier

If you look at the code of the [image-output](https://github.com/rikukissa/node-red-contrib-image-output/blob/master/image/image.js) node, you will see that it uses RED.comms.publish to push the image via a [websocket](https://github.com/node-red/node-red/wiki/Runtime-Editor-Comms-protocol) channel to the flow editor. I have very bad experiences with pushing lots of data through websockets. Never had a look at that UDP buffer size, but if you kind find a solution, **please** be my guest !!!

I try to avoid pushing image streams over websockets, since that freezes my user interface entirely. I have described this [here](https://www.npmjs.com/package/node-red-contrib-multipart-stream-encoder#push-the-images-to-the-dashboard), and in the section after that you can see how I avoid websockets by using my node-red-contrib-multipart-stream-encoder node ...

> [@wb666greene](#):
>
> Right now I've three "front ends for my AI) ftp snapshots from a camera or DVR, image grabs from rtsp streams with openCV

Is there any reason why you are using OpenCv to stream RTSP? From this explanation, I understand that OpenCv uses FFmpeg underneath to accomplish that. I would expect it to be faster to call FFmpeg directly from Node-RED, but don't hesitate to correct me if I'm wrong!

---

<div class="post-metadata">

**Author:** ![wb666greene](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wb666greene/32/6534_2.png) [@wb666greene](https://discourse.nodered.org/u/wb666greene)\
**Post date:** [22 January 2019 20:05 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/60 "2019-01-22T20:05:11Z")

</div>

> [@BartButenaers](#):
>
> Is there any reason why you are using OpenCv to stream RTSP? From this explanation, I understand that OpenCv uses FFmpeg underneath to accomplish that. I would expect it to be faster to call FFmpeg directly from Node-RED, but don't hesitate to correct me if I'm wrong!

The reason here is simple. Its done in the Python code that sends the images to the AI which uses the Movidius NCS python API so using opencv-python features are a natural. For the ftp front end, node-red implements the server and passes the file as a buffer to the Python code via MQTT. For the http jpeg snapshots I use the Python requests module.

I'm willing to bet there is not a "simpler" way to view multiple rtsp streams that this openCV Python snippet:

> windowName = list() # flags removes toolbar and status bar from window  
> for i in range(Nrtsp):  
> windowName.append('rtsp\_' + str(i))  
> cv2.namedWindow(windowName[i], flags=cv2.WINDOW\_GUI\_NORMAL + cv2.WINDOW\_AUTOSIZE) # this will fail for CV without QT for highgui
> 
> Rcap = list()  
> for i in range(Nrtsp):  
> Rcap.append(cv2.VideoCapture(rtspURL[i]))  
> Rcap[i].set(cv2.CAP\_PROP\_BUFFERSIZE, 2) # doesn't throw error or warning in python3, but not sure it is actually honored
> 
> while(1):  
> try:  
> for i in range(Nrtsp):  
> ret, frame = Rcap[i].read()  
> ##cv2.imshow(windowName[i],cv2.resize(frame, (640, 360)))  
> cv2.imshow(windowName[i], frame)  
> fps.update() # update the FPS counter  
> key = cv2.waitKey(1) & 0xFF  
> if key == ord("q"): # if the `q` key was pressed, break from the loop  
> break  
> except KeyboardInterrupt:  
> break  
> except Exception as e:  
> print('EXCEPTION! ' + str(e))  
> break

It handles 15 1920x1080 rtsp streams resized to 640x360 for live viewing on my i7 Desktop while I'm doing everything normal -- email about 30 browser tabs open on six virtual desktops, Email pandora, etc.

As to the avconv command I just copied it from the much earlier post in this thread and changed the URL to be one of my 720p Onvif cameras to illustrate there be deamons in rtsp-land. No problems on one system with one (brand) of camera is a long way from being a general solution.

VLC is the closest we have to a general solution -- its about the only "3rd party" rtsp viewers most of the network DVR vendors will offer any support for, but most use some lame unsigned activeX control limiting you to using Internet Explore for there web viewers. I'd love to find a way to use the "guts" of VLC, but last time I looked they made ffmpeg look like the king of clear documentation!

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [22 January 2019 20:09 UTC](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860/61 "2019-01-22T20:09:45Z")

</div>

The speed looks impressive ...

[Previous page](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860.md?page=2)

[Next page](https://discourse.nodered.org/t/how-to-display-cctv-camera-in-dashboard-rtsp/5860.md?page=4)
