QTMovie没有写入文件

时间:2012-01-20 08:53:34

标签: objective-c macos qtkit

我正在尝试将这些图像添加到QTMovie,但文件永远不会出现。我认为它与属性或addImage:

有关
NSTimeInterval t;
QTGetTimeInterval(frameInterval, &t);
NSLog(@"%f", t); // outputs 0.0333333


// --- initializes the movie ---
NSError *error = nil;

NSDictionary *at = [NSDictionary dictionaryWithObjectsAndKeys:
                    [NSNumber numberWithBool:YES], QTMovieEditableAttribute,
                    nil];

QTMovie *tst = [QTMovie movieWithAttributes:at error:&error];

if (error) {
    NSLog(@"%@", [error localizedDescription]); // outputs (null)
}


// --- initializes the images ---
NSImage *i1 = [[NSImage alloc] 
               initWithContentsOfFile:@"~/agimgs/1.tiff"];
NSImage *i2 = [[NSImage alloc] 
               initWithContentsOfFile:@"~/agimgs/110.tiff"];
NSImage *i3 = [[NSImage alloc] 
               initWithContentsOfFile:@"~/agimgs/130.tiff"];

// --- adds the images ---
for (int j=0; j<50; j++) {
    [tst addImage:i1 forDuration:frameInterval withAttributes:dict];
    [tst addImage:i2 forDuration:frameInterval withAttributes:dict];
    [tst addImage:i3 forDuration:frameInterval withAttributes:dict];
}

// --- (supposed to) output the movie ---
dict = [NSDictionary dictionaryWithObjectsAndKeys:
        [NSNumber numberWithBool:YES], QTMovieExport,
        nil];

BOOL worked = [tst writeToFile:@"/Users/nathanmswan/aaaa.mov" withAttributes:dict error:&error];
if (!worked) {
    NSLog(@"%@", [error localizedDescription]); // outputs nothing
}

NSLog(@"done with aaaa.mov");

1 个答案:

答案 0 :(得分:1)

您可以将影片直接写入这样的文件

NSString *tempName =  [NSString stringWithFormat:@"/Users/nathanmswan/aaaa.mov"];
tst = [[QTMovie alloc] initToWritableFile:tempName error:NULL];
添加框架后

[tst updateMovieFile];

这将创建文件,然后将所有内容写入文件,然后保存。 writeToFile:没有必要。但是,addImage:方法中使用的'dict'似乎在使用前没有初始化...它应该引用addImage的编解码器:例如,

dict = [NSDictionary dictionaryWithObjectsAndKeys:@"mp4v",
           QTAddImageCodecType,
           [NSNumber numberWithLong:codecHighQuality],
           QTAddImageCodecQuality,
           nil];
相关问题