Package com.peterphi.std.types
Class Timecode
java.lang.Object
com.peterphi.std.types.Timecode
Represents a timecode, dd:hh:mm:ss:ff - where ff may be an arbitrary length
Timecodes containing days are not well supported.
Timecodes containing days are not well supported.
-
Method Summary
Modifier and TypeMethodDescriptionadd(SampleCount samples) Add some samples to this timecodeaddPrecise(SampleCount samples) Add some samples to this timecode, throwing an exception if precision would be lostbooleanbuilder()Return a TimecodeBuilder for this Timecode instancebooleanbooleanbooleanlonglongReturns the duration of the timecode (from 00:00:00:00) in frameslonggetDurationInFrames(boolean allowDropFrameRemoval) Returns the duration of the timecode (from 00:00:00:00) in frameslongReturns the duration of the timecode in seconds (from 00:00:00:00), ignoring frameslonglongGet the frames part of this timecode in microsecondslongGet the frames part of this timecode in millisecondslongstatic final TimecodegetInstance(long frameNumber, boolean dropFrame, Timebase timebase) static final TimecodegetInstance(long frameNumber, boolean dropFrame, Timebase timebase, boolean supportDays) Deprecated.use method without supportDaysstatic final TimecodegetInstance(SampleCount samples) static final TimecodegetInstance(SampleCount samples, boolean dropFrame) static final TimecodegetInstance(SampleCount samples, boolean dropFrame, boolean supportDays) Deprecated.use method without supportDays (supportDays is now implicitly true) or dropFrame (drop frame timecode is not correctly supported currently)static final TimecodegetInstance(String encoded) Parse a Timecode encoded in the encoded style for this library ([-][dd:]hh:mm:ss:ff@timebase).static final TimecodegetInstance(String smpte, Timebase timebase) Part a Timecode encoded in the SMPTE style ([dd:]hh:mm:ss:ff- or[dd:]hh:mm:ss;fffor drop-frame timecode) alongside a timebase.longReturns a sample count as a delta from the timecode 00:00:00:00getSampleCount(Timecode from) Returns a sample count as an offset from the provided timecode
The resulting timecode will be expressed in the same timebase asthisobjectReturns a sample count as an offset from the provided timecode
The resulting timecode will be expressed in the same timebase asthisobjectlongstatic final TimecodegetSmpteTimecode(String smpte, Timebase timebase) Deprecated.booleaninthashCode()booleanbooleanbooleanbooleanResample this timecode to another timebase.Resample this timecode to another timebase.
If source+destination timecodes are non-drop frame then this is achieved by resampling the frames part of the timecode. If either side uses drop-frame then the resample works by converting this timecode into an amount of time (with half-up rounding rules, seeTimebase.resample(double, Timebase, Timebase))resamplePrecise(Timebase toRate) Resamplessubtract(SampleCount samples) Subtract some samples from this timecodeReturns the timecode in the Encoded Timecode format for this library.toEncodedString(boolean includeDays) Returns the timecode in the Encoded Timecode format for this library.Returns the timecode in FFmpeg format.toISODurationWithFrames(boolean includeDays) Returns the timecode in a format that is similar to the ISO 8601 Duration format, except with an F field for frames.Return a SMPTE string of the format, dropping the days component.toSMPTEString(boolean includeDays) Return a SMPTE-style string of the format[-][dd:]hh:mm:ss:ff(or[-][dd:]hh:mm:ss;fffor drop-frame timecode)toString()Returns the timecode as a String, formatted as either: hh:mm:ss:ff for non-dropframe timecode (where ff is of arbitrary length) hh:mm:ss;ff for dropframe timecode (where ff is of arbitrary length)Deprecated.use getSampleCount().toEncodedString();static final TimecodeParse a Timecode encoded in the encoded style for this library ([-][dd:]hh:mm:ss:ff@timebase).
-
Method Details
-
builder
Return a TimecodeBuilder for this Timecode instance- Returns:
- a TimecodeBuilder pre-populated with this timecode
-
getDurationInFrames
public long getDurationInFrames()Returns the duration of the timecode (from 00:00:00:00) in frames- Returns:
-
getDurationInFrames
public long getDurationInFrames(boolean allowDropFrameRemoval) Returns the duration of the timecode (from 00:00:00:00) in frames- Returns:
-
getDurationInSeconds
public long getDurationInSeconds()Returns the duration of the timecode in seconds (from 00:00:00:00), ignoring frames -
getFramesPartAsMicroseconds
public long getFramesPartAsMicroseconds()Get the frames part of this timecode in microseconds- Returns:
-
getFramesPartAsMilliseconds
public long getFramesPartAsMilliseconds()Get the frames part of this timecode in milliseconds- Returns:
-
isDropFrame
public boolean isDropFrame() -
isNegative
public boolean isNegative() -
getFramesPart
public long getFramesPart() -
getSecondsPart
public long getSecondsPart() -
getMinutesPart
public long getMinutesPart() -
getHoursPart
public long getHoursPart() -
getDaysPart
public long getDaysPart() -
getTimebase
-
toSMPTEString
Return a SMPTE string of the format, dropping the days component.- Returns:
[-]hh:mm:ss:ff(or[-]hh:mm:ss;fffor drop-frame timecode)
-
toSMPTEString
Return a SMPTE-style string of the format[-][dd:]hh:mm:ss:ff(or[-][dd:]hh:mm:ss;fffor drop-frame timecode)- Parameters:
includeDays- if true (and this timecode has a days component), emit a timecode with a days field. If false then the days component will be ignored- Returns:
-
toFfmpegString
Returns the timecode in FFmpeg format. The format of the timecode is hh:mm:ss:uuuuuu (where u = microseconds). The hours component counts days as well (i.e.01:01:01:01:00will be encoded as25:01:01.000000) -
toISODurationWithFrames
Returns the timecode in a format that is similar to the ISO 8601 Duration format, except with an F field for frames.- Returns:
-
toEncodedString
Returns the timecode in the Encoded Timecode format for this library. The format of this timecode issmpte timecode including days@ratewhere rate isdenominator:[numerator](where numerator, if omitted, is 1). SeeTimebasefor further information on the encoding of the timebase- Returns:
-
toEncodedString
Returns the timecode in the Encoded Timecode format for this library. The format of this timecode issmpte timecode optionally including days@ratewhere rate isdenominator:[numerator](where numerator, if omitted, is 1). SeeTimebasefor further information on the encoding of the timebase- Parameters:
includeDays- true if the days component should be emitted too (if non-zero)- Returns:
-
toVidispineString
Deprecated.use getSampleCount().toEncodedString();Returns the timecode in the Vidispine Timecode format. The format of this timecode isframes@ratewhere rate isdenominator:[numerator](where numerator, if omitted, is 1)- Returns:
-
between
-
eq
-
gt
-
lt
-
le
-
ge
-
subtract
Subtract some samples from this timecode- Parameters:
samples-- Returns:
-
add
Add some samples to this timecode- Parameters:
samples-- Returns:
-
addPrecise
Add some samples to this timecode, throwing an exception if precision would be lost- Parameters:
samples-- Returns:
- Throws:
ResamplingException- if the requested addition would result in a loss of accuracy due to resampling
-
getSampleCount
Returns a sample count as a delta from the timecode 00:00:00:00- Returns:
-
getSampleCount
Returns a sample count as an offset from the provided timecode
The resulting timecode will be expressed in the same timebase asthisobject- Parameters:
from- the start timecode- Returns:
- a SampleCount expressing the delta between
fromandthis - Throws:
ResamplingException- if the delta cannot be expressed without losing accuracy
-
getSampleCountPrecise
Returns a sample count as an offset from the provided timecode
The resulting timecode will be expressed in the same timebase asthisobject- Parameters:
from- the start timecode- Returns:
- a SampleCount expressing the delta between
fromandthis - Throws:
ResamplingException- if the delta cannot be expressed without losing accuracy
-
resample
Resample this timecode to another timebase. If the destination rate is NTSC (29.97) or NTSC_60 (59.94) then it will be resampled to a drop-frame Timecode- Parameters:
toRate- the destination rate- Returns:
-
resample
Resample this timecode to another timebase.
- If source+destination timecodes are non-drop frame then this is achieved by resampling the frames part of the timecode.
- If either side uses drop-frame then the resample works by converting this timecode into an amount of time (with half-up rounding rules, see
Timebase.resample(double, Timebase, Timebase))
- Parameters:
toRate- the destination ratetoDropFrame- if true, resulting Timecode will be marked as drop-frame (N.B. this flag will be checked against canBeDropFrame on the timebase - so if it's not 29.97 or 59.94 then it'll throw an exception- Returns:
- a Timecode expressed in toRate
- Throws:
IllegalArgumentException- if toDropFrame is set to true but toRate is not on the approved drop-frame list (NTSC and NTSC_60)
-
resamplePrecise
Resamples- Parameters:
toRate-- Returns:
- Throws:
ResamplingException
-
equals
-
hashCode
public int hashCode() -
toString
Returns the timecode as a String, formatted as either:- hh:mm:ss:ff for non-dropframe timecode (where ff is of arbitrary length)
- hh:mm:ss;ff for dropframe timecode (where ff is of arbitrary length)
-
getInstance
- Parameters:
frameNumber-dropFrame- set to true to indicate that the frame-rate excludes dropframestimebase-- Returns:
- a timecode representation of the given data, null when a timecode can not be generated (i.e. duration exceeds a day)
-
getInstance
-
getInstance
- Parameters:
samples-dropFrame-- Returns:
-
getInstance
@Deprecated public static final Timecode getInstance(SampleCount samples, boolean dropFrame, boolean supportDays) Deprecated.use method without supportDays (supportDays is now implicitly true) or dropFrame (drop frame timecode is not correctly supported currently)- Parameters:
samples-dropFrame-supportDays-- Returns:
-
getInstance
Parse a Timecode encoded in the encoded style for this library ([-][dd:]hh:mm:ss:ff@timebase). SeeTimebase.getInstance(java.lang.String)for information on valid timebase representations- Parameters:
encoded- a timecode encoded ashh:mm:ss:ff@timebase- Returns:
- a parsed timecode object
- Throws:
RuntimeException- if the encoded string is not well-formed or could not be parsed
-
valueOf
Parse a Timecode encoded in the encoded style for this library ([-][dd:]hh:mm:ss:ff@timebase). SeeTimebase.getInstance(java.lang.String)for information on valid timebase representations- Parameters:
encoded- a timecode encoded ashh:mm:ss:ff@timebase- Returns:
- a parsed timecode object (or null if the input is null)
- Throws:
RuntimeException- if the encoded string is not well-formed or could not be parsed
-
getSmpteTimecode
Deprecated.Part an SMPTE formatted timecode ([-][dd:]hh:mm:ss:ff-or[-][dd:]hh:mm:ss;fffor drop-frame timecode alongside a timebase- Parameters:
smpte-timebase-- Returns:
-
getInstance
Part a Timecode encoded in the SMPTE style ([dd:]hh:mm:ss:ff- or[dd:]hh:mm:ss;fffor drop-frame timecode) alongside a timebase.- Parameters:
smpte- the SMPTE-encoded timecodetimebase- the timebase to interpret the SMPTE timecode in- Returns:
- a parsed timecode object
- Throws:
RuntimeException- if parsing fails
-
getInstance
@Deprecated public static final Timecode getInstance(long frameNumber, boolean dropFrame, Timebase timebase, boolean supportDays) Deprecated.use method without supportDays- Parameters:
frameNumber- the frame offset from zerodropFrame- set to true to indicate that the frame-rate excludes dropframes (keep false for PAL)timebase- the timebasesupportDays- true if the resulting Timecode may use the days field (default false)- Returns:
- a timecode representation of the given data, null when a timecode can not be generated (i.e. duration exceeds a day)
-