From 442ba97c61378aa81a842166a1972afc0482da6d Mon Sep 17 00:00:00 2001 From: Cedric Verstraeten Date: Tue, 9 Jan 2024 13:13:42 +0100 Subject: [PATCH] [release] v3.1.2 hot-fix: for missing SPS and PPS from opening codec. --- machinery/src/capture/Gortsplib.go | 3 +-- machinery/src/capture/main.go | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/machinery/src/capture/Gortsplib.go b/machinery/src/capture/Gortsplib.go index ad3b4382..3c1946ae 100644 --- a/machinery/src/capture/Gortsplib.go +++ b/machinery/src/capture/Gortsplib.go @@ -131,7 +131,7 @@ func (g *Golibrtsp) Connect(ctx context.Context) (err error) { // It might be that the SPS is not available yet, so we'll proceed, // but try to fetch it later on. if errSPS != nil { - log.Log.Debug("capture.golibrtsp.Connect(H264): " + err.Error()) + log.Log.Debug("capture.golibrtsp.Connect(H264): " + errSPS.Error()) g.Streams = append(g.Streams, packets.Stream{ Name: formaH264.Codec(), IsVideo: true, @@ -537,7 +537,6 @@ func (g *Golibrtsp) Start(ctx context.Context, streamType string, queue *packets pkt.Data = pkt.Data[4:] if pkt.IsKeyFrame { - annexbNALUStartCode := func() []byte { return []byte{0x00, 0x00, 0x00, 0x01} } pkt.Data = append(annexbNALUStartCode(), pkt.Data...) pkt.Data = append(g.VideoH264Forma.PPS, pkt.Data...) diff --git a/machinery/src/capture/main.go b/machinery/src/capture/main.go index 16b98300..53a0c65a 100644 --- a/machinery/src/capture/main.go +++ b/machinery/src/capture/main.go @@ -223,10 +223,14 @@ func HandleRecordStream(queue *packets.Queue, configDirectory string, configurat //cws = newCacheWriterSeeker(4096) myMuxer, _ = mp4.CreateMp4Muxer(file) // We choose between H264 and H265 + width := configuration.Config.Capture.IPCamera.Width + height := configuration.Config.Capture.IPCamera.Height + widthOption := mp4.WithVideoWidth(uint32(width)) + heightOption := mp4.WithVideoHeight(uint32(height)) if pkt.Codec == "H264" { - videoTrack = myMuxer.AddVideoTrack(mp4.MP4_CODEC_H264) + videoTrack = myMuxer.AddVideoTrack(mp4.MP4_CODEC_H264, widthOption, heightOption) } else if pkt.Codec == "H265" { - videoTrack = myMuxer.AddVideoTrack(mp4.MP4_CODEC_H265) + videoTrack = myMuxer.AddVideoTrack(mp4.MP4_CODEC_H265, widthOption, heightOption) } // For an MP4 container, AAC is the only audio codec supported. audioTrack = myMuxer.AddAudioTrack(mp4.MP4_CODEC_AAC) @@ -386,10 +390,14 @@ func HandleRecordStream(queue *packets.Queue, configDirectory string, configurat // Check which video codec we need to use. videoSteams, _ := rtspClient.GetVideoStreams() for _, stream := range videoSteams { + width := configuration.Config.Capture.IPCamera.Width + height := configuration.Config.Capture.IPCamera.Height + widthOption := mp4.WithVideoWidth(uint32(width)) + heightOption := mp4.WithVideoHeight(uint32(height)) if stream.Name == "H264" { - videoTrack = myMuxer.AddVideoTrack(mp4.MP4_CODEC_H264) + videoTrack = myMuxer.AddVideoTrack(mp4.MP4_CODEC_H264, widthOption, heightOption) } else if stream.Name == "H265" { - videoTrack = myMuxer.AddVideoTrack(mp4.MP4_CODEC_H265) + videoTrack = myMuxer.AddVideoTrack(mp4.MP4_CODEC_H265, widthOption, heightOption) } } // For an MP4 container, AAC is the only audio codec supported.