Converting CMTime to Timecode
#69
Answered
by
orchetect
latenitefilms
asked this question in
Q&A
|
Sorry, this is a dumb newbie question... What's the best way to convert For example, if I have the current playhead time, and the frame duration in |
Answered by
orchetect
Dec 16, 2023
Replies: 1 comment 4 replies
|
First construct a let frameDuration = CMTime(value: 1, timescale: 25)
let tcFrameRate = TimecodeFrameRate(frameDuration: frameDuration)Then construct a If the play position is also a let playheadPosition = CMTime( /* ... */ )
let tc = try Timecode(.cmTime(playheadPosition), at: tcFrameRate)If the play position is a different time format, such as floating-point elapsed seconds, you can use a different time value type. It supports quite a few formats. let playheadPosition: TimeInterval = 12.45
let tc = try Timecode(.realTime(seconds: playheadPosition), at: tcFrameRate)To get the timecode string, with or without subframes: let string = tc.stringValue() // "00:00:00:00"
let string = tc.stringValue(format: [.showSubFrames]) // "00:00:00:00.00" |
4 replies
Answer selected by
latenitefilms
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First construct a
TimecodeFrameRateinstance from the frame duration.Then construct a
Timecodeinstance from the playhead position.If the play position is also a
CMTime, and assuming the video starts at00:00:00:00, you can do this:If the play position is a different time format, such as floating-point elapsed seconds, you can use a different time value type. It supports quite a few formats.