diff --git a/writer/internal/media/g711.go b/writer/internal/media/g711.go index 0927e5c..e5472a8 100644 --- a/writer/internal/media/g711.go +++ b/writer/internal/media/g711.go @@ -11,7 +11,7 @@ import ( "log" ) -// CheckG711Format finds the H264 media and format. +// CheckG711Format finds the G711 media and format. func CheckG711Format(desc *description.Session) (*format.G711, *description.Media, error) { var g711Format *format.G711 g711Media := desc.FindFormat(&g711Format) diff --git a/writer/internal/procRTSP/client.go b/writer/internal/procRTSP/client.go index 88158b9..bbe344d 100644 --- a/writer/internal/procRTSP/client.go +++ b/writer/internal/procRTSP/client.go @@ -7,6 +7,8 @@ import ( "github.com/bluenviron/gortsplib/v4/pkg/base" "github.com/bluenviron/gortsplib/v4/pkg/description" "github.com/bluenviron/gortsplib/v4/pkg/format" + "github.com/bluenviron/gortsplib/v4/pkg/format/rtph264" + "github.com/bluenviron/gortsplib/v4/pkg/format/rtplpcm" "github.com/pion/rtp" _ "github.com/zaf/g711" "log" @@ -18,6 +20,8 @@ import ( var ( resolutions = []string{"1280x720"} + h264RTPDec *rtph264.Decoder + g711RTPDec *rtplpcm.Decoder ) // ProcRTSP process RTSP protocol and writes H264 and PCM flows into TS container. @@ -70,15 +74,19 @@ func ProcRTSP(period int, URI string) error { //////////////////////////////////////////////////////////////////////////////////////// // Create RTP -> H264 decoder. - h264RTPDec, err := h264Format.CreateDecoder() - if err != nil { - return fmt.Errorf("create H264 decoder error: %w", err) + if h264Format != nil { + h264RTPDec, err = h264Format.CreateDecoder() + if err != nil { + return fmt.Errorf("create H264 decoder error: %w", err) + } } // Create RTP -> H264 decoder. - g711RTPDec, err := g711Format.CreateDecoder() - if err != nil { - return fmt.Errorf("create G711 decoder error: %w", err) + if g711Format != nil { + g711RTPDec, err = g711Format.CreateDecoder() + if err != nil { + return fmt.Errorf("create G711 decoder error: %w", err) + } } ////////////////////////////////////////////////////////////////////////////////////////