Skip to content

Commit

Permalink
add framerate getter
Browse files Browse the repository at this point in the history
  • Loading branch information
lomavkin committed Dec 25, 2023
1 parent 0618681 commit 868ffa2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions timecode/timecode.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ func (tc *Timecode) Duration() time.Duration {
return time.Duration((float64(tc.Frames()) * float64(tc.r.denominator) / float64(tc.r.numerator)) * float64(time.Second))
}

// Framerate denominator.
func (tc *Timecode) FramerateDenominator() int32 {
return tc.r.denominator
}

// Framerate numerator.
func (tc *Timecode) FramerateNumerator() int32 {
return tc.r.numerator
}

// Add Timecode and Timecode and return new Timecode.
func (tc *Timecode) Add(other *Timecode) (*Timecode, error) {
if !tc.r.equal(other.r) {
Expand Down
12 changes: 12 additions & 0 deletions timecode/timecode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ func TestNewTestcodeNonDF(t *testing.T) {
assert.Equal(t, "00:00:59:23", tc.String())
assert.Equal(t, uint64(1439), tc.Frames())
assert.Equal(t, 59.958, math.Round(tc.Duration().Seconds()*1000)/1000)
assert.Equal(t, int32(24), tc.FramerateNumerator())
assert.Equal(t, int32(1), tc.FramerateDenominator())

tc, err = NewTimecode(1440, 24, 1)
assert.NoError(t, err)
Expand Down Expand Up @@ -225,6 +227,8 @@ func TestNewTestcodeNonDF(t *testing.T) {
assert.Equal(t, "00:00:59:24", tc.String())
assert.Equal(t, uint64(1499), tc.Frames())
assert.Equal(t, 59.96, math.Round(tc.Duration().Seconds()*1000)/1000)
assert.Equal(t, int32(25), tc.FramerateNumerator())
assert.Equal(t, int32(1), tc.FramerateDenominator())

tc, err = NewTimecode(1500, 25, 1)
assert.NoError(t, err)
Expand Down Expand Up @@ -264,6 +268,8 @@ func TestNewTestcodeNonDF(t *testing.T) {
assert.Equal(t, "00:00:59:29", tc.String())
assert.Equal(t, uint64(1799), tc.Frames())
assert.Equal(t, 59.967, math.Round(tc.Duration().Seconds()*1000)/1000)
assert.Equal(t, int32(30), tc.FramerateNumerator())
assert.Equal(t, int32(1), tc.FramerateDenominator())

tc, err = NewTimecode(1800, 30, 1)
assert.NoError(t, err)
Expand Down Expand Up @@ -303,6 +309,8 @@ func TestNewTestcodeNonDF(t *testing.T) {
assert.Equal(t, "00:00:59:47", tc.String())
assert.Equal(t, uint64(2879), tc.Frames())
assert.Equal(t, 59.979, math.Round(tc.Duration().Seconds()*1000)/1000)
assert.Equal(t, int32(48), tc.FramerateNumerator())
assert.Equal(t, int32(1), tc.FramerateDenominator())

tc, err = NewTimecode(2880, 48, 1)
assert.NoError(t, err)
Expand Down Expand Up @@ -342,6 +350,8 @@ func TestNewTestcodeNonDF(t *testing.T) {
assert.Equal(t, "00:00:59:49", tc.String())
assert.Equal(t, uint64(2999), tc.Frames())
assert.Equal(t, 59.98, math.Round(tc.Duration().Seconds()*1000)/1000)
assert.Equal(t, int32(50), tc.FramerateNumerator())
assert.Equal(t, int32(1), tc.FramerateDenominator())

tc, err = NewTimecode(3000, 50, 1)
assert.NoError(t, err)
Expand Down Expand Up @@ -381,6 +391,8 @@ func TestNewTestcodeNonDF(t *testing.T) {
assert.Equal(t, "00:00:00:00", tc.String())
assert.Equal(t, uint64(0), tc.Frames())
assert.Equal(t, 0.0, math.Round(tc.Duration().Seconds()*1000)/1000)
assert.Equal(t, int32(60), tc.FramerateNumerator())
assert.Equal(t, int32(1), tc.FramerateDenominator())

tc, err = NewTimecode(3599, 60, 1)
assert.NoError(t, err)
Expand Down

0 comments on commit 868ffa2

Please sign in to comment.