Monibuca / plugin-rtmp

RTMP协议插件,提供RTMP协议的server功能:接收rtmp推流和rtmp的播放功能
MIT License
94 stars 51 forks source link

support rtmps ? #16

Closed eduardotang closed 1 year ago

eduardotang commented 1 year ago

if not, can this be considered?

langhuihui commented 1 year ago

not supported yet. if you can do this, welcome a PR

eduardotang commented 1 year ago

i have tried my best, but it didnt seem to work........... snippet from NewRTMPClient in client.go, basically just create the tls connection and change NetConnection to take net.Conn instead of *net.TCPConn

the log show connect success and publish start, so i assume the connection is ok??

isRtmps := u.Scheme == "rtmps"
if strings.Count(u.Host, ":") == 0 {
  if isRtmps {
      u.Host += ":443"
  } else {
      u.Host += ":1935"
  }
}
var conn net.Conn
if isRtmps {
  conn, err = tls.Dial("tcp", u.Host, &tls.Config{})
} else {
  conn, err = net.Dial("tcp", u.Host)
}
if err != nil {
  RTMPPlugin.Error("dial tcp", zap.String("host", u.Host), zap.Error(err))
  return nil, err
}
client = &NetConnection{
  Conn:               conn,
  Reader:             bufio.NewReader(conn),
  writeChunkSize:     conf.ChunkSize,
  readChunkSize:      RTMP_DEFAULT_CHUNK_SIZE,
  rtmpHeader:         make(map[uint32]*ChunkHeader),
  incompleteRtmpBody: make(map[uint32]*util.Buffer),
  bandwidth:          RTMP_MAX_CHUNK_SIZE << 3,
  tmpBuf:             make([]byte, 4),
}

