From 1b80c869ae0420246929a1f301d89d1b535f5e6f Mon Sep 17 00:00:00 2001 From: Jae-Sung Lee Date: Fri, 2 Jun 2023 08:39:12 +0000 Subject: [PATCH 1/2] parse audiocodecid from rtmp metadata --- pkg/remux/rtmp2rtsp.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/remux/rtmp2rtsp.go b/pkg/remux/rtmp2rtsp.go index 4d139ea..1011e60 100644 --- a/pkg/remux/rtmp2rtsp.go +++ b/pkg/remux/rtmp2rtsp.go @@ -73,6 +73,14 @@ func (r *Rtmp2RtspRemuxer) FeedRtmpMsg(msg base.RtmpMsg) { switch msg.Header.MsgTypeId { case base.RtmpTypeIdMetadata: if meta, err := rtmp.ParseMetadata(msg.Payload); err == nil { + if audioCodecId, ok := meta.Find("audiocodecid").(float64); ok { + switch uint8(audioCodecId) { + case base.RtmpSoundFormatG711U: + r.audioPt = base.AvPacketPtG711U + case base.RtmpSoundFormatG711A: + r.audioPt = base.AvPacketPtG711A + } + } if samplerate, ok := meta.Find("audiosamplerate").(float64); ok { r.audioSampleRate = int(samplerate) } From 6915ab3ddd9916c1d5339d4ac55449c76e88079b Mon Sep 17 00:00:00 2001 From: Jae-Sung Lee Date: Fri, 2 Jun 2023 09:12:27 +0000 Subject: [PATCH 2/2] if audioPt knows returns true in isAnalyzeEnough --- pkg/remux/rtmp2rtsp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/remux/rtmp2rtsp.go b/pkg/remux/rtmp2rtsp.go index 1011e60..f6b34f5 100644 --- a/pkg/remux/rtmp2rtsp.go +++ b/pkg/remux/rtmp2rtsp.go @@ -217,7 +217,7 @@ func (r *Rtmp2RtspRemuxer) doAnalyze() { func (r *Rtmp2RtspRemuxer) isAnalyzeEnough() bool { // 音视频头都收集好了 // 注意,这里故意只判断sps和pps,从而同时支持h264和2h65的情况 - if r.sps != nil && r.pps != nil && r.asc != nil { + if r.sps != nil && r.pps != nil && (r.asc != nil || r.audioPt != base.AvPacketPtUnknown) { return true }