Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift and CMTimeMake

Tags:

ios

swift

cmtime

I try to capture video:
https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html#//apple_ref/doc/uid/TP40010188-CH5-SW26

var maxDuration : CMTime = CMTimeMake(seconds, preferredTimeScale)
aMovieFileOutput.maxRecordedDuration = CMTimeMake(seconds, preferredTimeScale)

1 row have error: Use of module 'CMTime' as a type
2 row have error: Use of unresolved identifier 'CMTimeMake'

What I do wrong?

like image 227
Andrew Skrypnik Avatar asked Jun 25 '14 11:06

Andrew Skrypnik


People also ask

What is CMTimeMake?

1) CMTimeMake(1,10) means duration of 1 second and timescale of 10, or 10 frames per second. This means 1s duration of video with 10 frames? 2) CMTime lastTime=CMTimeMake(1,10); CMTime frameTime=CMTimeMake(1, 10); CMTime currentTime=CMTimeAdd(lastTime, frameTime)

What is CMTime Swift?

Overview. Core Media represents time as a rational value, with a time value as the numerator and timescale as the denominator. The structure can represent a specific numeric time in the media timeline, and can also represent nonnumeric values like invalid and indefinite times or positive and negative infinity.


1 Answers

CMTime and CMTimeMake are defined in the "CoreMedia" module, therefore you have to

import CoreMedia

Then this compiles without problems:

let seconds : Int64 = 10
let preferredTimeScale : Int32 = 1
let aMovieFileOutput = AVCaptureMovieFileOutput()
let maxDuration : CMTime = CMTimeMake(seconds, preferredTimeScale)
aMovieFileOutput.maxRecordedDuration = maxDuration

Update for Swift 3:

let maxDuration = CMTime(seconds: Double(seconds), preferredTimescale: 1)
like image 180
Martin R Avatar answered Sep 18 '22 18:09

Martin R