q191201771 / lal

🔥 Golang audio/video live streaming lib/client/server. support RTMP, RTSP(RTP/RTCP), HLS, HTTP[S]/WebSocket-FLV/TS, GB28181, H264/H265/AAC/G711/OPUS, relay, cluster, record, HTTP Notify/API/UI. 直播
https://pengrl.com/lal
MIT License
2.78k stars 468 forks source link

RTSP-H265拉流问题 #41

Closed ourfor-pp closed 3 years ago

ourfor-pp commented 3 years ago

使用pullrtsp.go与pullrtsp2pushrtmp.go两个demo进行测试

1.大华网络摄像头 H265的rtsp流拉流错误

日志:

2020/12/21 11:35:00.029883  INFO [RTSPPULL1] lifecycle new rtsp PullSession. session=0xc00014e000 - client_pull_session.go:80
2020/12/21 11:35:00.029883 DEBUG [RTSPPULL1] > tcp connect. - client_pull_session.go:182
2020/12/21 11:35:00.033872 DEBUG [RTSPPULL1] > write options. - client_pull_session.go:199
2020/12/21 11:35:00.040853 DEBUG [RTSPPULL1] < read response. 200 - client_pull_session.go:207
2020/12/21 11:35:00.040853 DEBUG [RTSPPULL1] > write describe. - client_pull_session.go:214
2020/12/21 11:35:00.085734 DEBUG [RTSPPULL1] < read response. code=200, body=v=0
o=- 2252316233 2252316233 IN IP4 0.0.0.0
s=Media Server
c=IN IP4 0.0.0.0
t=0 0
a=control:*
a=packetization-supported:DH
a=rtppayload-supported:DH
a=range:npt=now-
m=video 0 RTP/AVP 98
a=control:trackID=0
a=framerate:25.000000
a=rtpmap:98 H265/90000
a=fmtp:98 profile-id=1;sprop-sps=QgEBAWAAAAMAsAAAAwAAAwBaoAWCAJBY2uSTL5A=;sprop-pps=RAHA8vA8kA==;sprop-vps=QAEMAf//AWAAAAMAsAAAAwAAAwBarAk=
a=recvonly
 - client_pull_session.go:222
2020/12/21 11:35:00.085734 ERROR lal.sdp: fxxk - pullrtsp.go:64

原因初步定位

image

2.简单修改第一个问题后,尝试拉流,继续出现异常

日志

2020/12/21 11:33:43.594242  INFO [RTSPPULL1] lifecycle new rtsp PullSession. session=0xc00014e000 - client_pull_session.go:80
2020/12/21 11:33:43.595239 DEBUG [RTSPPULL1] > tcp connect. - client_pull_session.go:182
2020/12/21 11:33:43.600226 DEBUG [RTSPPULL1] > write options. - client_pull_session.go:199
2020/12/21 11:33:43.630146 DEBUG [RTSPPULL1] < read response. 200 - client_pull_session.go:207
2020/12/21 11:33:43.630146 DEBUG [RTSPPULL1] > write describe. - client_pull_session.go:214
2020/12/21 11:33:43.721901 DEBUG [RTSPPULL1] < read response. code=200, body=v=0
o=- 2252316157 2252316157 IN IP4 0.0.0.0
s=Media Server
c=IN IP4 0.0.0.0
t=0 0
a=control:*
a=packetization-supported:DH
a=rtppayload-supported:DH
a=range:npt=now-
m=video 0 RTP/AVP 98
a=control:trackID=0
a=framerate:25.000000
a=rtpmap:98 H265/90000
a=fmtp:98 profile-id=1;sprop-sps=QgEBAWAAAAMAsAAAAwAAAwBaoAWCAJBY2uSTL5A=;sprop-pps=RAHA8vA8kA==;sprop-vps=QAEMAf//AWAAAAMAsAAAAwAAAwBarAk=
a=recvonly
 - client_pull_session.go:222
