Documentation
¶
Overview ¶
Package timecode formats and parses FFmpeg time durations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultClock = FFmpegClock{}
DefaultClock is the FFmpeg duration clock.
var ErrInvalidTimecode = errors.New("invalid timecode")
ErrInvalidTimecode is returned when a timestamp string cannot be parsed.
Functions ¶
func FormatSeconds ¶
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 reads an FFmpeg time duration.
It accepts the forms [-][HH:]MM:SS[.m...] and [-]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 FieldError ¶ added in v0.4.0
type FieldError struct {
// Field names the field, such as "start" or "end".
Field string
// Value is what the field held.
Value string
}
FieldError reports a form field that holds something other than a timecode.
It names the field, so the page can say which one to fix.
func (*FieldError) Error ¶ added in v0.4.0
func (err *FieldError) Error() string
Error describes the field and what it held.
Returns:
- message: The error text.
func (*FieldError) Unwrap ¶ added in v0.4.0
func (*FieldError) Unwrap() error
Unwrap ties the error to ErrInvalidTimecode.
Returns:
- target: ErrInvalidTimecode.
type Timecode ¶
type Timecode struct {
// contains filtered or unexported fields
}
Timecode is a media timestamp.
func FromDuration ¶
FromDuration builds a timecode from a duration.
Parameters:
- d: Backing duration. Signed values are kept.
Returns:
- timecode: The timestamp.
func FromSeconds ¶
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 ¶
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 ¶
Duration returns the backing duration.
Returns:
- duration: The stored time.Duration.
func (Timecode) FormatSeconds ¶
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.