Class RationalTime

java.lang.Object
io.opentimeline.opentime.RationalTime
All Implemented Interfaces:
java.lang.Comparable<RationalTime>

public class RationalTime
extends java.lang.Object
implements java.lang.Comparable<RationalTime>
Represents an instantaneous point in time, value * (1/rate) seconds from time 0 seconds.
  • Constructor Details

  • Method Details

    • getValue

      public double getValue()
      Returns:
      value
    • getRate

      public double getRate()
      Returns:
      rate
    • isInvalidTime

      public boolean isInvalidTime()
      Check if the RationalTime represents a valid value and rate pair.
      Returns:
      is value and rate pair a valid RationalTime?
    • add

      public RationalTime add​(RationalTime other)
      Returns a RationalTime object that is the sum of this and other. If this and other have differing time rates, the result will have the have the rate of the faster time.
      Parameters:
      other - other RationalTime to add
      Returns:
      sum of the two RationalTimes
    • subtract

      public RationalTime subtract​(RationalTime other)
      Returns a RationalTime object that is this - other. If this and other have differing time rates, the result will have the have the rate of the faster time.
      Parameters:
      other - other RationalTime to add
      Returns:
      difference of the two RationalTimes
    • rescaledTo

      public RationalTime rescaledTo​(double newRate)
      Returns the time for this time converted to newRate
      Parameters:
      newRate - new rate
      Returns:
      time for this time converted to newRate
    • rescaledTo

      public RationalTime rescaledTo​(RationalTime rationalTime)
      Returns the time for this time converted to new rate of a RationalTime
      Parameters:
      rationalTime - RationalTime for new rate
      Returns:
      time for this time converted to new rate of a RationalTime
    • valueRescaledTo

      public double valueRescaledTo​(double newRate)
      Returns the time value for this converted to newRate
      Parameters:
      newRate - new Rate
      Returns:
      time value for this converted to newRate
    • valueRescaledTo

      public double valueRescaledTo​(RationalTime rationalTime)
      Returns the time value for this converted to new rate of a RationalTime
      Parameters:
      rationalTime - RationalTime for new rate
      Returns:
      time value for this converted to new rate of a RationalTime
    • almostEqual

      public boolean almostEqual​(RationalTime other)
      Checks if the two RationalTimes equal with a default tolerance of 0.
      Parameters:
      other - other RationalTime
      Returns:
      are the two RationalTimes equal with a default tolerance of 0?
    • almostEqual

      public boolean almostEqual​(RationalTime other, double delta)
      Checks if the two RationalTimes equal with a tolerance of delta.
      Parameters:
      other - other RationalTime
      delta - tolerance for equality comparison
      Returns:
      are the two RationalTimes equal with a tolerance of delta?
    • durationFromStartEndTime

      public static RationalTime durationFromStartEndTime​(RationalTime startTime, RationalTime endTimeExclusive)
      Compute duration of samples from first to last. This is not the same as distance. For example, the duration of a clip from frame 10 to frame 15 is 6 frames. The result will be at the rate of startTime.
      Parameters:
      startTime - start time of duration
      endTimeExclusive - end time of duration
      Returns:
      duration
    • isValidTimecodeRate

      public static boolean isValidTimecodeRate​(double rate)
      Check if the timecode rate is valid.
      Parameters:
      rate - frame rate in question
      Returns:
      is the timecode rate valid?
    • fromFrames

      public static RationalTime fromFrames​(double frame, double rate)
      Creates a RationalTime from frame number and fps
      Parameters:
      frame - frame number
      rate - rate
      Returns:
      equivalent RationalTime
    • fromSeconds

      public static RationalTime fromSeconds​(double seconds)
      Creates a RationalTime from time in seconds at rate 1.
      Parameters:
      seconds - time in seconds
      Returns:
      equivalent RationalTime at rate 1
    • fromTimecode

      public static RationalTime fromTimecode​(java.lang.String timecode, double rate, ErrorStatus errorStatus)
      Convert timecode to RationalTime.
      Parameters:
      timecode - a colon-delimited timecode
      rate - the frame-rate to calculate timecode in terms of
      errorStatus - errorStatus to report error in conversion
      Returns:
      RationalTime equivalent to timecode
    • fromTimeString

      public static RationalTime fromTimeString​(java.lang.String timeString, double rate, ErrorStatus errorStatus)
      Convert a time with microseconds string into a RationalTime
      Parameters:
      timeString - a HH:MM:ss.ms time
      rate - The frame-rate to calculate timecode in terms of
      errorStatus - errorStatus to report error in conversion
      Returns:
      RationalTime equivalent to timestring
    • toFrames

      public int toFrames()
      Convert RationalTime to integer frames at same rate
      Returns:
      integer frames equivalent to the RationalTime at same rate
    • toFrames

      public int toFrames​(double rate)
      Convert RationalTime to integer frames at new rate
      Parameters:
      rate - new rate
      Returns:
      integer frames equivalent to the RationalTime at new rate
    • toSeconds

      public double toSeconds()
      Convert RationalTime to time value in seconds
      Returns:
      time value in seconds
    • toTimecode

      public java.lang.String toTimecode​(double rate, IsDropFrameRate dropFrame, ErrorStatus errorStatus)
      Convert RationalTime to timecode
      Parameters:
      rate - the frame-rate to calculate timecode in terms of
      dropFrame - should the algorithm drop frames while conversion? [InferFromRate, ForceYes, ForceNo]
      errorStatus - errorStatus to report error in conversion
      Returns:
      equivalent timecode
    • toTimecode

      public java.lang.String toTimecode​(ErrorStatus errorStatus)
      Convert RationalTime to timecode and automatically infer if the frame rate is a Drop FrameRate.
      Parameters:
      errorStatus - errorStatus to report error in conversion
      Returns:
      equivalent timecode
    • toTimeString

      public java.lang.String toTimeString()
      Convert to time with microseconds as formatted in FFMPEG
      Returns:
      number formatted string of the RationalTime
    • equals

      public boolean equals​(RationalTime rationalTime)
    • equals

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object
    • compareTo

      public int compareTo​(RationalTime rationalTime)
      Compare two RationalTimes
      Specified by:
      compareTo in interface java.lang.Comparable<RationalTime>
      Parameters:
      rationalTime - other RationalTime
      Returns:
      0 if equal, <0 if lhs<rhs, >0 if lhs>rhs
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object