How to display CCTV camera in dashboard (RTSP)

Hi @BartButenaers , when you said :

my cameras are already set to 720p because in 1080p, like @Lupin_III, I only have still images or fragments of images.
Where can you set the image size and bit rate in Node-red?
image
i got only few nodes to display rstp streamming : image

Yes defining the framerate and image size in the ffmpeg command would be best, but I have no idea at the moment how to do that. Only workaround I would have at the moment is to retrieve the large images at full speed from ffpmeg, and throttle and resize them afterwards in node-red by adding extra nodes. But then of course you are wasting a lot of cpu for decoding the stream, while you throw away lot of the data afterwards...

Bart , this topic got 19.4k views !
What do you do , go to work now !
:rofl:

Tried to install last night ffmpeg again on my raspberry, but it keeps failing due to segmentation errors. So unfortunately cannot test it ...

But following to this link, you could set an FPS of e.g. 7 frames per second like this:

ffmpeg -i rtsp://... -r 7 ...

And here is another link with another way to set both FPS and resolution.

Would be nice if somebody could do some tests and post the results in this discussion.

P.S. Using my node-red-contrib-msg-speed node, you can show the FPS in Node-RED. Indeed the number of messages per second is equal to the FPS, since each message contains a single image ...

Great ! i test -r 5 5 img/s, and works nicely in 720p :slight_smile:
although the video quality is pixelated compared to VLC :worried:

  • with the same -r 5 but by selecting the 1080p stream: it is unusable! We do not see it on the capture but the image flashes and tries to be displayed but at the half, it is erased and starts again. In addition it can not stall on 5 img / s !?
  • I noticed this peak , each time the stream starts, then stabilize :
    image

Just one thing. If Im not wrong, setting -r after the input rtsp you're definig the option on the output. That means than the node works on all stream received and than shows just the output setting. Wouldn't be better the set the input option in order to avoid the worthless node working on all the input streaming?

Yes think you are right. If you see at the link in my previous post, you see this command:
ffmpeg -r 7 -i ...
Seems I made a copy paste error. It is a pity I cannot test it myself at the moment...

@Lupin_III @BartButenaers if i understand , this bad line
ffmpeg -f rtsp -i "rtsp://192.168.1.7:554/user=xxxxx_password=xxxxxx_channel=0_stream=1.sdp?real_stream" -r 5 -f image2pipe pipe:1

goes to :
ffmpeg -r 5 -f rtsp -i "rtsp://192.168.1.7:554/user=xxxxx_password=xxxxxx_channel=0_stream=1.sdp?real_stream" -f image2pipe pipe:1

with the -r 5 just after the ffmpeg . Right ?

Because i don't get the good result If i put -r 5before::


If i put -r 5after: it's better

Well I think that my Stackoverflow link points to an incorrect non-working example. :rage:
Indeed when I look at the official ffmpeg ChangingFrameRate example,two things become clear:

  • The -r option is an output option (as you already figured out)
  • Seems you could also use a filter -filter:v fps=fps=7 to drop frames in between.

Perhaps you can achieve better results with the fps filter? Seems that the -r option is applied AFTER the filter chain (where the fps filter is applied), so perhaps it is even better (for performance) if you drop the frames sooner using a filter. Then less processing is required for frames that you will drop anyway ...

[EDIT] the -r option is applied after the filters, but before the encoding. So I think both options will be applied in the ffmpeg architecture at the next two locations:

image

I should say: the sooner you drop the frames, the better ...

Thanks Bart.
@SuperNinja, I don't know how to show the frame rate on the video, as you do. So, try to put a filter at the beginning as Bart suggests.
Thanks

@Lupin_III
you have to add this 3 nodes in the RTSP stream output.

