Questions tagged [cmtime]

CMTime structs are non-opaque mutable structs representing times (either timestamps or durations). A CMTime is represented as a rational number, with a numerator (an int64_t value), and a denominator (an int32_t timescale). A flags field allows various non-numeric values to be stored (+infinity, -infinity, indefinite, invalid). There is also a flag to mark whether or not the time is completely precise, or had to be rounded at some point in its past.

CMTime structs are non-opaque mutable structs representing times (either timestamps or durations).

A CMTime is represented as a rational number, with a numerator (an int64_t value), and a denominator (an int32_t timescale). A flags field allows various non-numeric values to be stored (+infinity, -infinity, indefinite, invalid). There is also a flag to mark whether or not the time is completely precise, or had to be rounded at some point in its past.

CMTimes contain an epoch number, which is usually set to 0, but can be used to distinguish unrelated timelines: for example, it could be incremented each time through a presentation loop, to differentiate between time N in loop 0 from time N in loop 1.

Click here for Apple Documentaion of CMTime class.

98 questions
74
votes
3 answers

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…
RileyE
  • 10,874
  • 13
  • 63
  • 106
63
votes
6 answers

CMTime seconds output

This may seem ridiculous, but how can I output the seconds of CMTime to the console in Objective-C? I simply need the value divided by the timescale and then somehow see it in the console.
arik
  • 28,170
  • 36
  • 100
  • 156
26
votes
11 answers

Converting CMTime to human readable time in objective-c

So I have a CMTime from a video. How do I convert it into a nice string like in the video time duration label in the Photo App. Is there some convenience methods that handle this? Thanks. AVURLAsset* videoAsset = [AVURLAsset URLAssetWithURL:url…
randomor
  • 5,329
  • 4
  • 46
  • 68
20
votes
4 answers

AVPlayer - Add Seconds to CMTime

How can I add 5 seconds to my current playing Time? Actually this is my code: CMTime currentTime = music.currentTime; I can´t use CMTimeGetSeconds() , because I need the CMTime format. Thank you for your answers... EDIT: How can I set a variable…
Lorenz Wöhr
  • 855
  • 3
  • 14
  • 22
19
votes
3 answers

objectiveC/CMTime - convert AVPlayer.duration to milliseconds

I'm creating an app for playing a ringtone and I'd want to know the current time in milliseconds of the played ringtone every time. CMTime cTime = player_.currentTime; float currentTime = cTime.value / cTime.timescale; That currentTime here gets the…
nano
  • 2,511
  • 4
  • 25
  • 42
17
votes
1 answer

swift and CMTimeMake

I try to capture video: https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html#//apple_ref/doc/uid/TP40010188-CH5-SW26 var maxDuration : CMTime = CMTimeMake(seconds,…
Andrew Skrypnik
  • 183
  • 1
  • 2
  • 10
16
votes
4 answers

Using seconds in AVPlayer seekToTime

this should be a simple one. I have an AVPlayer playing a video file and I want to be able to jump to a specific time but I'm having some trouble understanding how CMTime works. I need to specify the time in seconds. For example: if I wanted to jump…
guardabrazo
  • 1,219
  • 1
  • 13
  • 26
15
votes
2 answers

Xcode 6- SWIFT- Cast CMTime as Float

var songs = MPMediaQuery() var localSongs = songs.items songList = NSMutableArray(array: localSongs) tableView.reloadData() var song = MPMediaItem(coder: songList[0] as NSCoder) var currentItem = AVPlayerItem(URL:…
Abdou23
  • 363
  • 1
  • 4
  • 11
14
votes
3 answers

AVAssetWriterInputPixelBufferAdaptor and CMTime

I'm writing some frames to video with AVAssetWriterInputPixelBufferAdaptor, and the behavior w.r.t. time isn't what I'd expect. If I write just one frame: [videoWriter startSessionAtSourceTime:kCMTimeZero]; [adaptor appendPixelBuffer:pxBuffer…
David Moles
  • 48,006
  • 27
  • 136
  • 235
8
votes
3 answers

How Does CMTimeCompare Work?

How does CMTimeCompare work? Apple seems to have left out the return values from their documentation. https://developer.apple.com/library/mac/#documentation/CoreMedia/Reference/CMTime/Reference/reference.html I assume if the times are equal it…
Dex
  • 12,527
  • 15
  • 69
  • 90
8
votes
2 answers

Movement by a single frame in CMTime and AVFoundation

I'm attempting to play a video with AVFoundation. I am using the following code for a button that advances the playback by one frame. It works intermittently, on some executions it will do the right thing and advance one frame, but most times I will…
Wil Gieseler
  • 1,893
  • 1
  • 17
  • 18
8
votes
0 answers

How to accurately set fast shutter speeds (exposure duration) on an AVCaptureDevice?

I'm working on a camera app for IOS (13). For that I use an AVCaptureSession in conjunction with an AVCaptureVideoPreviewLayer. So far everything works fine. Now I want to let the user choose and set a custom shutter speed (exposure duration) out of…
marcoavol
  • 81
  • 1
  • 4
8
votes
1 answer

Convert from NStimeInterval to CMTime accurately

I am using two players one is MPMoviePlayerController and the other is AVPlayer. henever MPMoviePlayerController is seeked, it sets the time to AVPlayer. Everything is working fine. While converting MPMoviePlayerController current time to CMTime it…
7
votes
1 answer

How do I convert a CMTime to an NSValue in Swift?

I was trying to make use of AVPlayer's addBoundaryTimeObserverForTimes method from swift and ran into a problem converting CMTimes to NSValues, which is what addBoundaryTimeObserverForTimes take as input. In the end I resorted to wrapping [NSString…
Mike Akers
  • 12,039
  • 14
  • 58
  • 71
6
votes
2 answers

AVPlayer seekToTime not working properly

Im having a problem with seeking with AVPlayer.seekToTime, I have the time index that I want to seek to inside a scrollViewDidScroll method like this: func scrollViewDidScroll(scrollView: UIScrollView) { let offsetTime =…
Garret Kaye
  • 2,412
  • 4
  • 21
  • 45
1
2 3 4 5 6 7