How to add CMTime to NSMutableDictionary?

I'm currently trying to add some video clip settings to NSMutableDictionary, including two CMTime objects.

I am trying to save the used video stream (indicated by an integer), clip duration (CMTime) and clip start time (CMTime), which are defined elsewhere in the code.

I'm probably stupid, but I can’t figure out how to add CMTimes to the dictionary, I get “Send CMTime” to the error parameter of incompatible type “id”.

I tried both setObject and setValue without success and cannot find the answer anywhere.

NSMutableDictionary *clipDetails = [NSMutableDictionary dictionary];
[clipDetails setObject:[NSNumber numberWithInteger:currentStream] forKey:@"stream"];
[clipDetails setObject:startTime forKey:@"clipStart"];
[clipDetails setObject:duration forKey:@"duration"];
+3
source share
4 answers

CMTime , Objective C, NSValue:

CMTime startTime = (...);
NSValue *startValue = [NSValue valueWithBytes:&startTime objCType:@encode(CMTime)];
[clipDetails setObject:startValue forKey:@"startTime"];

:

CMTime startTime;
NSValue *startValue = [clipDetails objectForKey:@"startTime"];
[startValue getValue:&startTime];

Sidenote, :

clipDetails[@"startTime"] = ...;
NSValue *value = clipDetails[@"startTime"];

; , AVFoundation CMTime-:

clipDetails[@"startTime"] = [NSValue valueWithCMTime:startTime];
CMTime startTime = [clipDetails[@"startTime"] CMTimeValue];
+12

:

NSValue *value=[NSValue valueWithCMTime:cmTime];

:

NSMutableDictionary *clipDetails = [NSMutableDictionary dictionary];
[clipDetails setObject: value forKey:@"cmtime"];
+3

CMTimeCopyAsDictionary, CMTime CFDictionaryRef CMTimeMakeFromDictionary, CMTime.

// Without ARC
 CFDictionaryRef timeAsDictionary = CMTimeCopyAsDictionary(startTime, kCFAllocatorDefault);
[clipDetails setObject:(NSDictionary*)timeAsDictionary forKey:@"clipStart"];
CFRelease(timeAsDictionary);
+2

, setObject: objectC (, , NSObject)

CMTime, on the other hand, is a structure, and you cannot use it to add to a dictionary. You will need to convert it to some other valid object ... perhaps NSDate?

0
source

All Articles