[英]Trying to understand CMTime
CMTime
結構表示存儲為有理數的時間長度(請參閱CMTime 參考)。 CMTime
有一個value
和一個timescale
字段,並表示時間value/timescale seconds
。
CMTimeMake
是一個返回CMTime
結構的函數,例如:
CMTime t1 = CMTimeMake(1, 10); // 1/10 second = 0.1 second
CMTime t2 = CMTimeMake(2, 1); // 2 seconds
CMTime t3 = CMTimeMake(3, 4); // 3/4 second = 0.75 second
CMTime t4 = CMTimeMake(6, 8); // 6/8 second = 0.75 second
最后兩個時間值t3
和t4
代表相同的時間值,因此
CMTimeCompare(t3, t4) == 0
如果您設置了AVCaptureSession
的videoMinFrameDuration
則不會有什么不同,如果您設置
connection.videoMinFrameDuration = CMTimeMake(1, 20); // or
connection.videoMinFrameDuration = CMTimeMake(2, 40);
在這兩種情況下,幀之間的最小時間間隔都設置為 1/20 = 0.05 秒。
我的經歷不同。
對於let testTime = CMTime(seconds: 3.83, preferredTimescale: 100)
如果您設置斷點並查看調試器側窗口,它會顯示:
“383 100 分之一秒”
通過在 AVPlayer 中尋找視頻中的固定偏移量進行的測試已經證實了這一點。
所以在 seconds 字段中輸入實際秒數,在 preferredTimescale 字段中輸入精度。 所以100意味着百分之一秒的精度。
做let testTime = CMTime(seconds: 3.83, preferredTimescale: 100)
仍然在視頻中尋找相同的位置,但它在調試器側窗口中顯示為“3833 1000ths of a second”
做let testTime = CMTime(seconds: 3.83, preferredTimescale: 1)
不尋找視頻中的相同位置,因為它已被截斷,並且在調試器側窗口中顯示為“3 秒”。 請注意,由於首選時間刻度,.833 部分已丟失。
CMTime(seconds: value, timescale: scale)
在一秒鍾內意味着價值/規模
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.