English 中文(简体)
QTMovie,29.97 with QTMaketime
原标题:QTMovie at 29.97 with QTMakeTime

我试图利用QTKit将图像清单转换成一个快速电影。 我详细描述了除达到29.97年标准外,如何做一切工作。 通过其他论坛和资源,trick似乎正在使用类似的东西:

QTTime frameDuration = QTMakeTime(1001, 30000)

然而,我使用这种方法的所有尝试,甚至(1,000,29970人)仍在30处制作一部电影。 这一缺陷是在与快速参与者玩.时出现的。

Any ideas? Is there some other way to set the frame rate for the entire movie once its created?

Here s some sample code:

NSDictionary *outputMovieAttribs = [NSDictionary dictionaryWithObjectsAndKeys:@"jpeg", QTAddImageCodecType, [NSNumber numberWithLong:codecHighQuality], QTAddImageCodecQuality, nil];
QTTime frameDuration = QTMakeTime(1001, 30000);
QTMovie *outputMovie = [[QTMovie alloc] initToWritableFile:@"/tmp/testing.mov" error:nil];
[outputMovie setAttribute:[NSNumber numberWithBool:YES] forKey:QTMovieEditableAttribute];
[outputMovie setAttribute:[NSNumber numberWithLong:30000] forKey:QTMovieTimeScaleAttribute];

if (!outputMovie) {
    printf("ERROR: Chunk: Could not create movie object:
");
} else {
    int frameID = 0;
    while (frameID < [framePaths count]) {
        NSAutoreleasePool *readPool = [[NSAutoreleasePool alloc] init];
        NSData *currFrameData = [NSData dataWithContentsOfFile:[framePaths objectAtIndex:frameID]];
        NSImage *currFrame = [[NSImage alloc] initWithData:currFrameData];

        if (currFrame) {
            [outputMovie addImage:currFrame forDuration:frameDuration withAttributes:outputMovieAttribs];
            [outputMovie updateMovieFile];
            NSString *newDuration = QTStringFromTime([outputMovie duration]);
            printf("new Duration: %s
", [newDuration UTF8String]);
            currFrame = nil;
        } else {
            printf("ERROR: Could not add image to movie");
        }
        frameID++;
        [readPool drain];
    }
}

NSString *outputDuration = QTStringFromTime([outputMovie duration]);
printf("output Duration: %s
", [outputDuration UTF8String]);
最佳回答

Ok, thanks to your code, I could solve the issue. I was using the development tool called Atom Inpector to see that the data structure looked totally different than the movies I am currently working with. As I said, I never created a movie from images as you do, but it seems that this is not the way to go if you want to have a movie afterwards. QuickTime recognizes the clip as "Photo-JPEG", so not a normal movie file. The reason for this seems to be, that the added pictures are NOT added to a movie track but just somewhere in the movie. This can also be seen with Atom Inspector. With the "movieTimeScaleAttribute", you set a timeScale that is not used!

为了解决这个问题,我只修改了法典。

NSDictionary *outputMovieAttribs = [NSDictionary dictionaryWithObjectsAndKeys:@"jpeg", 
                      QTAddImageCodecType, [NSNumber numberWithLong:codecHighQuality],
                      QTAddImageCodecQuality,[NSNumber numberWithLong:2997], QTTrackTimeScaleAttribute, nil];

QTTime frameDuration = QTMakeTime(100, 2997);
QTMovie *outputMovie = [[QTMovie alloc] initToWritableFile:@"/Users/flo/Desktop/testing.mov" error:nil];
[outputMovie setAttribute:[NSNumber numberWithBool:YES] forKey:QTMovieEditableAttribute];
[outputMovie setAttribute:[NSNumber numberWithLong:2997] forKey:QTMovieTimeScaleAttribute];

Everything else is unaltered. Oh, by the way. To print the timeValue and timeScale, you could also do :

NSLog(@"new Duration timeScale : %ld timeValue : %lld 
", 
       [outputMovie duration].timeScale, [outputMovie duration].timeValue);

这样,如果你的法典符合理想,你就可以更好地看到。

Hope that helps! Best regards

问题回答

I have never done what you re trying to do, but I can tell you how to get the desired framerate I guess. If you "ask" a movie for its current timing information, you always get a QTTime structure, which contains the timeScale and the timeValue. For a 29.97 fps video, you would get a timeScale of 2997 ( for example, see below ). This is the amount of "units" per second.

So, if the playback position of the movie is currently at exactly 2 seconds, you would get a timeValue of 5994. The frameDuration is therefore 100, because 2997 / 100 = 29.97 fps.

QuickTime cannot handle float values, so you have to convert all the values to a long value by multiplication. By the way, you don t have to use 100, you could also use 1000 and a timeScale of 29970, or 200 as frame duration and 5994 timeScale. That s all I can tell you from what you get if you read timing information from already existing clips. You wrote that this didn t work out for you, but this is how QuickTime works internally. You should look into it again!

最佳做法





相关问题
Display MPEG-4 Export Component Dialog

Below is my code for a doc based QTKit app that exports to the fixed Apple device formats by way of a popUp that displays the three device options. The [NSNumberWithLong:mpg4 ] option works fine as ...

Quicktime Framework and opening Transport Streams

I have noticed that Quicktime 10 is now able to open Transport Stream Video files and also search reliably within that video file(Which is something that VLC can not seem to handle). Quicktime 7, on ...

export to MP3 from quicktime API

A question for Apple,QT programmers. Would like to know if it s possible to export a Movie object to MP3 using the QuickTime API. Preferably the ConvertMovieToFile function. I ve looked at ...

热门标签