I am trying to create a movie in Cocoa using QTKit. This movie should consist of the NSImage group that I created. I have problems with this. A common problem is that the movie is not created. I get a file that seems empty, contains only a couple of hundred bytes, but not a movie that could be talked about. Anyway, the code:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSLog(@"Creating .mov out of NSImage(s)");
NSError *error = nil;
QTMovie *movie = [[QTMovie alloc] initToWritableFile:@"Temp.mov" error:&error];
if ( error )
NSLog(@"Error creating movie: %@", [error localizedDescription]);
assert([[movie attributeForKey:QTMovieEditableAttribute] boolValue] == YES);
NSImage *image = [NSImage imageNamed:@"screen-1"];
assert(image != nil);
NSDictionary *attributesForImage = [NSDictionary dictionaryWithObjectsAndKeys:@"tiff", QTAddImageCodecType, nil];
[movie addImage:image forDuration:QTMakeTime(6000, 600) withAttributes:attributesForImage];
NSDictionary *attributesForExport = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],
QTMovieFlatten, nil];
error = nil;
BOOL didSucceed = [movie writeToFile:@"Done.mov" withAttributes:attributesForExport error:&error];
if ( ! didSucceed || error )
NSLog(@"Did not succeed. Error was: %@", [error localizedDescription]);
else
{
assert(error == nil);
NSLog(@"Did succeed.");
}
[movie release];
[[NSFileManager defaultManager] removeItemAtPath:@"Temp.mov" error:nil];
[NSApp terminate:nil];
}
The line to be followed is [movie addImage.... An error occurs here. I get the following exception:
eException', reason: '*** -[NSArray objectAtIndex:]: index (0) beyond bounds (0)'
*** Call stack at first throw:
(
0 CoreFoundation 0x90e806ba __raiseError + 410
1 libobjc.A.dylib 0x97cde509 objc_exception_throw + 56
2 CoreFoundation 0x90ec5321 -[__NSArray0 objectAtIndex:] + 209
3 QTKit 0x9387492c -[QTMovie_QuickTime addImage:forDuration:atTime:withAttributes:] + 708
4 QTKitServer 0x000208ba do_addImageAtTimeWithAttributes + 327
5 QTKitServer 0x0000cb03 _XaddImageAtTimeWithAttributes + 291
6 QTKitServer 0x000021bb QTKitServer_server + 113
7 QTKitServer 0x0001e194 mach_port_callback + 84
8 CoreFoundation 0x90dee772 __CFMachPortPerform + 338
9 CoreFoundation 0x90dea4db __CFRunLoopRun + 6523
10 CoreFoundation 0x90de8464 CFRunLoopRunSpecific + 452
11 CoreFoundation 0x90dee3a4 CFRunLoopRun + 84
12 QTKitServer 0x0001e702 main + 1068
13 QTKitServer 0x00002141 start + 53
)
I googled a lot and found nothing that really answers this question. The code is pretty simple, it looks exactly like most code samples. The image loads fine, but it doesn't add at all. Any ideas? This is a JPEG image, if relevant.