swift and CMTimeMake
Asked Answered
T

1

17

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?

Thiosinamine answered 25/6, 2014 at 11:30 Comment(0)
J
33

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)
Jacqulynjactation answered 25/6, 2014 at 11:42 Comment(2)
if CMTimeMake also receives seconds what is the difference with CMTimeMakeWithSeconds? and if preferredTimeScale is just the denominator in CMTimeMake it is not clear what is its purpose in CMTimeMakeWithSecondsDermis
@dashesy: CMTimeMake(value, timescale) returns a CMTime with the given value and timescale, representing seconds = value/timescale (compare for example https://mcmap.net/q/145285/-trying-to-understand-cmtime). CMTimeMakeWithSeconds(seconds, preferredTimeScale) returns a CMTime where value and timescale are chosen such that seconds=value/timescale, and timescale is preferredTimeScale (or a fraction thereof in the case of an overflow). As an example CMTimeMake(2, 10) and CMTimeMakeWithSeconds(0.2, 10) give the same result.Jacqulynjactation

© 2022 - 2024 — McMap. All rights reserved.