bluenviron / gortsplib

RTSP 1.0 client and server library for the Go programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get width and height from SPS and PPS (resurfacing)

mateothegreat opened this issue · comments

I'm needing the dimensions of the stream and based on #473 and #475 the SPS should be available in github.com/bluenviron/gortsplib/v4 but I can't find it..

CleanShot 2024-02-15 at 05 24 59@2x

Can ya please advise on the proper method(s) for retrieving width and height?

Thanks!! 🙏

For reference the foundH265 value comes from a simple wrapper:

func findH265(desc *description.Session) *description.Media {
	var h265Format *format.H265
	findH265 := desc.FindFormat(&h265Format)
	return findH265
}

Solved (had to cast it -- had a moment of weakness :)).

		// Extract SPS from the first format
		sps := foundH265.Formats[0].(*format.H265).SPS

		var parsedSPS h265.SPS
		err := parsedSPS.Unmarshal([]byte(sps))
		if err != nil {
			return Stream{}, fmt.Errorf("failed to parse SPS: %w", err)
		}

		stream.Width = parsedSPS.Width()
		stream.Height = parsedSPS.Height()

		log.Printf("Width: %d, Height: %d", stream.Width, stream.Height)