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
3.76k stars 305 forks source link

connect to RTMP server after handshake, but get EOF error #1109

Open Danrry opened 1 month ago

Danrry commented 1 month ago

Hi: I am using go2rtc lib with verison 1.9.1,to connect rtmp server for getting the video stream data. but I got the network error[EOF].

So I debug the code to find the error position. By learning RTMP protocol, I find there is no response data when sending the connection description to server after handshake stage. I don't know why it happens. Here is the code:

    rtmpURL := "rtmp://xxx:xxx/live/openUrl/WabN53"
    client, err := rtmp.DialPlay(rtmpURL)
    if err != nil {
        panic(err)
    }
    ret := client.GetMedias()
    fmt.Printf("%v\n", ret)

Debuging the further code, I find the first step of c.clienHandshake() is ok. The next step c.writePacketSize() is also ok. But the third step c.writeConnect() failed. After c.writeMessage(3, TypeCommand, 0, b) step, the error position is at c.readResponse(1).

func (c *Conn) writeConnect() error {
       b := amf.EncodeItems("connect", 1, map[string]any{
        "app":      c.App,
            "flashVer": "LNX 9,0,124,2",
            "tcUrl": c.url,
            "fpad":  false,
            "capabilities": 15,
            "audioCodecs": 4071,
            "videoCodecs": 252,
            "videoFunction": 1
    })
    if err := c.writeMessage(3, TypeCommand, 0, b); err != nil {
        return err
    }

    v, err := c.readResponse(1)

        ... ...
}

Looking forward to your replies~

AlexxIT commented 1 month ago

I don't understand where your get this code. Go2rtc don't have it.

Danrry commented 1 month ago

Thank you for your replies. I am sorry to make you misunderstand.

The first part codes above are written in my project. The main intention is to access the remote RTMP server and get media information by creating RTMP client. They are from Go2rtc library at line 14: https://github.com/AlexxIT/go2rtc/blob/master/pkg/rtmp/client.go

The second part codes is in the further debug, which are from file at line 84 and 118: https://github.com/AlexxIT/go2rtc/blob/master/pkg/rtmp/client.go. The connecting stage of RTMP protocol is realized in the file at line 230: https://github.com/AlexxIT/go2rtc/blob/master/pkg/rtmp/conn.go . At first, I got EOF error after running the origin code. I doubted whether I missed some key information during the connecting stage. So I modified the sending description data, adding some fields. But it doesn't work.

I don't know why it happens. I check the codes and functions according to the RTMP protocol, including handshake, connection etc. But the server does not repsonse the expected message of "_result" command type . In contrast, I get the EOF error from network. Could you give me some suggestion?

AlexxIT commented 1 month ago

I can't be responsible for your code. There may be errors in it.