QTMovie не пишет в файл - PullRequest
       9

QTMovie не пишет в файл

0 голосов
/ 20 января 2012

Я пытаюсь добавить эти изображения в 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 Ответ

1 голос
/ 13 апреля 2012

Вы можете записать фильм непосредственно в файл, подобный этому

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

после добавления кадра

[tst updateMovieFile];

Это создаст файл, а затем запишет все в файл,затем сохраните его.WriteToFile: не будет необходимости.Однако «dict», используемый в методе addImage:, похоже, не инициализируется перед использованием ... он должен ссылаться на кодек для addImage: например,

dict = [NSDictionary dictionaryWithObjectsAndKeys:@"mp4v",
           QTAddImageCodecType,
           [NSNumber numberWithLong:codecHighQuality],
           QTAddImageCodecQuality,
           nil];
...