Allow IVFWriter Framerate to be modified

Before was hardcoded to 30/1

Resolves #696
This commit is contained in:
Sean DuBois
2025-09-08 10:36:22 -07:00
parent cf7625dff8
commit 1527bfa2e3
2 changed files with 24 additions and 0 deletions

View File

@@ -352,3 +352,12 @@ func WithWidthAndHeight(width, height uint16) Option {
return nil
}
}
func WithFrameRate(numerator, denominator uint32) Option {
return func(i *IVFWriter) error {
i.timebaseNumerator = numerator
i.timebaseDenominator = denominator
return nil
}
}

View File

@@ -401,3 +401,18 @@ func TestIVFWriter_WithWidthAndHeight(t *testing.T) {
0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x84, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}, buffer.Bytes())
}
func TestIVFWriter_WithFrameRate(t *testing.T) {
buffer := &bytes.Buffer{}
writer, err := NewWith(buffer, WithFrameRate(60, 1))
assert.NoError(t, err)
assert.NoError(t, writer.WriteRTP(&rtp.Packet{Payload: []byte{}}))
assert.NoError(t, writer.Close())
assert.Equal(t, []byte{
0x44, 0x4b, 0x49, 0x46, 0x00, 0x00, 0x20, 0x00, 0x56, 0x50, 0x38, 0x30, 0x80, 0x02, 0xe0, 0x01,
0x01, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x84, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}, buffer.Bytes())
}