CMTime / CMTimeMake noob question

CMTimeMake does not give me the expected results. The following code:

CMTime testTime = CMTimeMake(0, 30);
NSLog(@"testTime w/ input 0, 30: value: %d, timescale %d, seconds: %f",
       testTime.value, testTime.timescale,
      (float) testTime.value / testTime.timescale);

testTime = CMTimeMake(1, 30);
NSLog(@"testTime w/ input 1, 30: value: %d, timescale %d, seconds: %f",
      testTime.value, testTime.timescale,
      (float) testTime.value / testTime.timescale);

testTime = CMTimeMake(15, 30);
NSLog(@"testTime w/ input 15, 30: value: %d, timescale %d, seconds: %f",
      testTime.value, testTime.timescale,
      (float) testTime.value / testTime.timescale);

outputs the following result:

testTime w / input 0, 30: value: 0, timeline 0, seconds: 0.000000

testTime w / input 1, 60: value: 1, timeline 0, seconds: 0.000000

testTime w / input 15, 60: value: 15, timeline 0, seconds: 0.000000

Why is testTime.timescale always zero?

+3
source share
1 answer

This is a problem with your format string for NSLog. Since the title of the question indicates that you are “noob,” I will take some time to explain what is happening here.

Functions that accept a variable number of type arguments NSLog(NSString* format, ...)must read additional arguments based on a format string ...

  • %d : (32 ) .
  • %f : (32 ) .

:

%d %d %f , :

testTime.value     // A 64-bit integer (8 bytes) with the value 15
testTime.timescale // A 32-bit integer (4-bytes) with the value 30
(float)15 / 30     // A 32-bit float (4-bytes) with the value 0.5f

- , , 32- testTime.value %d, , , 15, %d %f 32- (0) , , , 0.0. , 0.0 , , 30 float, 4.2E-44 - - , .

, - %d %lld, . testTime .

+3

All Articles