Converting CMTime to Timecode #69
-
| 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 |
Beta Was this translation helpful? Give feedback.
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" |
Beta Was this translation helpful? Give feedback.
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.