2020/12/21 11:33:43.722898 DEBUG [RTSPPULL1] > write setup. - client_pull_session.go:257
2020/12/21 11:33:43.756807 DEBUG [RTSPPULL1] < read response. code=200, ctx={Version:RTSP/1.0 StatusCode:200 Reason:OK Headers:map[CSeq:3 Session:377976728209;timeout=60 Transport:RTP/AVP/UDP;unicast;client_port=8000-8001;server_port=33634-33635;ssrc=42D34B52 x-Dynamic-Rate:1] Body:[]} - client_pull_session.go:265
2020/12/21 11:33:43.756807 DEBUG [RTSPPULL1] > write play. - client_pull_session.go:302
2020/12/21 11:33:43.804679 DEBUG [RTSPPULL1] < read response. 200 - client_pull_session.go:310
2020/12/21 11:33:43.881474 ERROR unknown nalu type. outerNALUType=32 - rtp_unpacker_hevc.go:76
2020/12/21 11:33:43.881474 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246
2020/12/21 11:33:43.881474 ERROR unknown nalu type. outerNALUType=33 - rtp_unpacker_hevc.go:76
2020/12/21 11:33:43.881474 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246
2020/12/21 11:33:43.881474 ERROR unknown nalu type. outerNALUType=34 - rtp_unpacker_hevc.go:76
2020/12/21 11:33:43.881474 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246
2020/12/21 11:33:43.881474 ERROR unknown nalu type. outerNALUType=39 - rtp_unpacker_hevc.go:76
2020/12/21 11:33:43.881474 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246
2020/12/21 11:33:43.881474 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246
2020/12/21 11:33:43.881474 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246
2020/12/21 11:33:43.881474 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246
2020/12/21 11:33:43.881474 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246
2020/12/21 11:33:43.881474 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246
2020/12/21 11:33:43.881474 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246
2020/12/21 11:33:43.881474 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246
2020/12/21 11:33:43.881474 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246
2020/12/21 11:33:43.881474 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246
2020/12/21 11:33:43.881474 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246
2020/12/21 11:33:43.883469 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246
2020/12/21 11:33:43.883469 ERROR invalid position. pos=0 - rtp_unpacker_avc.go:246

3.尝试H264的rtsp流,pullRtsp的demo未成功,flv文件为空

日志:

2020/12/21 11:35:57.517690 DEBUG [RTSPPULL1] > write setup. - client_pull_session.go:257
2020/12/21 11:35:57.549604 DEBUG [RTSPPULL1] < read response. code=200, ctx={Version:RTSP/1.0 StatusCode:200 Reason:OK Headers:map[CSeq:3 Session:378110526422;timeout=60 Transport:RTP/AVP/UDP;unicast;client_port=8000-8001;server_port=23722-23723;ssrc=0B15E296 x-Dynamic-Rate:1] Body:[]} - client_pull_session.go:265
2020/12/21 11:35:57.549604 DEBUG [RTSPPULL1] > write setup. - client_pull_session.go:257
2020/12/21 11:35:57.557583 DEBUG [RTSPPULL1] < read response. code=200, ctx={Version:RTSP/1.0 StatusCode:200 Reason:OK Headers:map[CSeq:4 Session:378110526422;timeout=60 Transport:RTP/AVP/UDP;unicast;client_port=8002-8003;server_port=0-0;ssrc=0B15E296 x-Dynamic-Rate:1] Body:[]} - client_pull_session.go:265
2020/12/21 11:35:57.557583 DEBUG [RTSPPULL1] > write play. - client_pull_session.go:302
2020/12/21 11:35:57.590494 DEBUG [RTSPPULL1] < read response. 200 - client_pull_session.go:310
2020/12/21 11:36:02.435543  WARN video queue full, drop front packet. - avpacket_queue.go:59
2020/12/21 11:36:02.468453  WARN video queue full, drop front packet. - avpacket_queue.go:59
2020/12/21 11:36:02.509344  WARN video queue full, drop front packet. - avpacket_queue.go:59
2020/12/21 11:36:02.547243  WARN video queue full, drop front packet. - avpacket_queue.go:59

生成的文件只有flv的头信息,1kb

image

4.rtsp没有做保活,即每分钟发送rtsp保活请求,导致网络摄像头的rtsp自动断开

5.rtsp的setup请求异常

日志

2020/12/21 11:41:46.685167  INFO [RTSPPULL1] lifecycle new rtsp PullSession. session=0xc00014e000 - client_pull_session.go:80
2020/12/21 11:41:46.685167 DEBUG [RTSPPULL1] > tcp connect. - client_pull_session.go:182
2020/12/21 11:41:46.689156 DEBUG [RTSPPULL1] > write options. - client_pull_session.go:199
2020/12/21 11:41:46.702122 DEBUG [RTSPPULL1] < read response. 200 - client_pull_session.go:207
2020/12/21 11:41:46.702122 DEBUG [RTSPPULL1] > write describe. - client_pull_session.go:214
2020/12/21 11:41:46.745007 DEBUG [RTSPPULL1] < read response. code=200, body=v=0
o=- 2252310609 2252310609 IN IP4 0.0.0.0
s=Media Server
c=IN IP4 0.0.0.0
t=0 0
a=control:*
a=packetization-supported:DH
a=rtppayload-supported:DH
a=range:npt=now-
m=video 0 RTP/AVP 96
a=control:trackID=0
a=framerate:25.000000
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=4D002A;sprop-parameter-sets=Z00AKp2oHgCJ+WbgICAoAAAfQAAGGoQgAA==,aO48gAA=
a=recvonly
m=audio 0 RTP/AVP 97
a=control:trackID=1
a=rtpmap:97 MPEG4-GENERIC/48000
a=fmtp:97 streamtype=5;profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1188
a=recvonly
 - client_pull_session.go:222
