Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4100234
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:32:24+00:00 2026-05-20T20:32:24+00:00

I’m writing an application that uses AVFoundation and CMTime. I have logged the values

  • 0

I’m writing an application that uses AVFoundation and CMTime. I have logged the values of my CMTime instances created using CMTimeMake(). This value seems to be rounded to the nearest integer. I need a CMTime instance with a precise value, without rounding.

I have seen the rounding constants in the CMTime reference:

enum {
   kCMTimeRoundingMethod_RoundHalfAwayFromZero = 1,
   kCMTimeRoundingMethod_RoundTowardZero = 2,
   kCMTimeRoundingMethod_RoundAwayFromZero = 3,
   kCMTimeRoundingMethod_QuickTime = 4,
   kCMTimeRoundingMethod_RoundTowardPositiveInfinity = 5,
   kCMTimeRoundingMethod_RoundTowardNegativeInfinity = 6,

   kCMTimeRoundingMethod_Default = kCMTimeRoundingMethod_RoundHalfAwayFromZero
};

There aren’t any example of how I can control which of these strategies is applied to a CMTime instance? Or, if this isn’t the right way, how can I extract a precise value from a CMTime instance?


Edit:

I have found and tested CMTIME_HAS_BEEN_ROUNDED(). I passed my CMTime instance to this function and it returns No (indicating that the value has not been rounded). So why am I losing precision?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:32:25+00:00Added an answer on May 20, 2026 at 8:32 pm

    If you read the documentation for CMTime you will see that it stores time as a rational number using a numerator and denominator. The numerator is int64_t while the denominator is int32_t.

    The numerator specifies how many “ticks” have passed, and the denominator specifies how many “ticks” per second.

    So 0.5 seconds can be stored as:

    • 100/200: 100 ticks, 200 ticks per second
    • 500/1000: 500 ticks, 1000 ticks per second
    • 8/16, 8 ticks, 16 ticks per second

    And so forth. The way you have done it, using

    CMTimeMake([[Array objectAtIndex:i]floatValue], 1);
    

    Is saying “there is one tick per second”, and since the numerator is an integer, the float value is truncated so only the 1 is stored. Therefore you are specifying time as: 1/1, one tick has elapsed, one tick per second, so you are actually storing exactly 1 second.

    To fix this, it depends on what you want to do and whether you care about the timescale. Apple recommends a timescale of 600, but if you don’t care, you can just do this:

    CMTimeMake([[Array objectAtIndex:i]floatValue]*1000, 1000);
    

    That sets timescale to 1000, so 1000 ticks per second, so one millisecond per tick. It also converts the time in seconds to milliseconds. Note that it truncates the 4th digit, so if you had 1.2345 you just get 1.234 not 1.235. If that matters to you, see roundf.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.