2017-02-23 6 views
1

私は小さな整数値を持っており、CMTimeに変換したいと思います。CMTimeを非常に小さな値にする

問題はその

CMTIMEある(値:_、タイムスケール:_)

又は

CMTimeMakeWithSeconds(値:_、タイムスケール:_)

は常にフロアを返すので、その時間は常に等しい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

感謝と同じ。私は 'CMTimeMultiplyWithFloat64(..)'が 'CMTime(..)= 1 Sec'と' smallValue'が取られた場合にも動作することを発見しました。 –

+0

@Tyrone:そうです、両方のソリューションが機能します。 –

1

質問を投稿する前に少し考えてください。

let smallValue = 0.0401588716 
let oneSec =  CMTimeMakeWithSeconds(1, timeScale: 1) 
let frameTime = CMTimeMultiplyByFloat64(oneSec , smallValue) 
print(CMTimeGetSeconds(frameTime))        // 0.040158872 
関連する問題