2020/12/21 11:41:46.746005 DEBUG [RTSPPULL1] > write setup. - client_pull_session.go:257
2020/12/21 11:41:46.752986 DEBUG [RTSPPULL1] < read response. code=451, ctx={Version:RTSP/1.0 StatusCode:451 Reason:Parameter Not Understood Headers:map[CSeq:3 Session:378459737223] Body:[]} - client_pull_session.go:265
2020/12/21 11:41:46.752986 ERROR lal.rtsp: fxxk - pullrtsp.go:64

Debugger finished with exit code 0

经vlc抓包对比分析,定位问题如下

image

与vlc对比临时修正测试成功

image

附VLC播放抓包明细

image

OPTIONS rtsp://192.168.7.85:554/cam/realmonitor?channel=1&subtype=1 RTSP/1.0
CSeq: 2
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)

RTSP/1.0 200 OK
CSeq: 2
Server: Rtsp Server/3.0
Public: OPTIONS, DESCRIBE, ANNOUNCE, SETUP, PLAY, RECORD, PAUSE, TEARDOWN, SET_PARAMETER, GET_PARAMETER

--------------------------------------

DESCRIBE rtsp://192.168.7.85:554/cam/realmonitor?channel=1&subtype=1 RTSP/1.0
CSeq: 3
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp

RTSP/1.0 200 OK
CSeq: 3
x-Accept-Dynamic-Rate: 1
Content-Base: rtsp://192.168.7.85:554/cam/realmonitor?channel=1&subtype=1/
Cache-Control: must-revalidate
Content-Length: 419
Content-Type: application/sdp

v=0
o=- 2252316863 2252316863 IN IP4 0.0.0.0
s=Media Server
c=IN IP4 0.0.0.0
t=0 0
a=control:*
a=packetization-supported:DH
a=rtppayload-supported:DH
a=range:npt=now-
m=video 0 RTP/AVP 98
a=control:trackID=0
a=framerate:25.000000
a=rtpmap:98 H265/90000
a=fmtp:98 profile-id=1;sprop-sps=QgEBAWAAAAMAsAAAAwAAAwBaoAWCAJBY2uSTL5A=;sprop-pps=RAHA8vA8kA==;sprop-vps=QAEMAf//AWAAAAMAsAAAAwAAAwBarAk=
a=recvonly

--------------------------------------

SETUP rtsp://192.168.7.85:554/cam/realmonitor?channel=1&subtype=1/trackID=0 RTSP/1.0
CSeq: 4
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP;unicast;client_port=54934-54935

RTSP/1.0 200 OK
CSeq: 4
Session: 378682809165;timeout=60
Transport: RTP/AVP/UDP;unicast;client_port=54934-54935;server_port=26884-26885;ssrc=331AFDA4
x-Dynamic-Rate: 1

--------------------------------------

PLAY rtsp://192.168.7.85:554/cam/realmonitor?channel=1&subtype=1/ RTSP/1.0
CSeq: 5
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Session: 378682809165
Range: npt=0.000-

RTSP/1.0 200 OK
CSeq: 5
Session: 378682809165
Range: npt=0.000000-
RTP-Info: url=trackID=0;seq=64932;rtptime=64932

--------------------------------------

GET_PARAMETER rtsp://192.168.7.85:554/cam/realmonitor?channel=1&subtype=1/ RTSP/1.0
CSeq: 6
User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
Session: 378682809165

RTSP/1.0 200 OK
CSeq: 6
Session: 378682809165
q191201771 commented 3 years ago

这几个问题我都尝试修复了,请拉取最新代码测试,谢谢。

ourfor-pp commented 3 years ago

@q191201771 拉取新的代码进行测试,尝试后发现以下问题

1.拉取无音频H265的流失败

日志

2020/12/28 10:09:12.731648  INFO [RTSPPULL1] lifecycle new rtsp PullSession. session=0xc000062820 - client_pull_session.go:96
2020/12/28 10:09:12.731648 DEBUG bitrate. rtsp pull=0kbit/s - pullrtsp.go:78
2020/12/28 10:09:12.731648 DEBUG [RTSPPULL1] > tcp connect. - client_pull_session.go:289
2020/12/28 10:09:12.735637 DEBUG [RTSPPULL1] > write options. - client_pull_session.go:306
2020/12/28 10:09:12.756580 DEBUG [RTSPPULL1] < read response. 200 - client_pull_session.go:314
2020/12/28 10:09:12.756580 DEBUG [RTSPPULL1] > write describe. - client_pull_session.go:328
2020/12/28 10:09:12.839359 DEBUG [RTSPPULL1] < read response. code=200, body=v=0
o=- 2252311042 2252311042 IN IP4 0.0.0.0
s=Media Server
c=IN IP4 0.0.0.0
t=0 0
a=control:*
a=packetization-supported:DH
a=rtppayload-supported:DH
a=range:npt=now-
m=video 0 RTP/AVP 98
a=control:trackID=0
a=framerate:25.000000
a=rtpmap:98 H265/90000
a=fmtp:98 profile-id=1;sprop-sps=QgEBAWAAAAMAsAAAAwAAAwBaoAWCAJBY2uSTL5A=;sprop-pps=RAHA8vA8kA==;sprop-vps=QAEMAf//AWAAAAMAsAAAAwAAAwBarAk=
a=recvonly
 - client_pull_session.go:336
