Struct Timecode
A struct that represents a timestamp used to label a frame.
Namespace: Unity.LiveCapture
Syntax
[Serializable]
public struct Timecode : IComparable, IComparable<Timecode>, IEquatable<Timecode>
Remarks
A timecode represents a time in 24 hour period. This implementation supports negative timecodes. Since a timecode contains the number of the represented frame within the current second, each timecode is implicitly associated with the frame rate specified when creating the timecode and should only be compared to timecodes created with the same frame rate, or else the comparisons may not give sensible results.
Timecodes are typically used to synchronize content generated in a live context. By matching data samples with a timecode, samples from various sources with differing latencies can be aligned properly when played back later.
When using NTSC frame rates (23.976, 29.970, 59.94), it is not possible to accurately represent most timecodes in whole frames, as ~5% of a frame is missing each second. In order to correctly match wall-clock time to the timecode and prevent drift over time, drop frame timecode is often used, where the first few timecodes of every minute are skipped, except on every tenth minute.
Properties
Frames
The number of elapsed frames in the current second.
Declaration
public readonly int Frames { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
Hours
The number of elapsed hours.
Declaration
public readonly int Hours { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
IsDropFrame
Was this timecode generated taking into account drop frame calculations.
Declaration
public readonly bool IsDropFrame { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
Minutes
The number of elapsed minutes in the current hour.
Declaration
public readonly int Minutes { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
Seconds
The number of elapsed seconds in the current minute.
Declaration
public readonly int Seconds { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
Subframe
The time within the frame.
Declaration
public readonly Subframe Subframe { get; }
Property Value
| Type | Description |
|---|---|
| Subframe |
Methods
Center()
Gets the timecode at the center of the current frame.
Declaration
public readonly Timecode Center()
Returns
| Type | Description |
|---|---|
| Timecode | A Timecode at the middle of the frame interval. |
CompareTo(Object)
Compares this instance to a specified object and returns an indication of their relative values.
Declaration
public readonly int CompareTo(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | obj | The object to compare with this instance. |
Returns
| Type | Description |
|---|---|
| Int32 | A signed number indicating the relative values of this instance and
|
CompareTo(Timecode)
Compares this instance to a specified Timecode and returns an indication of their relative values.
Declaration
public readonly int CompareTo(Timecode other)
Parameters
| Type | Name | Description |
|---|---|---|
| Timecode | other | The value to compare with this instance. |
Returns
| Type | Description |
|---|---|
| Int32 | A signed number indicating the relative values of this instance and
|
Equals(Object)
Returns a value indicating whether this instance is equal to a specified object.
Declaration
public override readonly bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| Object | obj | An object to compare with this instance. |
Returns
| Type | Description |
|---|---|
| Boolean | true if |
Overrides
Equals(Timecode)
Returns a value indicating whether this instance is equal to a specified Timecode.
Declaration
public readonly bool Equals(Timecode other)
Parameters
| Type | Name | Description |
|---|---|---|
| Timecode | other | A value to compare with this instance. |
Returns
| Type | Description |
|---|---|
| Boolean | true if |
Floor()
Gets the timecode rounded down to the start of the current frame.
Declaration
public readonly Timecode Floor()
Returns
| Type | Description |
|---|---|
| Timecode | A Timecode with no subframe component. |
FromFrameTime(FrameRate, FrameTime)
Constructs a new Timecode from a frame number.
Declaration
public static Timecode FromFrameTime(FrameRate frameRate, FrameTime frameTime)
Parameters
| Type | Name | Description |
|---|---|---|
| FrameRate | frameRate | The number of frames per second. |
| FrameTime | frameTime | The frame number. |
Returns
| Type | Description |
|---|---|
| Timecode | A new Timecode that represents the given time, or default
if |
Remarks
If the total time is greater than 24 hours, the time is wrapped around to zero.
FromHMSF(FrameRate, Int32, Int32, Int32, Int32, Subframe, Boolean)
Constructs a new Timecode from a given time.
Declaration
public static Timecode FromHMSF(FrameRate frameRate, int hours, int minutes, int seconds, int frames, Subframe subframe = default(Subframe), bool isDropFrame = true)
Parameters
| Type | Name | Description |
|---|---|---|
| FrameRate | frameRate | The number of frames per second. |
| Int32 | hours | The number of hours. |
| Int32 | minutes | The number of minutes. |
| Int32 | seconds | The number of seconds. |
| Int32 | frames | The number of frames. |
| Subframe | subframe | The time within the frame. |
| Boolean | isDropFrame | Is the given time provided as a valid drop frame timecode, as opposed to a real (wall clock) timecode. This parameter is
only relevant if |
Returns
| Type | Description |
|---|---|
| Timecode | A new Timecode that represents the given time, or default
if |
Remarks
If the total time is greater than 24 hours, the time is wrapped around to zero.
FromSeconds(FrameRate, Double)
Constructs a new Timecode from a number of elapsed seconds.
Declaration
public static Timecode FromSeconds(FrameRate frameRate, double time)
Parameters
| Type | Name | Description |
|---|---|---|
| FrameRate | frameRate | The number of frames per second. |
| Double | time | The number of elapsed seconds. |
Returns
| Type | Description |
|---|---|
| Timecode | A new Timecode that represents the given time, or default
if |
Remarks
If the total time is greater than 24 hours, the time is wrapped around to zero.
FromTimeSpan(FrameRate, TimeSpan)
Declaration
public static Timecode FromTimeSpan(FrameRate frameRate, TimeSpan time)
Parameters
| Type | Name | Description |
|---|---|---|
| FrameRate | frameRate | The number of frames per second. |
| TimeSpan | time | The time span. |
Returns
| Type | Description |
|---|---|
| Timecode | A new Timecode that represents the given time, or default
if |
Remarks
If the total time is greater than 24 hours, the time is wrapped around to zero.
GetHashCode()
Returns the hash code for this instance.
Declaration
public override readonly int GetHashCode()
Returns
| Type | Description |
|---|---|
| Int32 | The hash code for this instance. |
Overrides
ToFrameTime(FrameRate)
Declaration
public readonly FrameTime ToFrameTime(FrameRate frameRate)
Parameters
| Type | Name | Description |
|---|---|---|
| FrameRate | frameRate | The frame rate of the frame sequence. |
Returns
| Type | Description |
|---|---|
| FrameTime | The frame time represented by this timecode, or default if |
ToSeconds(FrameRate)
Declaration
public readonly double ToSeconds(FrameRate frameRate)
Parameters
| Type | Name | Description |
|---|---|---|
| FrameRate | frameRate | The frame rate of the frame sequence. |
Returns
| Type | Description |
|---|---|
| Double | The time in seconds represented by this timecode, or default
if |
ToString()
Returns a string that represents the current instance.
Declaration
public override readonly string ToString()
Returns
| Type | Description |
|---|---|
| String | A string that represents the current instance. |
Overrides
Operators
Equality(Timecode, Timecode)
Indicates whether two specified instances of Timecode are equal.
Declaration
public static bool operator ==(Timecode a, Timecode b)
Parameters
| Type | Name | Description |
|---|---|---|
| Timecode | a | The first instance to compare. |
| Timecode | b | The second instance to compare. |
Returns
| Type | Description |
|---|---|
| Boolean |
GreaterThan(Timecode, Timecode)
Declaration
public static bool operator>(Timecode a, Timecode b)
Parameters
| Type | Name | Description |
|---|---|---|
| Timecode | a | The first instance to compare. |
| Timecode | b | The second instance to compare. |
Returns
| Type | Description |
|---|---|
| Boolean |
GreaterThanOrEqual(Timecode, Timecode)
Declaration
public static bool operator >=(Timecode a, Timecode b)
Parameters
| Type | Name | Description |
|---|---|---|
| Timecode | a | The first instance to compare. |
| Timecode | b | The second instance to compare. |
Returns
| Type | Description |
|---|---|
| Boolean |
Inequality(Timecode, Timecode)
Indicates whether two specified instances of Timecode are not equal.
Declaration
public static bool operator !=(Timecode a, Timecode b)
Parameters
| Type | Name | Description |
|---|---|---|
| Timecode | a | The first instance to compare. |
| Timecode | b | The second instance to compare. |
Returns
| Type | Description |
|---|---|
| Boolean | true if |
LessThan(Timecode, Timecode)
Declaration
public static bool operator <(Timecode a, Timecode b)
Parameters
| Type | Name | Description |
|---|---|---|
| Timecode | a | The first instance to compare. |
| Timecode | b | The second instance to compare. |
Returns
| Type | Description |
|---|---|
| Boolean |
LessThanOrEqual(Timecode, Timecode)
Declaration
public static bool operator <=(Timecode a, Timecode b)
Parameters
| Type | Name | Description |
|---|---|---|
| Timecode | a | The first instance to compare. |
| Timecode | b | The second instance to compare. |
Returns
| Type | Description |
|---|---|
| Boolean | true if |