在Cocoa應用程序目前我編碼,我發現了從石英作曲家渲染快照映像(NSImage中的對象),我想它們編碼的QTMovie在720 * 480尺寸,25 fps的,和H264使用的編解碼器addImage:方法。下面是相應的代碼:爲什麼我的基於QTKit的圖像編碼應用如此之慢?
qRenderer = [[QCRenderer alloc] initOffScreenWithSize:NSMakeSize(720,480) colorSpace:CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB) composition:[QCComposition compositionWithFile:qcPatchPath]]; // define an "offscreen" Quartz composition renderer with the right image size
imageAttrs = [NSDictionary dictionaryWithObjectsAndKeys: @"avc1", // use the H264 codec
QTAddImageCodecType, nil];
qtMovie = [[QTMovie alloc] initToWritableFile: outputVideoFile error:NULL]; // initialize the output QT movie object
long fps = 25;
frameNum = 0;
NSTimeInterval renderingTime = 0;
NSTimeInterval frameInc = (1./fps);
NSTimeInterval myMovieDuration = 70;
NSImage * myImage;
while (renderingTime <= myMovieDuration){
if(![qRenderer renderAtTime: renderingTime arguments:NULL])
NSLog(@"Rendering failed at time %.3fs", renderingTime);
myImage = [qRenderer snapshotImage];
[qtMovie addImage:myImage forDuration: QTMakeTimeWithTimeInterval(frameInc) withAttributes:imageAttrs];
[myImage release];
frameNum ++;
renderingTime = frameNum * frameInc;
}
[qtMovie updateMovieFile];
[qRenderer release];
[qtMovie release];
它的工作原理,但我的應用程序是無法做到的,在現實的時間在我的新的MacBook Pro,而我知道的QuickTime廣播公司可以在H264實時編碼圖像在同一臺計算機上使用的質量甚至更高。
那麼爲什麼?這裏有什麼問題?這是一個硬件管理問題(多核線程,GPU,...)還是我錯過了一些東西?讓我作序,我是新的(2周的實踐)在蘋果發展的世界裏,無論是在目標C,可可,X-代碼,QuickTime和石英作曲家圖書館等
感謝您的幫助
您確定要使用25fps的720x480嗎?難道不應該是要麼在720×480或29.97,在720×576 25fps的?我懷疑它會解決你的速度問題,但它看起來像一個奇怪的格式。 – user1118321 2012-01-05 01:06:26