2017-02-23 21 views
1

저는 작은 정수 값을 가지고 있으며 이것을 CMTime으로 변환하고 싶습니다.매우 작은 값으로 CMTime 만들기

또는

CMTimeMakeWithSeconds (값 : _, 척도 : _)

문제는

CMTime (: _, 척도 _ 값) 인

은 항상 바닥을 반환하므로 시간은 항상 동일합니다. S 0.0 seconds

let smallValue = 0.0401588716 
let frameTime = CMTime(Int64(smallValue) , timeScale: 1) 
//frameTime is 0.0 seconds because of Int64 conversion 

let frameTimeInSeconds = CMTimeMakeWithSeconds(smallValue , timeScale: 1) 
// frameTimeInSeconds also returns 0.0 seconds. 
+0

출력이 –

+0

을 기대하고 무엇을'smallValue' 즉'솔루션에 대한 0.0401588716' –

답변

0

CMTime 정수 분자합니다 (value)와 분모합니다 (timescale)와 합리적 번호와 같은 시간 값을 나타낸다. 너 같은 작은 값 을 표현하려면 더 큰 시간 단위를 선택해야합니다 (원하는 정확도 인 에 따라 다름). 예 :

let smallValue = 0.0401588716 
let frameTime = CMTime(seconds: smallValue, preferredTimescale: 1000000) 

print(frameTime.seconds) // 0.040158 
+0

감사와 같은. 또한'CMTime (..) = 1 Sec'와'smallValue'가 사용되면'CMTimeMultiplyWithFloat64 (..)'가 작동하는 것을 발견했습니다. –

+0

@ Tyrone : 맞습니다. 두 가지 솔루션 모두 작동합니다. –

1

질문을 게시하기 전에 약간의 생각을 했어야합니다.

let smallValue = 0.0401588716 
let oneSec =  CMTimeMakeWithSeconds(1, timeScale: 1) 
let frameTime = CMTimeMultiplyByFloat64(oneSec , smallValue) 
print(CMTimeGetSeconds(frameTime))        // 0.040158872