From 2b9926cedb5506b385cc6b01754478a3a6b8174c Mon Sep 17 00:00:00 2001 From: Alex X Date: Sat, 14 Oct 2023 08:04:20 +0300 Subject: [PATCH] Support broken SPS for MP4 --- pkg/mp4/muxer.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/pkg/mp4/muxer.go b/pkg/mp4/muxer.go index 77cc7421..5533a9a3 100644 --- a/pkg/mp4/muxer.go +++ b/pkg/mp4/muxer.go @@ -2,7 +2,6 @@ package mp4 import ( "encoding/hex" - "errors" "github.com/AlexxIT/go2rtc/pkg/core" "github.com/AlexxIT/go2rtc/pkg/h264" @@ -43,13 +42,17 @@ func (m *Muxer) GetInit() ([]byte, error) { pps = []byte{0x68, 0xce, 0x38, 0x80} } - s := h264.DecodeSPS(sps) - if s == nil { - return nil, errors.New("mp4: can't parse SPS") + var width, height uint16 + if s := h264.DecodeSPS(sps); s != nil { + width = s.Width() + height = s.Height() + } else { + width = 1920 + height = 1080 } mv.WriteVideoTrack( - uint32(i+1), codec.Name, codec.ClockRate, s.Width(), s.Height(), h264.EncodeConfig(sps, pps), + uint32(i+1), codec.Name, codec.ClockRate, width, height, h264.EncodeConfig(sps, pps), ) case core.CodecH265: @@ -65,13 +68,17 @@ func (m *Muxer) GetInit() ([]byte, error) { pps = []byte{0x44, 0x01, 0xc0, 0x73, 0xc0, 0x4c, 0x90} } - s := h265.DecodeSPS(sps) - if s == nil { - return nil, errors.New("mp4: can't parse SPS") + var width, height uint16 + if s := h265.DecodeSPS(sps); s != nil { + width = s.Width() + height = s.Height() + } else { + width = 1920 + height = 1080 } mv.WriteVideoTrack( - uint32(i+1), codec.Name, codec.ClockRate, s.Width(), s.Height(), h265.EncodeConfig(vps, sps, pps), + uint32(i+1), codec.Name, codec.ClockRate, width, height, h265.EncodeConfig(vps, sps, pps), ) case core.CodecAAC: