Skip to content

Commit

Permalink
Merge pull request #1 from abema/add-timecode
Browse files Browse the repository at this point in the history
add timecode
  • Loading branch information
lomavkin authored Sep 13, 2023
2 parents fd91a38 + 74ccf46 commit ee09a0c
Show file tree
Hide file tree
Showing 7 changed files with 1,125 additions and 2 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 ABEMA
Copyright (c) 2023 AbemaTV

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
# go-timecode
go-timecode
===========

[![GoDoc](https://godoc.org/github.com/abema/go-timecode/timecode?status.svg)](https://godoc.org/github.com/abema/go-timecode/timecode)

go-timecode is a Go library for SMPTE 12M timecodes.

Features
-----------

- supports drop-frame (DF) and non-drop-frame (NDF)
- supports standard film, video, and television editing rates of 10, 15, 23.976, 24, 25, 29.97, 30, 48, 50, 59.94, 60
- timecode and number of frames can be calculated
- convertable between timecode and number of frames

Installation
-----------

```shell
go get github.com/abema/go-timecode/timecode
```

Usage
-----------
[GoDoc Examples](https://godoc.org/github.com/abema/go-timecode/timecode/#pkg-examples).

License
-----------
go-timecode is available under the [MIT License](https://opensource.org/license/mit/).
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module github.com/abema/go-timecode

go 1.19

require github.com/stretchr/testify v1.8.4

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
94 changes: 94 additions & 0 deletions timecode/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package timecode_test

import (
"fmt"

"github.com/abema/go-timecode/timecode"
)

func ExampleNewTimecode() {
tc, err := timecode.NewTimecode(1800, 30000, 1001)
if err != nil {
panic(1)
}
fmt.Println(tc)
// Output: 00:01:00:02
}

func ExampleParseTimecode() {
tc, err := timecode.ParseTimecode("00:09:00:00", 30000, 1001)
if err != nil {
panic(1)
}
fmt.Println(tc)
// Output: 00:09:00:02
}

func ExampleReset() {
tc, err := timecode.NewTimecode(1798, 30000, 1001)
if err != nil {
panic(1)
}
tcc, _ := timecode.Reset(tc, 1800)
fmt.Println(tcc)
// Output: 00:01:00:02
}

func ExampleTimecode_Add() {
tc1, err := timecode.NewTimecode(1798, 30000, 1001)
if err != nil {
panic(1)
}
tc2, err := timecode.NewTimecode(2, 30000, 1001)
if err != nil {
panic(1)
}
tc3, _ := tc1.Add(tc2)
fmt.Println(tc3)
// Output:
// 00:01:00:02
}

func ExampleTimecode_AddFrames() {
tc1, err := timecode.NewTimecode(1798, 30000, 1001)
if err != nil {
panic(1)
}

tc2, _ := tc1.AddFrames(2)
fmt.Println(tc2)
// Output: 00:01:00:02
}

func ExampleTimecode_Sub() {
tc1, err := timecode.NewTimecode(1800, 30000, 1001)
if err != nil {
panic(1)
}
tc2, err := timecode.NewTimecode(2, 30000, 1001)
if err != nil {
panic(1)
}
tc3, _ := tc1.Sub(tc2)
fmt.Println(tc3)
// Output: 00:00:59:28
}

func ExampleTimecode_SubFrames() {
tc1, err := timecode.NewTimecode(1800, 30000, 1001)
if err != nil {
panic(1)
}
tc2, _ := tc1.SubFrames(2)
fmt.Println(tc2)
// Output: 00:00:59:28
}

func ExampleTimecode_String() {
tc, err := timecode.NewTimecode(3600, 60000, 1001)
if err != nil {
panic(1)
}
fmt.Println(tc.String())
// Output: 00:01:00:04
}
Loading

0 comments on commit ee09a0c

Please sign in to comment.