2020/12/28 10:09:12.839359  WARN [RTSPPULL1] audio unpacker not support yet. origin type=0 - base_in_session.go:88
2020/12/28 10:09:12.840357 DEBUG [RTSPPULL1] > write setup. - client_pull_session.go:384
2020/12/28 10:09:12.847338 DEBUG [RTSPPULL1] < read response. code=200, ctx={Version:RTSP/1.0 StatusCode:200 Reason:OK Headers:map[CSeq:3 Session:372861431965;timeout=60 Transport:RTP/AVP/UDP;unicast;client_port=30000-30001;server_port=20446-20447;ssrc=54DC8E1D x-Dynamic-Rate:1] Body:[]} - client_pull_session.go:392
2020/12/28 10:09:12.848336 DEBUG [RTSPPULL1] > write play. - client_pull_session.go:462
2020/12/28 10:09:12.881247 DEBUG [RTSPPULL1] < read response. 200 - client_pull_session.go:470
2020/12/28 10:09:13.731973 DEBUG bitrate. rtsp pull=216kbit/s - pullrtsp.go:78
2020/12/28 10:09:14.732303 DEBUG bitrate. rtsp pull=91kbit/s - pullrtsp.go:78
2020/12/28 10:09:15.732624 DEBUG bitrate. rtsp pull=294kbit/s - pullrtsp.go:78
2020/12/28 10:09:16.732949 DEBUG bitrate. rtsp pull=142kbit/s - pullrtsp.go:78
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x8b0fa0]

goroutine 20 [running]:
github.com/q191201771/naza/pkg/nazanet.(*UDPConnection).Write2Addr(0x0, 0xc000088400, 0x20, 0x20, 0xc000098c30, 0x0, 0x0)
    E:/Develop/WorkSpace/go/pkg/mod/github.com/q191201771/naza@v0.16.0/pkg/nazanet/udp_connection.go:120 +0x40
github.com/q191201771/lal/pkg/rtsp.(*BaseInSession).handleRTCPPacket(0xc000120240, 0xc00014a600, 0x30, 0x5dc, 0xc000098c30, 0x0, 0x0)
    E:/Develop/WorkSpace/go/src/Monibuca/lal/pkg/rtsp/base_in_session.go:312 +0x588
github.com/q191201771/lal/pkg/rtsp.(*BaseInSession).onReadRTCPPacket(0xc000120240, 0xc00014a600, 0x30, 0x5dc, 0xc000098c30, 0x0, 0x0, 0x0)
    E:/Develop/WorkSpace/go/src/Monibuca/lal/pkg/rtsp/base_in_session.go:274 +0x1fb
github.com/q191201771/naza/pkg/nazanet.(*UDPConnection).RunLoop(0xc0001b4100, 0xc000182250, 0x0, 0x0)
    E:/Develop/WorkSpace/go/pkg/mod/github.com/q191201771/naza@v0.16.0/pkg/nazanet/udp_connection.go:87 +0x248
created by github.com/q191201771/lal/pkg/rtsp.(*BaseInSession).SetupWithConn
    E:/Develop/WorkSpace/go/src/Monibuca/lal/pkg/rtsp/base_in_session.go:130 +0x1c9

Debugger finished with exit code 0

DEBUG问题定位

base_in_session.go 119行,136行 猜测判断有误

if strings.HasSuffix(uri, s.sdpLogicCtx.AudioAControl) 

image

尝试修改测试:

if s.sdpLogicCtx.AudioAControl !="" && strings.HasSuffix(uri, s.sdpLogicCtx.AudioAControl) 

修改后,持续拉流成功,但是生成的out.flv文件VLC无法解码 image

q191201771 commented 3 years ago

你后面提交的那个bug,对应的修复方法是对的,我已经做了相应修改并提交到master分支了。

vlc播放不了H265的flv文件,应该是vlc不支持,你可以用支持H265 flv的ffmpeg试试。

q191201771 commented 3 years ago

这个问题之前已经修复了,这个issue先关闭了。 有需要可以随时打开或者创建新的issue,感谢。