Converting CMTime to human readable time in objective-c
c, cmtime, cocoa-touch, ios, objective-c
Solution
For example you can use NSDate and it's description method. You can specify any output format you want.
> `
// First, create NSDate object using
NSDate* d = [[NSDate alloc] initWithTimeIntervalSinceNow:seconds];
// Then specify output format
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"HH:mm:ss"];
// And get output with
NSString* result = [dateFormatter stringWithDate:d];`
Problem
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 options:nil]; CMTime videoDuration = videoAsset.duration; float videoDurationSeconds = CMTimeGetSeconds(videoDuration); ```