Package io.opentimeline.opentime
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.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RationalTime.RationalTimeBuilder
-
Constructor Summary
Constructors Constructor Description RationalTime()
RationalTime(double value, double rate)
RationalTime(RationalTime rationalTime)
RationalTime(RationalTime.RationalTimeBuilder rationalTimeBuilder)
-
Method Summary
Modifier and Type Method Description RationalTime
add(RationalTime other)
Returns a RationalTime object that is the sum of this and other.boolean
almostEqual(RationalTime other)
Checks if the two RationalTimes equal with a default tolerance of 0.boolean
almostEqual(RationalTime other, double delta)
Checks if the two RationalTimes equal with a tolerance of delta.int
compareTo(RationalTime rationalTime)
Compare two RationalTimesstatic RationalTime
durationFromStartEndTime(RationalTime startTime, RationalTime endTimeExclusive)
Compute duration of samples from first to last.boolean
equals(RationalTime rationalTime)
boolean
equals(java.lang.Object obj)
static RationalTime
fromFrames(double frame, double rate)
Creates a RationalTime from frame number and fpsstatic RationalTime
fromSeconds(double seconds)
Creates a RationalTime from time in seconds at rate 1.static RationalTime
fromTimecode(java.lang.String timecode, double rate, ErrorStatus errorStatus)
Convert timecode to RationalTime.static RationalTime
fromTimeString(java.lang.String timeString, double rate, ErrorStatus errorStatus)
Convert a time with microseconds string into a RationalTimedouble
getRate()
double
getValue()
boolean
isInvalidTime()
Check if the RationalTime represents a valid value and rate pair.static boolean
isValidTimecodeRate(double rate)
Check if the timecode rate is valid.RationalTime
rescaledTo(double newRate)
Returns the time for this time converted to newRateRationalTime
rescaledTo(RationalTime rationalTime)
Returns the time for this time converted to new rate of a RationalTimeRationalTime
subtract(RationalTime other)
Returns a RationalTime object that is this - other.int
toFrames()
Convert RationalTime to integer frames at same rateint
toFrames(double rate)
Convert RationalTime to integer frames at new ratedouble
toSeconds()
Convert RationalTime to time value in secondsjava.lang.String
toString()
java.lang.String
toTimecode(double rate, IsDropFrameRate dropFrame, ErrorStatus errorStatus)
Convert RationalTime to timecodejava.lang.String
toTimecode(ErrorStatus errorStatus)
Convert RationalTime to timecode and automatically infer if the frame rate is a Drop FrameRate.java.lang.String
toTimeString()
Convert to time with microseconds as formatted in FFMPEGdouble
valueRescaledTo(double newRate)
Returns the time value for this converted to newRatedouble
valueRescaledTo(RationalTime rationalTime)
Returns the time value for this converted to new rate of a RationalTime
-
Constructor Details
-
RationalTime
public RationalTime() -
RationalTime
public RationalTime(double value, double rate) -
RationalTime
-
RationalTime
-
-
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
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
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
Returns the time for this time converted to newRate- Parameters:
newRate
- new rate- Returns:
- time for this time converted to newRate
-
rescaledTo
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
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
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
Checks if the two RationalTimes equal with a tolerance of delta.- Parameters:
other
- other RationalTimedelta
- 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 durationendTimeExclusive
- 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
Creates a RationalTime from frame number and fps- Parameters:
frame
- frame numberrate
- rate- Returns:
- equivalent RationalTime
-
fromSeconds
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 timecoderate
- the frame-rate to calculate timecode in terms oferrorStatus
- 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 timerate
- The frame-rate to calculate timecode in terms oferrorStatus
- 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 ofdropFrame
- should the algorithm drop frames while conversion? [InferFromRate, ForceYes, ForceNo]errorStatus
- errorStatus to report error in conversion- Returns:
- equivalent timecode
-
toTimecode
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
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equals
in classjava.lang.Object
-
compareTo
Compare two RationalTimes- Specified by:
compareTo
in interfacejava.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 classjava.lang.Object
-