[{"id":"e7882733.fd58a8","type":"msg-speed","z":"fe2c7bc6.bd49c8","name":"","frequency":"sec","estimation":true,"ignore":false,"x":440,"y":3540,"wires":[["3359b1d5.b8b7de","4829f33f.1f83dc","e8b1420c.5086b"],[]]},{"id":"3359b1d5.b8b7de","type":"ui_valuetrail","z":"fe2c7bc6.bd49c8","group":"7d9caa9a.53c694","order":4,"width":3,"height":1,"name":"","label":"","blur":false,"minmax":true,"colorLine":"#ff9900","colorFromTheme":true,"stroke":2,"pointcount":"24","x":610,"y":3530,"wires":[]},{"id":"4829f33f.1f83dc","type":"ui_text","z":"fe2c7bc6.bd49c8","group":"7d9caa9a.53c694","order":5,"width":1,"height":1,"name":"dash fps","label":"{{msg.payload}}fps","format":"","layout":"row-center","x":630,"y":3500,"wires":[]},{"id":"7d9caa9a.53c694","type":"ui_group","z":"","name":"camMisecu","tab":"250de740.57ee78","order":8,"disp":true,"width":"6","collapse":true},{"id":"250de740.57ee78","type":"ui_tab","z":"","name":"Dashboard","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

found here :



And Dashboard text node

-filter:v fps=fps=5 seems to be same or little better : the CPU is at 15% and respect 5fps. compared to -r 5 in the output.
BUT 1080p is allways unusable :pleading_face:

This means you have no high FPS peak at startup anymore?

Looking for a needle in a haystack :weary:

  • You can show some more logging via ffmpeg -v verbose, but I think we will need a shrink when evaluating the output of it ... But I could image that there are buffers being used, whose size is not sufficient for holding the data of large images. Or anything else ...
  • Some sites (e.g. zoneminder) advise to use TCP (instead of UDP) as transport protocol: ffmpeg -rtsp_transport tcp ...
  • In the previous Zoneminder link, they advise to lower the FPS in the camera itself (and use inside Zoneminder an FPS larger than the one from the camera').

And no, I always have the peak at startup:
image
There is a waiting time before the stream is displayed, (filling the buffer?) and when it has enough image, it launches them. Does it suddenly display the 30 images, to make up for the accumulated delay?Then the fps are respected.

If I set 5FPS per filter in the node, OR in the camera settings, I always have this peak at startup.


1080p 1FPS, poor quality, 190Kb/S. See at the right, the 720p camera parameters 5FPS, Best quality, 824Kb/s work like a charme !
1080worst
1080p 1FPS, poor quality, 190Kb/S.

Even by reducing the parameters of the camera to 1FPS and "poor" quality (the bitrate is at 190Kb / s) I only have 1/8 of the image displayed by jerking and a rise to 7FPS displayed.

Surely the solution, but I admit being unable to do it. :disappointed:

I'm not an expert, but too me it seems that 'some' ffmpeg buffer is not big enough to fit the entire image. If you would add the verbose logging parameter (which I have showed in my previous post) we hopefully get a bit more information about what is going on.

Not quite sure what you mean. In my previous post I have explained which parameter you need to add to specify the tcp protocol.

Sorry Bart , I threw in the towel too early :sweat_smile: :
i test this : ffmpeg -v verbose -rtsp_transport tcp -i "rtsp://192.168.1.7:554/user=..
working with 720p, but unusable in 1080p
image
1080p, 1FPS, quality worst, TCP transport

[EDIT] i compare 1080p not working, with 720p working
1080p not working : 1


720p working :

1080p: 2

720p working :

1080p: 3

720p: 3

1080p: 4

720p: 4

1080p: 5

720p: 5

1080p: 6

1080p: 7

720p: 7

1080p 8

1080p 9

720p 9

1080p 10

720p 10

1080p 11

720p 11

1080p 12

720p 12

1080p 13

720p 13

1080p 14

720p 14

1080p 15

720p 15


I've made several test, but it remains this peak at startup :frowning:

BTW nice area where you live!!! I'm quite jealous....

The error "decoding for stream 0 failed" doesn't give us much detail, except from the fact that the decoding module fails (which might indicate bad input data).

We have added -rtsp_transport tcp because TCP makes sure that all your network packets arrive, while UDP doesn't retransmit packets that are lost. And when packets get lost, the lost data could e.g. result in various decoding problems.

But from this Stackoverflow discussion it becomes clear that:

  • Your packet loss might increase at higher bitrates. Your network card might be dropping packets, when e.g. ffmpeg takes too long to decode the video. I think you can check (on linux) with the ifconfig command whether there is packet loss?
  • Then they propose to increase the size of the receiver buffer (e.g. ffmpeg recv_buffer_size=2000000), but don't understand that very well since it is an UDP buffer...

You could try to set the log level to "debug" (instead of verbose) to get more information, more specific the extra logging just before or after the error. Think you can also set the log level to "trace" to even show yet more detailed information ...

hi
i pasted your flow and changed with mr rstp adreed but i get error "rc - 2" in decode node
can you help me?

Hi @anto86na,
Welcome to the forum!
Next time please add some more information about what you have tried already, because now it is rather impossible for us to determine the root cause ...

  • Which hardware and operating system are your running on?
  • Have you installed ffmpeg succesfully?
  • Can you access ffmpeg from anywhere on the command line (e.g. check it by ffmpeg -version)?
  • Have you tried to change the loglevel, as describe above (to get more information)
  • ...

Bart