Skip to content

Converting CMTime to Timecode #69

Answered by orchetect
latenitefilms asked this question in Q&A
Discussion options

You must be logged in to vote

First construct a TimecodeFrameRate instance from the frame duration.

let frameDuration = CMTime(value: 1, timescale: 25)
let tcFrameRate = TimecodeFrameRate(frameDuration: frameDuration)

Then construct a Timecode instance from the playhead position.

If the play position is also a CMTime, and assuming the video starts at 00:00:00:00, you can do this:

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(

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@latenitefilms
Comment options

@orchetect
Comment options

@orchetect
Comment options

@latenitefilms
Comment options

Answer selected by latenitefilms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants