timecode

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNilTimecode          = errors.New("nil timecode")           // error for nil timecode
	ErrUnsupportedFrameRate = errors.New("unsupported frame rate") // error for unsupported frame rate
	ErrMismatchFrameRate    = errors.New("mismatch frame rate")    // error for mismatch frame rate
	ErrUnderflowFrames      = errors.New("underflow frames")       // error for underflow frames
	ErrInvalidTimecode      = errors.New("invalid timecode")       // error for invalid timecode
	ErrTooManyFrames        = errors.New("too many frames")        // error for too many frames
)

Functions

func IsRepresentableFrames

func IsRepresentableFrames(frames uint64, num, den int32, opts ...IsRepresentableFramesOption) bool

IsRepresentableFrames returns whether frames is representable.

func IsSupportedFrameRate

func IsSupportedFrameRate(num, den int32) bool

IsSupportedFrameRate returns whether frame rate is supported.

Types

type IsRepresentableFramesOption added in v1.1.0

type IsRepresentableFramesOption func(*IsRepresentableFramesOptionParam)

IsRepresentableFramesOption represents IsRepresentableFrames option.

type IsRepresentableFramesOptionParam added in v1.1.0

type IsRepresentableFramesOptionParam struct {
	ForceAsNDF bool
}

IsRepresentableFramesOptionParam represents IsRepresentableFrames option parameter.

type ParseTimecodeOption added in v1.1.0

type ParseTimecodeOption func(*ParseTimecodeOptionParam)

ParseTimecodeOption represents parse timecode option.

type ParseTimecodeOptionParam added in v1.1.0

type ParseTimecodeOptionParam struct {
	ForceAsNDF bool
	Sep        string
	LastSep    string
}

TimecodeOptionParam represents timecode option parameter.

type Timecode

type Timecode struct {
	HH uint64
	MM uint64
	SS uint64
	FF uint64
	// contains filtered or unexported fields
}

Timecode represents timecode.

func NewTimecode

func NewTimecode(frames uint64, num, den int32, opts ...TimecodeOption) (*Timecode, error)

NewTimecode returns new Timecode.

Example
package main

import (
	"fmt"

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

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

00:01:00:02

func ParseTimecode

func ParseTimecode(s string, num, den int32, opts ...ParseTimecodeOption) (*Timecode, error)

ParseTimecode returns new Timecode from formatted string.

Example
package main

import (
	"fmt"

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

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

00:09:00:02

func Reset

func Reset(tc *Timecode, frames uint64) (*Timecode, error)

Reset returns new Timecode from Timecode and frames.

Example
package main

import (
	"fmt"

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

func main() {
	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 (*Timecode) Add

func (tc *Timecode) Add(other *Timecode) (*Timecode, error)

Add Timecode and Timecode and return new Timecode.

Example
package main

import (
	"fmt"

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

func main() {
	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 (*Timecode) AddFrames

func (tc *Timecode) AddFrames(frames uint64) (*Timecode, error)

Add Timecode and frames and return new Timecode.

Example
package main

import (
	"fmt"

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

func main() {
	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 (*Timecode) Duration

func (tc *Timecode) Duration() time.Duration

Duration returns duration from zero-origin.

func (*Timecode) FramerateDenominator added in v1.0.1

func (tc *Timecode) FramerateDenominator() int32

Framerate denominator.

func (*Timecode) FramerateNumerator added in v1.0.1

func (tc *Timecode) FramerateNumerator() int32

Framerate numerator.

func (*Timecode) Frames

func (tc *Timecode) Frames() uint64

Frames returns number of frames.

func (*Timecode) String

func (tc *Timecode) String() string

String returns Timecode formatted string. e.g. 01:23:45:28

Example
package main

import (
	"fmt"

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

func main() {
	tc, err := timecode.NewTimecode(3600, 60000, 1001)
	if err != nil {
		panic(1)
	}
	fmt.Println(tc.String())
}
Output:

00:01:00:04

func (*Timecode) Sub

func (tc *Timecode) Sub(other *Timecode) (*Timecode, error)

Sub Timecode and Timecode and return new Timecode.

Example
package main

import (
	"fmt"

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

func main() {
	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 (*Timecode) SubFrames

func (tc *Timecode) SubFrames(frames uint64) (*Timecode, error)

Sub Timecode and frames and return new Timecode.

Example
package main

import (
	"fmt"

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

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

00:00:59:28

type TimecodeOption

type TimecodeOption func(*TimecodeOptionParam)

TimecodeOption represents timecode option.

type TimecodeOptionParam

type TimecodeOptionParam struct {
	ForceAsNDF bool
	Sep        string
	LastSep    string
}

TimecodeOptionParam represents timecode option parameter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL