https://github.com/spiretechnology/go-timecode
SMPTE timecode parser and formatter for Go.
https://github.com/spiretechnology/go-timecode
audio golang multimedia smpte timecode video
Last synced: about 1 month ago
JSON representation
SMPTE timecode parser and formatter for Go.
- Host: GitHub
- URL: https://github.com/spiretechnology/go-timecode
- Owner: spiretechnology
- License: mit
- Created: 2021-08-12T09:46:18.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-03-18T19:57:31.000Z (almost 2 years ago)
- Last Synced: 2024-06-20T14:22:47.125Z (over 1 year ago)
- Topics: audio, golang, multimedia, smpte, timecode, video
- Language: Go
- Homepage:
- Size: 31 MB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-timecode
A Go library for parsing and manipulating SMPTE timecodes and frame rates.
Development of this library is very test-driven to ensure accuracy of the frame and timecode calculations. If you'd like to contribute to this library, adding additional useful test cases is a great place to start!
## Installation
```sh
go get github.com/spiretechnology/go-timecode
```
## Usage Examples
### Parse a timecode (drop frame)
```go
tc, err := timecode.Parse("00:01:02;23", timecode.Rate_29_97)
tc.String() // => 00:01:02;23
tc.Frame() // => 1881
```
### Parse a timecode (non-drop frame)
```go
tc, err := timecode.Parse("00:01:02:23", timecode.Rate_24)
tc.String() // => 00:01:02:23
tc.Frame() // => 1511
```
### Create a timecode from a frame count
```go
tc := timecode.FromFrame(1511, timecode.Rate_24, false /* non-drop frame */)
tc.String() // => 00:01:02:23
tc.Frame() // => 1511
```
### Algebra with timecodes and frames
```go
tc, err := timecode.Parse("00:01:02:23", timecode.Rate_24)
tc = tc.Add(timecode.Frame(3))
tc.String() // => 00:01:03:02
tc.Frame() // => 1514
```
## Note: parsing timecodes that don't exist in drop frame
Drop frame timecodes skip the first 2 frames of each minute, unless the minute is a multiple of 10. This changes to the first 4 frames of each minute if the frame rate is 59.94.
For instance, in `29.97`, the timecode `00:00:59:29` is immediately followed by `00:01:00:02`. Two timecodes were dropped: `00:01:00:00` and `00:01:00:01`
Those dropped timecodes don't correspond to any actual frame number, and so we need to choose how to resolve those frames. The choice we have made with this library is to round up the next valid frame. If you try to parse `00:01:00:00`, the result will be rounded up to `00:01:00:02`, which is the next valid frame in the sequence.
## Contributing
We welcome contributions that make this library more reliable. To add test cases, fix bugs, or anything else, please submit a pull request.
## Other resources
- [spiretechnology/js-timecode](https://github.com/spiretechnology/js-timecode) - A TypeScript / JavaScript library for parsing and manipulating SMPTE timecodes and frame rates.