Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

ios - Trying to understand CMTime

I have seen some examples of CMTime (Three separate links), but I still don't get it. I'm using an AVCaptureSession with AVCaptureVideoDataOutput and I want to set the max and min frame rate of the the output. My problem is I just don't understand the CMTime struct.

Apparently CMTimeMake(value, timeScale) should give me value frames every 1/timeScale seconds for a total of value/timeScale seconds, or am I getting that wrong?

Why isn't this documented anywhere in order to explain what this does?

If it does truly work like that, how would I get it to have an indefinite number of frames?

If its really simple, I'm sorry, but nothing has clicked just yet.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

A CMTime struct represents a length of time that is stored as rational number (see CMTime Reference). CMTime has a value and a timescale field, and represents the time value/timescale seconds .

CMTimeMake is a function that returns a CMTime structure, for example:

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

The last two time values t3 and t4 represent the same time value, therefore

CMTimeCompare(t3, t4) == 0

If you set the videoMinFrameDuration of a AVCaptureSession is does not make a difference if you set

connection.videoMinFrameDuration = CMTimeMake(1, 20); // or
connection.videoMinFrameDuration = CMTimeMake(2, 40);

In both cases the minimum time interval between frames is set to 1/20 = 0.05 seconds.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...