Support broken SPS for MP4

This commit is contained in:
Alex X
2023-10-14 08:04:20 +03:00
parent af24fd67aa
commit 2b9926cedb
+16 -9
View File
@@ -2,7 +2,6 @@ package mp4
import ( import (
"encoding/hex" "encoding/hex"
"errors"
"github.com/AlexxIT/go2rtc/pkg/core" "github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/h264" "github.com/AlexxIT/go2rtc/pkg/h264"
@@ -43,13 +42,17 @@ func (m *Muxer) GetInit() ([]byte, error) {
pps = []byte{0x68, 0xce, 0x38, 0x80} pps = []byte{0x68, 0xce, 0x38, 0x80}
} }
s := h264.DecodeSPS(sps) var width, height uint16
if s == nil { if s := h264.DecodeSPS(sps); s != nil {
return nil, errors.New("mp4: can't parse SPS") width = s.Width()
height = s.Height()
} else {
width = 1920
height = 1080
} }
mv.WriteVideoTrack( 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: case core.CodecH265:
@@ -65,13 +68,17 @@ func (m *Muxer) GetInit() ([]byte, error) {
pps = []byte{0x44, 0x01, 0xc0, 0x73, 0xc0, 0x4c, 0x90} pps = []byte{0x44, 0x01, 0xc0, 0x73, 0xc0, 0x4c, 0x90}
} }
s := h265.DecodeSPS(sps) var width, height uint16
if s == nil { if s := h265.DecodeSPS(sps); s != nil {
return nil, errors.New("mp4: can't parse SPS") width = s.Width()
height = s.Height()
} else {
width = 1920
height = 1080
} }
mv.WriteVideoTrack( 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: case core.CodecAAC: