go-timecode simplifies the use of string based timecodes by providing conversions, frame based math, and support for SMTPE drop frame encoding. go-timecode offers a variety of industry standard formats out of the box but is designed to make it easy to work with any combination of formats you need.
go get github.com/agorman/go-timecode/v2
https://godoc.org/github.com/agorman/go-timecode/v2
tc, err := timecode.Parse(timecode.R30, "01:30:12:15")
if err != nil {
panic(err)
}
tc.String() # "01:30:12:15"
tc.Frames() # 162375
tc.Seconds() # 5412.5
tc := timecode.FromFrames(timecode.R2997DF, 162213)
tc.String() # "01:30:12:15"
tc.Frames() # 162213
tc.Seconds() # 5407.1
tc, err := timecode.FromSeconds(timecode.R2398, 5412.625)
if err != nil {
panic(err)
}
tc.String() # "01:30:12:15"
tc.Frames() # 129903
tc.Seconds() # 5412.625
rate, err := timecode.NewRate(30, false)
if err != nil {
panic(err)
}
rate.FPS() # 30.0
rate.DropFrame() # false
rate, err := timecode.ParseRate("30000/1001", true)
if err != nil {
panic(err)
}
rate.FPS() # 29.97
rate.DropFrame() # true