AlexxIT / go2rtc

Ultimate camera streaming application with support RTSP, RTMP, HTTP-FLV, WebRTC, MSE, HLS, MP4, MJPEG, HomeKit, FFmpeg, etc.
https://github.com/AlexxIT/Blog
MIT License
4.95k stars 397 forks source link

Black Screen Issue with go2rtc on Raspberry Pi 4 #1252

Closed Rhox21 closed 2 months ago

Rhox21 commented 3 months ago

I am experiencing issues with go2rtc on my Raspberry Pi 4. I am running go2rtc version 1.9.4 and using it for an OctoPrint web stream. After an unspecified amount of time, I only get a black screen and have to stop and restart go2rtc via the terminal. This is particularly annoying as I am trying to film time-lapses, and the stream failure disrupts this process. After a failure, the configuration tab is sometimes empty.

Here is my current configuration code:


streams:
   picam_mjpeg: exec:libcamera-vid -t 0  --autofocus-range normal --autofocus-window 0.25,0.25,0.5,0.5 --width 2592 --height 1944 --codec mjpeg --libav-format mpegts -o - --vflip

// log:
    // level: trace

ffmpeg:
  bin: /home/swex/bin/ffmpeg-6.1-amd64-static/ffmpeg

Could you provide some guidance on how to resolve this issue?

Thank you.

Edit: Octoprint runs in docker but the screen from go2rtc webinterface is also black 🤷

AlexxIT commented 3 months ago

You need to collect logs and stream info at the moment of problem.

Rhox21 commented 3 months ago

What happened? The issue has recurred. When I remove the print from the printers bed and my hand is visible in the image, the picture suddenly freezes in OctoPrint. This occurs frequently after removing a completed print from the bed. Refreshing OctoPrint UI in the browser only shows a black image. After restarting via the Go2RTC interface, OctoPrint displays an error message "Webstream not loaded".

Observations: After restarting via the Go2RTC GUI, the following logfile with one error is generated:

Click to show full log > ` > > 15:30:22,839 | trace | [api] GET /api/streams 192.168.2.100:22159 > -- | -- | -- > 15:30:21,816 | trace | [api] GET /api/streams 192.168.2.100:22159 > 15:30:20,813 | trace | [api] GET /api/streams 192.168.2.100:22159 > 15:30:19,804 | trace | [api] GET /api/streams 192.168.2.100:22159 > 15:30:19,704 | trace | [api] GET /api/log 192.168.2.100:22159 > 15:30:18,782 | trace | [api] GET /api/streams 192.168.2.100:22159 > 15:30:17,774 | trace | [api] GET /api/streams 192.168.2.100:22159 > 15:30:16,761 | trace | [api] GET /api/streams 192.168.2.100:22159 > 15:30:16,737 | trace | [api] GET /api/log 192.168.2.100:22159 > 15:30:16,239 | trace | [api] GET /api/streams 192.168.2.100:22159 > 15:30:14,618 | trace | [api] GET /api/streams 192.168.2.100:22159 > 15:30:14,540 | trace | [api] GET /api/log 192.168.2.100:22159 > 15:30:14,448 | trace | [api] GET /main.js 192.168.2.100:22159 > 15:30:14,378 | trace | [api] GET /log.html 192.168.2.100:22159 > 15:30:13,606 | trace | [api] GET /api/streams 192.168.2.100:22159 > 15:30:12,590 | trace | [api] GET /api/streams 192.168.2.100:22159 > 15:30:11,592 | trace | [api] GET /api/streams 192.168.2.100:22159 > 15:30:10,644 | error | [api.mjpeg] add consumer error=streams: exec/pipe: EOF[3:50:08.096369711] [31753]  INFO Camera camera_manager.cpp:313 libcamera v0.3.0+65-6ddd79b5[3:50:08.113080936] [31756] ERROR V4L2 v4l2_device.cpp:353 'imx708': Unable to set controls: Device or resource busy[3:50:08.135992949] [31756]  WARN RPiSdn sdn.cpp:40 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise[3:50:08.138767270] [31756]  INFO RPI vc4.cpp:446 Registered camera /ba... > 15:30:10,644 | trace | [streams] skip stop none producer > 15:30:10,644 | trace | [streams] dial cons=0 prod=0 error=exec/pipe: EOF[3:50:08.096369711] [31753]  INFO Camera camera_manager.cpp:313 libcamera v0.3.0+65-6ddd79b5[3:50:08.113080936] [31756] ERROR V4L2 v4l2_device.cpp:353 'imx708': Unable to set controls: Device or resource busy[3:50:08.135992949] [31756]  WARN RPiSdn sdn.cpp:40 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise[3:50:08.138767270] [31756]  INFO RPI vc4.cpp:446 Registered camera /ba... > 15:30:10,643 | trace | [exec] kill with signal=9 > 15:30:10,632 | debug | [exec] ERROR: *** failed to acquire camera /base/soc/i2c0mux/i2c@1/imx708@1a *** > 15:30:10,631 | debug | [exec] [3:50:08.139683304] [31753]  INFO Camera camera.cpp:990 Pipeline handler in use by another process > 15:30:10,631 | debug | [exec] Preview window unavailable > 15:30:10,630 | debug | [exec] [3:50:08.138767270] [31756]  INFO RPI vc4.cpp:446 Registered camera /base/soc/i2c0mux/i2c@1/imx708@1a to Unicam device /dev/media3 and ISP device /dev/media0[3:50:08.138833474] [31756]  INFO RPI pipeline_base.cpp:1104 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml' > 15:30:10,628 | debug | [exec] [3:50:08.135992949] [31756]  WARN RPiSdn sdn.cpp:40 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise > 15:30:10,604 | debug | [exec] [3:50:08.113080936] [31756] ERROR V4L2 v4l2_device.cpp:353 'imx708': Unable to set controls: Device or resource busy > 15:30:10,588 | debug | [exec] [3:50:08.096369711] [31753]  INFO Camera camera_manager.cpp:313 libcamera v0.3.0+65-6ddd79b5 > 15:30:10,568 | trace | [api] GET /api/streams 192.168.2.100:22159 > 15:30:10,232 | debug | [exec] run pipe args=libcamera-vid,-t,0,--autofocus-range,normal,--autofocus-window,0.25,0.25,0.5,0.5,--width,2592,--height,1944,--codec,mjpeg,--libav-format,h264,-o,-,--vflip,--hflip > 15:30:10,232 | trace | [streams] check cons=0 media=video, sendonly, JPEG, RAW > 15:30:10,231 | trace | [api] GET /api/stream.mjpeg?src=picam_mjpeg 192.168.2.100:22160 > 15:30:09,556 | trace | [api] GET /api/streams 192.168.2.100:22159 > 15:30:08,807 | trace | [api] GET /api/streams 192.168.2.100:22159 > 15:30:08,667 | trace | [api] register path path=/api/stack > 15:30:08,667 | trace | [api] register path path=/api/gopro > 15:30:08,667 | trace | [api] register path path=/api/nest > 15:30:08,667 | trace | [api] register path path=/api/homekit > 15:30:08,667 | trace | [api] register path path=/api/roborock > 15:30:08,667 | trace | [api] register path path=/api/stream.aac > 15:30:08,667 | trace | [api] register path path=/api/stream.ts > 15:30:08,667 | trace | [api] register path path=/api/dvrip > 15:30:08,667 | trace | [api] register path path=/api/stream > 15:30:08,667 | trace | [api] register path path=/api/ffmpeg/hardware > 15:30:08,667 | trace | [api] register path path=/api/ffmpeg/devices > 15:30:08,667 | trace | [api] register path path=/api/ffmpeg > 15:30:08,666 | trace | [api] register path path=/api/stream.flv > 15:30:08,666 | trace | [api] register path path=/api/webtorrent > 15:30:08,666 | trace | [api] register path path=/api/onvif > 15:30:08,666 | trace | [api] register path path=/onvif/ > 15:30:08,666 | trace | [api] register path path=/api/hass > 15:30:08,666 | trace | [hass] can't import config: open .storage/core.config_entries: no such file or directory > 15:30:08,666 | trace | [api] register path path=/stream/ > 15:30:08,666 | trace | [api] register path path=/streams > 15:30:08,666 | trace | [api] register path path=/static > 15:30:08,666 | trace | [api] register path path=/api/stream.y4m > 15:30:08,666 | trace | [api] register path path=/api/stream.ascii > 15:30:08,666 | trace | [api] register path path=/api/stream.mjpeg > 15:30:08,666 | trace | [api] register path path=/api/frame.jpeg > 15:30:08,665 | trace | [api] register path path=/api/hls/segment.m4s > 15:30:08,665 | trace | [api] register path path=/api/hls/init.mp4 > 15:30:08,665 | trace | [api] register path path=/api/hls/segment.ts > 15:30:08,665 | trace | [api] register path path=/api/hls/playlist.m3u8 > 15:30:08,665 | trace | [api] register path path=/api/stream.m3u8 > 15:30:08,665 | trace | [api] register path path=/api/stream.mp4 > 15:30:08,665 | trace | [api] register path path=/api/frame.mp4 > 15:30:08,665 | trace | [api] register path path=/api/webrtc > 15:30:08,665 | info | [webrtc] listen addr=:8555/tcp > 15:30:08,665 | info | [api] listen addr=:1984 > 15:30:08,665 | info | [rtsp] listen addr=:8554 > 15:30:08,664 | trace | [api] register path path=/api/streams.dot > 15:30:08,664 | trace | [api] register path path=/api/streams > 15:30:08,664 | trace | [api] register path path=/api/ws > 15:30:08,664 | trace | [api] register path path=/api/log > 15:30:08,664 | trace | [api] register path path=/api/restart > 15:30:08,664 | trace | [api] register path path=/api/exit > 15:30:08,664 | trace | [api] register path path=/api/config > 15:30:08,664 | trace | [api] register path path=/api > 15:30:08,664 | trace | [api] register path path=/ > 15:30:08,663 | info | config path=/usr/local/bin/go2rtc/go2rtc.yaml > 15:30:08,663 | debug | build version=go1.22.4 vcs.time=2024-06-18T18:33:36Z > 15:30:08,663 | info | go2rtc version=1.9.4 platform=linux/arm64 revision=a4885c2 > > > > ` >

