Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTMP push from OpenIPC web camera doesn't work (while RTSP pull with the same audio/video settings works) #1354

Open
MalgathThelamin opened this issue Sep 16, 2024 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@MalgathThelamin
Copy link

I am using go2rtc version 1.9.4 on Debian Bookworm arm64.

Issue description

I push an RTMP stream from my camera (102.168.0.188, running OpenIPC) to go2rtc (192.168.0.2).
However, http://192.168.0.2:1984/stream.html?src=mystream shows black video player with webrtc/offer: stream not found message.

If I stop the video pushing from the camera and configure go2rtc to pull the video from the camera via RTSP protocol, the player shows video normally.

How to replicate the issue

  1. Configure an OpenIPC camera to push RTMP stream to rtmp://[go2rtc IP]/mystream (Majestic > Settings > Outgoing)
  2. Run go2rtc.
  3. Open http://[go2rtc IP]:1984/stream.html?src=mystream with your browser.

Files

go2rtc.yaml

rtmp:
  listen: ":1935"
log:
  level: trace
  api: trace
  exec: trace
  ngrok: trace
  rtsp: trace
  streams: trace
  webrtc: trace

go2rtc.log

11:04:56.565 INF go2rtc platform=linux/arm64 revision=a4885c2 version=1.9.4
11:04:56.565 DBG build vcs.time=2024-06-18T18:33:36Z version=go1.22.4
11:04:56.565 INF config path=/home/pi/Downloads/go2rtc/go2rtc.yaml
11:04:56.565 TRC [api] register path path=/
11:04:56.565 TRC [api] register path path=/api
11:04:56.566 TRC [api] register path path=/api/config
11:04:56.566 TRC [api] register path path=/api/exit
11:04:56.566 TRC [api] register path path=/api/restart
11:04:56.566 TRC [api] register path path=/api/log
11:04:56.566 TRC [api] register path path=/api/ws
11:04:56.566 TRC [api] register path path=/api/streams
11:04:56.566 TRC [api] register path path=/api/streams.dot
11:04:56.566 INF [rtsp] listen addr=:8554
11:04:56.566 INF [api] listen addr=:1984
11:04:56.567 INF [webrtc] listen addr=:8555/tcp
11:04:56.567 TRC [api] register path path=/api/webrtc
11:04:56.567 TRC [api] register path path=/api/frame.mp4
11:04:56.567 TRC [api] register path path=/api/stream.mp4
11:04:56.567 TRC [api] register path path=/api/stream.m3u8
11:04:56.567 TRC [api] register path path=/api/hls/playlist.m3u8
11:04:56.567 TRC [api] register path path=/api/hls/segment.ts
11:04:56.567 TRC [api] register path path=/api/hls/init.mp4
11:04:56.567 TRC [api] register path path=/api/hls/segment.m4s
11:04:56.567 TRC [api] register path path=/api/frame.jpeg
11:04:56.567 TRC [api] register path path=/api/stream.mjpeg
11:04:56.567 TRC [api] register path path=/api/stream.ascii
11:04:56.567 TRC [api] register path path=/api/stream.y4m
11:04:56.568 TRC [api] register path path=/static
11:04:56.568 TRC [api] register path path=/streams
11:04:56.568 TRC [api] register path path=/stream/
11:04:56.568 TRC [hass] can't import config: open .storage/core.config_entries: no such file or directory
11:04:56.568 TRC [api] register path path=/api/hass
11:04:56.568 TRC [api] register path path=/onvif/
11:04:56.568 TRC [api] register path path=/api/onvif
11:04:56.568 TRC [api] register path path=/api/webtorrent
11:04:56.569 TRC [api] register path path=/api/stream.flv
11:04:56.569 INF [rtmp] listen addr=:1935
11:04:56.569 TRC [api] register path path=/api/ffmpeg
11:04:56.569 TRC [api] register path path=/api/ffmpeg/devices
11:04:56.569 TRC [api] register path path=/api/ffmpeg/hardware
11:04:56.569 TRC [api] register path path=/api/stream
11:04:56.569 TRC [api] register path path=/api/dvrip
11:04:56.569 TRC [api] register path path=/api/stream.ts
11:04:56.569 TRC [api] register path path=/api/stream.aac
11:04:56.569 TRC [api] register path path=/api/roborock
11:04:56.570 TRC [api] register path path=/api/homekit
11:04:56.570 TRC [api] register path path=/api/nest
11:04:56.570 TRC [api] register path path=/api/gopro
11:04:56.570 TRC [api] register path path=/api/stack
11:04:58.949 ERR github.com/AlexxIT/go2rtc/internal/rtmp/rtmp.go:61 > error="rtmp: read command 020007636f6e6e656374003ff000000000000003000361707002000000047479706502000a6e6f6e70726976617465000e737570706f727473476f417761790101000673776655726c02001272746d703a2f2f3139322e3136382e302e320005746355726c02001272746d703a2f2f3139322e3136382e302e32000009"
11:05:05.080 TRC [api] GET /stream.html?src=mystream 192.168.1.205:60086
11:05:05.121 TRC [api] GET /video-stream.js 192.168.1.205:60086
11:05:05.151 TRC [api] GET /video-rtc.js 192.168.1.205:60086
11:05:05.171 TRC [api] GET /api/ws?src=mystream 192.168.1.205:60088
11:05:05.218 TRC [api] ws msg type=webrtc/offer
11:05:05.218 DBG [webrtc] new consumer src=mystream
11:05:05.220 TRC [api] ws msg type=webrtc/candidate
11:05:05.221 TRC [webrtc] remote candidate="candidate:2361374035 1 udp 2113937151 9db8c05c-e170-4953-91bb-00454645d45a.local 56158 typ host generation 0 ufrag Onko network-cost 999"
11:05:06.637 TRC [api] ws msg type=mse
11:05:06.640 TRC [api] ws msg type=mjpeg
@AlexxIT AlexxIT added the bug Something isn't working label Sep 16, 2024
@AlexxIT AlexxIT self-assigned this Sep 16, 2024
@AlexxIT
Copy link
Owner

