diff --git a/pkg/bits/reader.go b/pkg/bits/reader.go index 31ea9ef8..435cf5f7 100644 --- a/pkg/bits/reader.go +++ b/pkg/bits/reader.go @@ -122,9 +122,9 @@ func (r *Reader) ReadUEGolomb() uint32 { // ReadSEGolomb - ReadSignedExponentialGolomb func (r *Reader) ReadSEGolomb() int32 { if b := r.ReadUEGolomb(); b%2 == 0 { - return -int32(b >> 1) + return -int32(b / 2) } else { - return int32(b >> 1) + return int32((b + 1) / 2) } } diff --git a/pkg/h264/h264_test.go b/pkg/h264/h264_test.go index 8b9fb737..c3a83cc0 100644 --- a/pkg/h264/h264_test.go +++ b/pkg/h264/h264_test.go @@ -5,7 +5,6 @@ import ( "encoding/hex" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -91,5 +90,14 @@ func TestDecodeSPS2(t *testing.T) { require.Nil(t, err) sps := DecodeSPS(b) - assert.Nil(t, sps) // broken SPS? + require.Equal(t, uint16(928), sps.Width()) + require.Equal(t, uint16(576), sps.Height()) + + s = "Z2QAHq2EAQwgCGEAQwgCGEAQwgCEO1BQF/yzcBAQFAAAD6AAAXcCEA==" // unknown + b, err = base64.StdEncoding.DecodeString(s) + require.Nil(t, err) + + sps = DecodeSPS(b) + require.Equal(t, uint16(640), sps.Width()) + require.Equal(t, uint16(360), sps.Height()) } diff --git a/pkg/h264/sps.go b/pkg/h264/sps.go index 6bcca669..1ac73945 100644 --- a/pkg/h264/sps.go +++ b/pkg/h264/sps.go @@ -88,6 +88,8 @@ func (s *SPS) Height() uint16 { } func DecodeSPS(sps []byte) *SPS { + // https://developer.ridgerun.com/wiki/index.php/H264_Analysis_Tools + // ffmpeg -i file.h264 -c copy -bsf:v trace_headers -f null - r := bits.NewReader(sps) hdr := r.ReadByte()