Help us shape the future of Go! Take the 2026 Go Developer Survey

timecode

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package timecode formats and parses FFmpeg time durations.

Index

Constants

This section is empty.

Variables

View Source
var DefaultClock = FFmpegClock{}

DefaultClock is the FFmpeg duration clock.

View Source
var ErrInvalidTimecode = errors.New("invalid timecode")

ErrInvalidTimecode is returned when a timestamp string cannot be parsed.

Functions

func FormatSeconds

func FormatSeconds(seconds float64) string

FormatSeconds renders seconds as a fixed-point decimal carrying exactly three fractional digits. Negative or non-finite values render as zero.

Parameters:

  • seconds: Timestamp in seconds.

Returns:

  • text: A decimal string carrying exactly three fractional digits.

Types

type FFmpegClock

type FFmpegClock struct{}

FFmpegClock is the FFmpeg time-duration clock.

func (FFmpegClock) Format

func (FFmpegClock) Format(duration time.Duration) string

Format renders duration as HH:MM:SS.mmm.

Parameters:

  • duration: Backing duration. Negative values render as zero.

Returns:

  • text: The duration in clock form, rounded to milliseconds.

func (FFmpegClock) Parse

func (clock FFmpegClock) Parse(value string) (time.Duration, error)

Parse accepts FFmpeg time durations: [-][HH:]MM:SS[.m...], [-]S+[.m...][s|ms|us].

Parameters:

  • value: An FFmpeg time-duration string.

Returns:

  • duration: The parsed duration, negative when the value is.
  • err: Non-nil when value is not a valid duration.

type Timecode

type Timecode struct {
	// contains filtered or unexported fields
}

Timecode is a media timestamp.

func FromDuration

func FromDuration(d time.Duration) Timecode

FromDuration builds a timecode from a duration.

Parameters:

  • d: Backing duration. Signed values are kept.

Returns:

  • timecode: The timestamp.

func FromSeconds

func FromSeconds(seconds float64) Timecode

FromSeconds builds a timecode from a floating-point second count.

Parameters:

  • seconds: Timestamp in seconds. Negative, NaN, and Inf become zero.

Returns:

  • timecode: The timestamp, or a zero value when seconds is not finite.

func Parse

func Parse(value string) (Timecode, error)

Parse builds a timecode from an FFmpeg time-duration string.

Parameters:

  • value: An FFmpeg time-duration string.

Returns:

  • timecode: The parsed timestamp.
  • err: Non-nil when value is not a valid duration.

func (Timecode) Duration

func (t Timecode) Duration() time.Duration

Duration returns the backing duration.

Returns:

func (Timecode) FormatSeconds

func (t Timecode) FormatSeconds() string

FormatSeconds renders the timestamp as a fixed-point decimal carrying exactly three fractional digits. The value is rounded to the nearest millisecond, matching FFmpegClock.Format, and negative values render as zero.

Returns:

  • text: A decimal string carrying exactly three fractional digits.

func (Timecode) Short

func (t Timecode) Short() string

Short renders a duration in the short form, with empty parts left out.

Returns:

  • short: The duration in short form.

func (Timecode) String

func (t Timecode) String() string

String renders HH:MM:SS.mmm.

Returns:

  • text: The timestamp in clock form.

Jump to

Keyboard shortcuts

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