WebRTC stream from RTSPtoWeb is not playing

What is the problem?

I'm trying to use RTSPtoWeb (GitHub - deepch/RTSPtoWeb: RTSP Stream to WebBrowser) to use my RTSP stream from my IP cam as WebRTC in OctoPrint but with no luck... WebRTC stream from RTSPtoWeb is working - when I access it from demo page with Chrome, but when I use webrtc://demo:demo@octopi.groch.lan:8083/stream/Groch-CAM2/channel/0/webrtc URL in OctoPrint and test it, I can see only browser WebRTC player playing nothing... I can see error in RTSPtoWeb log when trying to play WebRTC through OctoPrint:

[GIN] 2022/05/26 - 08:54:16 | 204 |          74ยตs |   192.168.1.197 | OPTIONS  "/stream/Groch-CAM2/channel/0/webrtc"
INFO[2022-05-26T08:54:16+02:00] Run stream                                    call=Run channel=0 func=StreamServerRunStreamDo module=core stream=Groch-CAM2
INFO[2022-05-26T08:54:17+02:00] Success connection RTSP                       call=Start channel=0 func=StreamServerRunStream module=core stream=Groch-CAM2
2022/05/26 08:54:17 Set ICEServers [stun:stun.l.google.com:19302]
ERRO[2022-05-26T08:54:17+02:00] SetRemoteDescription called with no ice-ufrag  call=WriteHeader channel=0 func=HTTPAPIServerStreamWebRTC module=http_webrtc stream=Groch-CAM2
[GIN] 2022/05/26 - 08:54:17 | 400 |  829.242677ms |   192.168.1.197 | POST     "/stream/Groch-CAM2/channel/0/webrtc"
INFO[2022-05-26T08:54:57+02:00] Stream exit by signal or not client           call=StreamServerRunStream channel=0 func=StreamServerRunStreamDo module=core stream=Groch-CAM2

What did you already try to solve it?

I've tried to change various RTSPtoWeb options in configuration without luck...

Have you tried running in safe mode?

No matters

Did running in safe mode solve the problem?

No matters

Systeminfo Bundle

You can download this in OctoPrint's System Information dialog ... no bundle, no support!)

browser.user_agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36
connectivity.connection_check : 1.1.1.1:53
connectivity.connection_ok : true
connectivity.enabled : true
connectivity.online : true
connectivity.resolution_check : octoprint.org
connectivity.resolution_ok : true
env.hardware.cores : 1
env.hardware.freq : 1000
env.hardware.ram : 386322432
env.os.bits : 32
env.os.id : linux
env.os.platform : linux
env.plugins.pi_support.model : Raspberry Pi Zero W Rev 1.1
env.plugins.pi_support.octopi_version : 0.18.0
env.plugins.pi_support.throttle_state : 0x0
env.python.pip : 20.3.3
env.python.version : 3.7.3
env.python.virtualenv : true
octoprint.last_safe_mode.date : unknown
octoprint.last_safe_mode.reason : unknown
octoprint.safe_mode : false
octoprint.version : 1.8.1
printer.firmware : Marlin 1.1.9.1 (Github)
systeminfo.generated : 2022-05-26T08:41:34Z
systeminfo.generator : systemapi

Additional information about your setup

OctoPrint version, OctoPi version, printer, firmware, browser, operating system, ... as much data as possible

All can be seen in systembundle above

At the moment, the only webrtc stream that works (as far as I know) is one provided by aiortc. This is what the implementation was based around.

This limitation is because there is no standard signalling protocol to setup the stream. In the RTSPtoWeb repository it has the source to the demo page, which you can find some of the JS code it uses to connect the stream:

We intend to create a proper plugin interface for the webcam streaming setup to make it really easy for people to add support for other streaming types in the future. My current recommendation is to either create a custom plugin to stream on a separate tab for example, adapting the demo code they provided or, if you don't mind the latency, switch to HLS streaming as that should be a common standard.

I did just think of one other option - embedding the RTSPtoWeb demo page in an iframe:

I do also have it on my list to create a proper guide/add to the documentation a part about OctoPrint and webcam streaming but have not yet had time.

OK, thanks... So I've used same RTSPtoWeb server but with hlsll output used in OctoPrint webcam url. It works OK for now. I will be checking time to time in future OctoPrint versions if WebRTC support is fixed

You might have better luck in the meantime with rtsp2mjpg based on other comments I've seen recently.

I will stay with RTSPtoWeb, becouse it is doing no re-encodig - h.264 stream is untouched, just transport is changed. Rtsp2mjpg will do recompression what is not acceptable on my RPI Zero OctoPi :wink:

That makes sense and is how I was using restreamer for HLS.

Hello. I share your interest in RTSPtoWeb for its small footprint and minimal CPU usage. can you elaborate on how you went about making this work? I am able to host the web server and see the streams at http://MYIP:8083, but haven't been able to show the stream in octoprint from there. thanks!

assuming you updated your stream URL in OctoPrint's settings, it may be related to browser security. how are you accessing your OctoPrint instance? if the address starts with https:// rather than http:// then it could block the cross-site access (CORS). If that is the case you'll see an error in the developer tools console tab in your browser on initial page load or when you go to the control tab.

one other possibility is the webserver doesn't like cache busters and there's an option in webcam settings you can turn off to disable that in OctoPrint under the advanced options.

Couse WebRTC doesn't work yet, I'm using HLS-LL stream, in OctoPrint as Stream URL:

http://user:pass@my_webrtc_url:8083/stream/Groch-CAM2/channel/0/hls/live/index.m3u8

WebRTC config.json looks like:

{
  "server": {
    "debug": false,
    "http_debug": false,
    "http_demo": false,
    "http_login": "user",
    "http_password": "pass",
    "http_port": ":8083",
    "ice_servers": ["stun:stun.l.google.com:19302"],
    "log_level": "debug"
  },
  "streams": {
    "Groch-CAM2": {
      "channels": {
        "0": {
          "url": "rtsp://my_webcam_url",
          "debug": false,
          "audio": false,
          "on_demand": true
        }
      },
      "name": "Groch-CAM2"
    }
  }
}

thanks for the advice. seems that for me, using jneilliii's Webcam Iframe plugin (thanks!) with the RTSPtoWeb (Http://IP:8083/pages/player/webrtc/CAM_ID/0 as the URL) works best for me. I do have to occasionally scroll in the Iframe, but it gives we almost no latency and minimal CPU usage. I have been running RTSPtoWeb on a separate pi4 that is on ethernet, again to keep the CPU usage of my PiZero2 running octoprint to a minimum.