SMPTE timecode to CMTime

Greetings,

I have my own class for handling SMPTE timecode (formatted as 00:00:00:00). To work with AVPlayer, AVAsset, etc I need to use CMTime. I'd like to convert my SMPTE timecode to CMTime but am running into concerns because while I can convert my timecode to seconds stored in a Float64, CMTimeMakeWithSeconds requires an Int32 as the preferredTimeScale.


The quicktime I'm using as a test file (and most other i'd use) has the frame rate of 23.976.

Shouldn't I be using 23.976 as the preferredTimeScale in CMTime? If so, this needs to a be an Int32 at which point I lose precision.

Can anyone explain or point to examples how to best use CMTime for tracking timecode?

I notice the naturalTimeScale of my sample track is 24000. What does this really represent?

The specific use of converting SMPTE timecode to CMTime is allowing the user to manually enter a timecode and the playback cursor will jump to that spot in the AVPlayer.


Thank you very much for any ideas or suggestions on making this work.


-Cablet

Answered by cablet in 89170022

As the documentation states we should be using 600 as the CMTime preferredTimeScale. I didn't realize that CMTimeMakeSeconds will do the math for me. This is what solved my issue.

I think I found most of what I need. By using the AVAssetTrack.timeRange method I can get the files CMTime info. This provides me with the correct info to use in my math so I can locate a specific point in time using user entered data.

Accepted Answer

As the documentation states we should be using 600 as the CMTime preferredTimeScale. I didn't realize that CMTimeMakeSeconds will do the math for me. This is what solved my issue.

The natural timescale is 24000 because a frame duration of 1001 represents your frame rate very well (actually this is the frame rate's definition).

Duration 1000 on a timescale of 23976 would also be very accurate.

Timescale 600 is the QuickTime default. Final Cut has other preferences. See here

https://developer.apple.com/library/mac/qa/qa1447/_index.html


Jan E.

SMPTE timecode to CMTime
 
 
Q