Current Workaround: To get the camera running again, I had to restart using the terminal commands stop go2rctc and start go2rctc. After this, the camera works again in OctoPrint.

Suspected Cause: The logs suspected that the camera is being claimed by another service. Running sudo lsof /dev/video0 and sudo kill PID restores the stream also in OctoPrint.

grafik

Webcam works after restarting Go2RTC or using corresponding terminal commands grafik

Additional Info:

PRETTY_NAME="Debian GNU/Linux 12 (bookworm)" NAME="Debian GNU/Linux" VERSION_ID="12" VERSION="12 (bookworm)" VERSION_CODENAME=bookworm ID=debian

Octoprint Settings Stream URL: http://192.168.2.117:1984/api/stream.mjpeg?src=picam_mjpeg Snapshot-URL: http://192.168.2.117:1984/api/frame.jpeg?src=picam_mjpeg

TLDR: The issue occurs when the hand is visible in the image after removing a print from the bed, causing the image to freeze in OctoPrint and resulting in webcam failure. The camera is likely being claimed by another service, temporarily resolved by restarting Go2RTC or using corresponding terminal commands.

I would like to determine whether the issue lies with Go2RTC or another program that may be monopolizing the camera. Any assistance would be appreciated because manually restarting is soo annoying.

Rhox21 commented 3 months ago

The Error came again just after i started a print and my hand was in the image. Over the night it was stable. This is the log when the error occurs:

grafik

Currently 7 streams but i dont have image in stream. grafik

grafik

http://192.168.2.117:1984/stream.html?src=picam_mjpeg shows only: grafik

Rhox21 commented 2 months ago

@AlexxIT Issue can be closed. Found the problem: i removed the autofocus option from the config file.

streams: picam_mjpeg: exec:libcamera-vid --width 2592 --height 1944 --codec mjpeg --libav-format mpegts -o - --vflip --hflip