vtc-go
A SMPTE Timecode Library for Go
Overview
vtc-go
is inspired by years of scripting workflow solutions in a Hollywood cutting
room. It aims to capture all the ways in which timecode is used throughout the industry
so users can spend more time on their workflow logic, and less time handling the
corner-cases of parsing and calculating timecode.
Demo
Let's take a quick high-level look at what you can do with vtc-rs:
package main
import (
"fmt"
"github.com/opencinemac/vtc-go/pkg/rate"
"github.com/opencinemac/vtc-go/pkg/tc"
"math/big"
)
func main() {
timecode, err := tc.FromTimecode("01:00:00:00", rate.F23_98)
if err != nil {
panic(fmt.Errorf("error parsing timecode: %w", err))
}
fmt.Println(timecode)
fmt.Println(timecode.Timecode())
fmt.Println(timecode.Frames())
fmt.Println(timecode.Seconds())
fmt.Println(timecode.Runtime(9))
fmt.Println(timecode.PremiereTicks())
fmt.Println(timecode.FeetAndFrames())
fmt.Println(timecode.Rate().Playback())
fmt.Println(timecode.Rate().Timebase())
fmt.Println(timecode.Rate().NTSC())
timecode, _ = tc.FromTimecode("3:12", rate.F23_98)
fmt.Println(timecode)
timecode = tc.FromFrames(24, rate.F23_98)
fmt.Println(timecode)
timecode = tc.FromSeconds(big.NewRat(3, 2), rate.F23_98)
fmt.Println(timecode)
timecode = tc.FromPremiereTicks(254016000000, rate.F23_98)
fmt.Println(timecode)
timecode, _ = tc.FromRuntime("01:00:00.5", rate.F23_98)
fmt.Println(timecode)
timecode, _ = tc.FromFeetAndFrames("213+07", rate.F23_98)
fmt.Println(timecode)
timecode, _ = tc.FromTimecode("17:23:13:02", rate.F23_98)
other, _ := tc.FromTimecode("01:00:00:00", rate.F23_98)
timecode = timecode.Add(other)
fmt.Println(timecode)
timecode = timecode.Sub(other)
fmt.Println(timecode)
fmt.Println(timecode.Cmp(other))
timecode = timecode.Mul(big.NewRat(2, 1))
fmt.Println(timecode)
timecode = timecode.Div(big.NewRat(2, 1))
fmt.Println(timecode)
dividend, remainder := timecode.DivMod(big.NewRat(3, 2))
fmt.Println("DIVIDEND:", dividend)
fmt.Println("REMAINDER:", remainder)
timecode = timecode.Neg()
fmt.Println(timecode)
timecode = timecode.Abs()
fmt.Println(timecode)
dropFrame := tc.FromFrames(15000, rate.F29_97Df)
fmt.Println(dropFrame)
fmt.Println(dropFrame.Rate().NTSC())
framerate, _ := rate.FromInt(137, rate.NTSCNone)
timecode, _ = tc.FromTimecode("01:00:00:00", framerate)
fmt.Println(timecode.Frames())
framerate, _ = rate.FromInt(120, rate.NTSCNonDrop)
timecode, _ = tc.FromTimecode("01:00:00:00", framerate)
fmt.Println(timecode)
timecode = timecode.Rebase(rate.F59_94Ndf)
fmt.Println(timecode)
}
Features
- SMPTE Conventions:
- Timecode Representations:
- Timecode | '01:00:00:00'
- Frames | 86400
- Seconds | 3600.0
- Runtime | '01:00:00.0'
- Rational | 18018/5
- Feet+Frames | '5400+00'
- Premiere Ticks | 15240960000000
- Operations:
- Comparisons (==, <, <=, >, >=)
- Add
- Subtract
- Scale (multiply and divide)
- Div/Rem
- Modulo
- Negative
- Absolute
- Rebase (recalculate frame count at new framerate)
- Flexible Parsing:
- Partial timecodes | '1:12'
- Partial runtimes | '1.5'
- Negative string values | '-1:12', '-3+00'
- Poorly formatted tc | '1:13:4'
- Built-in consts for common framerates.
Goals
- Parse and fetch all Timecode representations.
- A clean, idiomatic API.
- Support all operations that make sense for timecode.
Non-Goals
- Real-time timecode generators.
Attributions