docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct Timecode

    A struct that represents a timestamp used to label a frame.

    Namespace: Unity.LiveCapture
    Assembly: Unity.LiveCapture.dll
    Syntax
    [Serializable]
    public struct 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 int Frames { get; }
    Property Value
    Type Description
    int

    Hours

    The number of elapsed hours.

    Declaration
    public int Hours { get; }
    Property Value
    Type Description
    int

    IsDropFrame

    Was this timecode generated taking into account drop frame calculations.

    Declaration
    public bool IsDropFrame { get; }
    Property Value
    Type Description
    bool

    Minutes

    The number of elapsed minutes in the current hour.

    Declaration
    public int Minutes { get; }
    Property Value
    Type Description
    int

    Seconds

    The number of elapsed seconds in the current minute.

    Declaration
    public int Seconds { get; }
    Property Value
    Type Description
    int

    Subframe

    The time within the frame.

    Declaration
    public Subframe Subframe { get; }
    Property Value
    Type Description
    Subframe

    Methods

    Center()

    Gets the timecode at the center of the current frame.

    Declaration
    public 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 int CompareTo(object obj)
    Parameters
    Type Name Description
    object obj

    The object to compare with this instance.

    Returns
    Type Description
    int

    A signed number indicating the relative values of this instance and obj. * Returns a negative value when obj is not a valid Timecode instance or this instance is less than obj. * Returns zero when this instance is the same as obj. * Returns a positive value when this instance is greater than obj.

    CompareTo(Timecode)

    Compares this instance to a specified Timecode and returns an indication of their relative values.

    Declaration
    public int CompareTo(Timecode other)
    Parameters
    Type Name Description
    Timecode other

    The value to compare with this instance.

    Returns
    Type Description
    int

    A signed number indicating the relative values of this instance and other. * Returns a negative value when this instance is less than other. * Returns zero when this instance is the same as other. * Returns a positive value when this instance is greater than other.

    Equals(object)

    Returns a value indicating whether this instance is equal to a specified object.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    object obj

    An object to compare with this instance.

    Returns
    Type Description
    bool

    true if obj is an instance of Timecode and equals the value of this instance; otherwise, false.

    Overrides
    ValueType.Equals(object)

    Equals(Timecode)

    Returns a value indicating whether this instance is equal to a specified Timecode.

    Declaration
    public bool Equals(Timecode other)
    Parameters
    Type Name Description
    Timecode other

    A value to compare with this instance.

    Returns
    Type Description
    bool

    true if other has the same value as this instance; otherwise, false.

    Floor()

    Gets the timecode rounded down to the start of the current frame.

    Declaration
    public 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 frameRate is invalid.

    Remarks

    If the total time is greater than 24 hours, the time is wrapped around to zero.

    FromHMSF(FrameRate, int, int, int, int, Subframe)

    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)
    Parameters
    Type Name Description
    FrameRate frameRate

    The number of frames per second.

    int hours

    The number of hours.

    int minutes

    The number of minutes.

    int seconds

    The number of seconds.

    int frames

    The number of frames.

    Subframe subframe

    The time within the frame.

    Returns
    Type Description
    Timecode

    A new Timecode that represents the given time, or default if frameRate is invalid.

    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 frameRate is invalid.

    Remarks

    If the total time is greater than 24 hours, the time is wrapped around to zero.

    FromTimeSpan(FrameRate, TimeSpan)

    Constructs a new Timecode from a 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 frameRate is invalid.

    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 int GetHashCode()
    Returns
    Type Description
    int

    The hash code for this instance.

    Overrides
    ValueType.GetHashCode()

    ToFrameTime(FrameRate)

    Gets the FrameTime represented by this Timecode for a given FrameRate.

    Declaration
    public 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 frameRate is invalid.

    ToSeconds(FrameRate)

    Gets the time in seconds represented by this Timecode for a given FrameRate.

    Declaration
    public 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 frameRate is invalid.

    ToString()

    Returns a string that represents the current instance.

    Declaration
    public override string ToString()
    Returns
    Type Description
    string

    A string that represents the current instance.

    Overrides
    ValueType.ToString()

    Operators

    operator ==(Timecode, Timecode)

    Determines 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
    bool

    true if a and b represent the same value; otherwise, false.

    operator >(Timecode, Timecode)

    Determines whether one specified Timecode is later than another specified 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
    bool

    true if a is later than b; otherwise, false.

    operator >=(Timecode, Timecode)

    Determines whether one specified Timecode is later than or the same as another specified 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
    bool

    true if a is later than or the same as b; otherwise, false.

    operator !=(Timecode, Timecode)

    Determines 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
    bool

    true if a and b do not represent the same value; otherwise, false.

    operator <(Timecode, Timecode)

    Determines whether one specified Timecode is earlier than another specified 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
    bool

    true if a is earlier than b; otherwise, false.

    operator <=(Timecode, Timecode)

    Determines whether one specified Timecode is earlier than or the same as another specified 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
    bool

    true if a is earlier than or the same as b; otherwise, false.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)