AlexxIT commented Sep 16, 2024

11:04:58.949 ERR github.com/AlexxIT/go2rtc/internal/rtmp/rtmp.go:61 > error="rtmp: read command 020007636f6e6e656374003ff000000000000003000361707002000000047479706502000a6e6f6e70726976617465000e737570706f727473476f417761790101000673776655726c02001272746d703a2f2f3139322e3136382e302e320005746355726c02001272746d703a2f2f3139322e3136382e302e32000009"

@MalgathThelamin
Copy link
Author

@AlexxIT, do you mean that the problem is on the camera side?

@AlexxIT
Copy link
Owner

AlexxIT commented Sep 16, 2024

I don't know. RTMP awful legacy protocol. I need to check what inside this message.

@MalgathThelamin
Copy link
Author

MalgathThelamin commented Sep 17, 2024

This message is encoded in AMF0 format and represents the following data:

"connect"
1.0
{
	"app": "",
	"type": "nonprivate",
	"supportsGoAway": true,
	"swfUrl": "rtmp://192.168.0.2",
	"tcUrl": "rtmp://192.168.0.2"
}
Decoding details
02 - String
0007 - Length
636f6e6e656374 - "connect"

00 - Double
3ff0000000000000 - 1.0

03 - Object
0003 - Length
617070 - "app"
	02 - String
	0000 - Length
0004 - Length
74797065 - "type"
	02 - String
	000a - Length
	6e6f6e70726976617465 - "nonprivate"
000e - Length
737570706f727473476f41776179 - "supportsGoAway"
	01 - Boolean
	01 - True
0006 - Length
73776655726c - "swfUrl"
	02 - String
	0012 - Length
	72746d703a2f2f3139322e3136382e302e32 - "rtmp://192.168.0.2"
0005 - Length
746355726c - "tcUrl"
	02 - String
	0012 - Length
	72746d703a2f2f3139322e3136382e302e32 - "rtmp://192.168.0.2"
0000 - Empty length
09 - Object end

@MalgathThelamin
Copy link
Author

MalgathThelamin commented Sep 18, 2024

@AlexxIT, the error is being raised in https://github.com/AlexxIT/go2rtc/blob/master/pkg/rtmp/server.go:120

		if c.App == "" {
			return fmt.Errorf("rtmp: read command %x", b)
		}

The app field is "" in the message (see my previous comment). The camera sends the RTMP stream to an URL without an application name: rtmp://192.168.0.2/mystream. This is because the documentation says so. The URL with an application name would be, for example, rtmp://192.168.0.2/myapp/mystream.

Later in https://github.com/AlexxIT/go2rtc/blob/master/internal/rtmp/rtmp.go:80 you use the app name as a stream name:

		stream := streams.Get(rtmpConn.App)
		if stream == nil {
			return errors.New("stream not found: " + rtmpConn.App)
		}

I tried to push the video to rtmp://192.168.0.2/mystream/mystream, but I still got an error: stream not found: mystream.

@AlexxIT
Copy link
Owner

AlexxIT commented Sep 20, 2024

"stream not found" - because you haven't created it manually in config:
https://github.com/AlexxIT/go2rtc?tab=readme-ov-file#incoming-sources

@MalgathThelamin
Copy link
Author

MalgathThelamin commented Sep 20, 2024

My go2rtc.yaml is:

streams:
  mystream
rtmp:
  listen: ":1935"
log:
  level: trace
  api: trace
  exec: trace
  ngrok: trace
  rtsp: trace
  streams: trace
  webrtc: trace

I stream to rtmp://192.168.0.2/mystream/mystream.

I get an error:

18:10:49.018 ERR github.com/AlexxIT/go2rtc/internal/rtmp/rtmp.go:61 > error="stream not found: mystream"

What am I doing wrong?

@MalgathThelamin
Copy link
Author

By the way, how do you create a log file, not only display the log information on the screen?

@AlexxIT
Copy link
Owner

AlexxIT commented Sep 20, 2024

You need ":" after stream name. YAML rules

@MalgathThelamin
Copy link
Author

Thank you! Now I can see the stream in the go2rtc console.

Please note, that even without :, it is a valid YAML. Please consider adding an example of what you mean by stream with empty source to the documentation.

It seems that the correct URL to push RTMP to is rtmp://192.168.0.2/mystream/anything, where anything means really anything. If I am right, please consider adding it to the documentation.

Unfortunately, the stream shows up, but does not play in the go2rtc console. The built-in player shows mse: streams: unknown error.

Please see the attached go2rtc.log.

@AlexxIT
Copy link
Owner

AlexxIT commented Sep 22, 2024

Try to get stream info for active stream. I can't see any codecs information for your stream in logs.

@MalgathThelamin
Copy link
Author

{
  "producers": [
    {
      "id": 16,
      "format_name": "rtmp",
      "protocol": "rtmp",
      "remote_addr": "192.168.0.188:57012",
      "bytes_recv": 22970920
    }
  ],
  "consumers": null
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants