SvenVD / rpisurv

Raspberry Pi surveillance
https://community.rpisurv.net
GNU General Public License v2.0
610 stars 101 forks source link

Screen change causes flickering on rpi2 B #156

Closed icebrian closed 9 months ago

icebrian commented 2 years ago

I am having issues with screen/cameras flickering after screen change that ends up reverting to previous screen.

Firstly some details, am running Raspberry Pi OS Lite (Legacy) 32bit released on April 4th 2022 and rpisurv-3.0.0.

To account for Lite and multiple screens, I added, as per docs, the following to my /boot/config.txt

disable_overscan=1           # without this I get not only flickering but multiple horizontal lines through my video
framebuffer_width=1920
framebuffer_height=1080
gpu_mem=512

In my /etc/rpisurv/display1.yml I have the following:

  screens:
    - camera_streams:
        - url: "rtmp://10.10.10.63:1935/live/north_camera_1"
          probe_timeout: 30
          rtsp_over_tcp: true
        - url: "rtmp://10.10.10.63:1935/live/north_camera_2"
          probe_timeout: 30
          rtsp_over_tcp: true
        - url: "rtmp://10.10.10.63:1935/live/west_camera_1"
          probe_timeout: 30
          rtsp_over_tcp: true
        - url: "rtmp://10.10.10.63:1935/live/west_camera_2"
          probe_timeout: 30
          rtsp_over_tcp: true
      duration: 20
    - camera_streams:
        - url: "rtmp://10.10.10.63:1935/live/east_camera_1"
          probe_timeout: 30
          rtsp_over_tcp: true
        - url: "rtmp://10.10.10.63:1935/live/east_camera_2"
          probe_timeout: 30
          rtsp_over_tcp: true
        - url: "rtmp://10.10.10.63:1935/live/south_camera_1"
          probe_timeout: 30
          rtsp_over_tcp: true
        - url: "rtmp://10.10.10.63:1935/live/south_camera_2"
          probe_timeout: 30
          rtsp_over_tcp: true
      duration: 20

I've tested each camera feed, and they are all working both in VLC and in Home Assistant.

Now the behaviour I am seeing is very strange, at first screen 1 shows all 4 cameras no problem, then when it tries to change to screen 2 (after 20 second duration) it jumps to a black screen for about 3 - 4 seconds, then back to screen 1 and now all cameras are flickering non-stop, it stay's like this for the same 20seconds, then changes once again to screen 2, and now screen 2 works just fine and display's the remaning 4 cameras just fine, then the cycle repeats, when the 20 seconds are up it stries to change back to screen 1, goes black for about 3-4 seconds then returns to screen 2 and all cameras are flickering.

I've tried with network caching but same result.

Initially I also tried having all 8 cameras on the same screen, but there I had a diferente problem. When the screen would start showing, cam 1, then 2 would show then suddenly HDMI output is lost and my monitor goes into power saving. The only way round this that I found was to have only 4 cameras on each screen.

In the log I have the following:

2022/06/01 19:01:23 - l_default - INFO - Starting rpisurv 3.0.0
2022/06/01 19:01:23 - l_default - INFO - Auto detected display DEL-DELL_P2719H at HDMI 0 with display number 2 1920 x 1080
2022/06/01 19:01:23 - l_default - INFO - Unique id of this installation is 82edee3c7b65198eee76da679a8bf45dce3865f4c92cdc63fc1ace1b5ed72333
2022/06/01 19:03:16 - l_default - INFO - Sending stats is disabled, not sending stats
2022/06/01 19:05:06 - l_default - ERROR - Skipping calculating free malloc memory because of TimeoutExpired(['/usr/bin/vcgencmd', 'get_mem', 'malloc'], 1)
2022/06/01 19:05:07 - l_default - ERROR - Skipping calculating free reloc memory because of TimeoutExpired(['/usr/bin/vcgencmd', 'get_mem', 'reloc'], 1)

Anyone have any idea?

Thanks!

icebrian commented 2 years ago

In the meantime, i've downscalled my streams first to 960x540, but still same problem, then to 640x480 and also a problem, but no flickering, just not chaning correctly, to next screen, flashs black for another 20 second then eventually changes.

May-be rpi2 B is simply not capable of so many streams?

icebrian commented 2 years ago

So I've just tested with a RaspPi 3 B and flickering is indeed gone. Seems as thou rpi2 is not enough hardware for multiple streams (in this case 8 at 640x480).

Even thou on the rpi3, I however still don't have a perfect experience. Whenever the screen changes I am getting a black screen for about 20-30 seconds, not sure if this is expected given the probe_timeouts but to be honest I was expecting a smoother transition between screens.

SvenVD commented 2 years ago

8 streams is a hit or miss scenario regardless of resolution, due to the way the GPU of the pi works, probably you will see a lot of timeouts in the rpisurv log because the pi is overloaded. I guess the errors and timeouts disappear if you remove one stream?

Whenever the screen changes I am getting a black screen for about 20-30 seconds => duration: 20 is also on the edge to allow for the next screen to startup caching in the back while the other screen is showing, but should be doable in most cases but in combination with the timeouts of the gpu probably causes your described behavior