13:07:49 INFO connect {"plugin": "RTMP", "appName": "live", "objectEncoding": 0} 13:07:49 INFO decode command amf0 {"plugin": "RTMP", "cmd": "FCPublish"} 13:07:49 INFO createStream: {"plugin": "RTMP", "streamId": 1} 13:07:49 INFO publish {"plugin": "RTMP", "path": "live/test"} 13:07:49 INFO created {"stream": "live/test"} 13:07:49 INFO ⌛->🟢 {"stream": "live/test", "action": "publish"} 13:07:49 INFO push {"plugin": "RTMP", "path": "live/test", "url": "rtmps://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} 13:07:49 INFO subscribe {"plugin": "HLS", "path": "live/test"} 13:07:49 INFO start push {"plugin": "RTMP", "path": "live/test", "url": "rtmps://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} 13:07:49 INFO suber +1 {"stream": "live/test", "type": "HLSWriter", "remains": 1} 13:07:49 INFO subscribe {"plugin": "RTMP", "path": "live/test"} 13:07:49 INFO suber +1 {"stream": "live/test", "type": "RTMPPusher", "remains": 2} 13:07:51 INFO track +1 {"stream": "live/test", "name": "h264"} 13:07:51 INFO track+1 {"stream": "live/test", "type": "HLSWriter", "name": "h264"} 13:07:51 INFO track+1 {"stream": "live/test", "type": "RTMPPusher", "name": "h264"} 13:07:59 INFO playblock {"stream": "live/test", "type": "HLSWriter"} 13:07:59 INFO firstIFrame {"stream": "live/test", "type": "HLSWriter", "seq": 0} 13:07:59 INFO _result : {"plugin": "RTMP", "code": "NetConnection.Connect.Success"} 13:07:59 INFO connect {"plugin": "RTMP", "remoteURL": "rtmps://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} 13:07:59 INFO _result : {"plugin": "RTMP", "code": "NetStream.Publish.Start"} 13:07:59 INFO playblock {"stream": "live/test", "type": "RTMPPusher"} 13:07:59 INFO firstIFrame {"stream": "live/test", "type": "RTMPPusher", "seq": 0}

langhuihui commented 1 year ago

it seems you what to relay rtmp to rtmps? and handshake was succeed…… I can't find out what is wrong. first of all, make sure push rtmp is ok.

eduardotang commented 1 year ago

it seems you what to relay rtmp to rtmps? and handshake was succeed…… I can't find out what is wrong. first of all, make sure push rtmp is ok.

yes, and the push rtmp works, have successfully viewed it in /preview/live/test using http-flv

and i have just tested with youtube rtmps, it is not working either and the log show Publish.Start as well, so is it rtmp to rtmps relay problem??

14:18:19 INFO _result : {"plugin": "RTMP", "code": "NetConnection.Connect.Success"} 14:18:19 INFO connect {"plugin": "RTMP", "remoteURL": "rtmps://a.rtmps.youtube.com/live2/xxxxxxxxxxxxxxxxxx"} 14:18:19 INFO decode command amf0 {"plugin": "RTMP", "cmd": "onBWDone"} 14:18:20 INFO _result : {"plugin": "RTMP", "code": "NetStream.Publish.Start"} 14:18:20 INFO playblock {"stream": "live/test2", "type": "RTMPPusher"} 14:18:20 INFO firstIFrame {"stream": "live/test2", "type": "RTMPPusher", "seq": 0}

langhuihui commented 1 year ago

you what to push rtmps to youtube?

eduardotang commented 1 year ago

you what to push rtmps to youtube?

no , i just want to make sure its not the problem of the rtmps server

langhuihui commented 1 year ago

so how do you know it's not working

eduardotang commented 1 year ago

when you try to do live in youtube , it has a preview of the stream but i dont see it.............

langhuihui commented 1 year ago

maybe it has nothing to do with tls. or there are bugs in pushing rtmp to other server. I need check it

eduardotang commented 1 year ago

i am using ffmpeg to pull rtsp and push to rtmp

ffmpeg -i rtsp://.................... -c:v libx264 -an -f flv rtmp://xxxxxxxxxxxxxxxxxxxx/live/test
langhuihui commented 1 year ago

receving rtmp is not the problem

eduardotang commented 1 year ago

just FYI, as i can see in /preview , i guess receiving should be fine

i am using ffmpeg to pull rtsp and push to rtmp

ffmpeg -i rtsp://.................... -c:v libx264 -an -f flv rtmp://xxxxxxxxxxxxxxxxxxxx/live/test
langhuihui commented 1 year ago

maybe something wrong with pushing rtmp to other servers

eduardotang commented 1 year ago

ok, more findings, but dont know whether it is related

i use another client which i am sure it works with rtmps but i got below exception if i change it to push to monibuca rtmp

panic: interface conversion: rtmp.AMFValue is *struct {}, not float64

goroutine 43 [running]:
m7s.live/plugin/rtmp/v4.(*RTMPConfig).ServeTCP(0x1c1fdc0, 0xc000014028)
        /go/monibuca/workspace/plugin-rtmp/server.go:75 +0x1c1f
created by m7s.live/engine/v4/config.(*TCP).listen
        /go/monibuca/workspace/engine/config/tcp.go:39 +0xf8
exit status 2
langhuihui commented 1 year ago

i see,objectEncoding prop should be float64. However it got something else

langhuihui commented 1 year ago

i fixed it.

objectEncoding := cmd.Object["objectEncoding"] // AMF编码方法
    switch v := objectEncoding.(type) {
    case float64:
        nc.objectEncoding = v
    default:
        nc.objectEncoding = 0
    }
eduardotang commented 1 year ago

i fixed it.

objectEncoding := cmd.Object["objectEncoding"] // AMF编码方法
  switch v := objectEncoding.(type) {
  case float64:
      nc.objectEncoding = v
  default:
      nc.objectEncoding = 0
  }

FYI, this another client works , after you fixed above, but ffmpeg doesnt, weird, hope u have time look into it

langhuihui commented 1 year ago

i confused. ffmpeg doesn't work means what?

eduardotang commented 1 year ago

what i mean is , when i use another client, to push rtmp, it can successfully relay to rtmps but if i push to rtmp with below ffmpeg command, the streaming does not work.....

ffmpeg -re -i rtsp://xxxxxxx -c:v libx264 -f flv rtmp://localhost/live/test

config.yaml

rtmp:
  push:
      push: -1
      pushlist:
          live/test: rtmps://abcd.com/app/key

when i use another client to push to rtmp://localhost/live/test i can see the stream at rtmps://abcd.com/app/key

so maybe let me submit the PR, and close this issue it seems that the ffmpeg convert from rtsp to rtmp has problem but is out of scope of this issue.

langhuihui commented 1 year ago

ok, i agree

eduardotang commented 1 year ago

ok, please review #17