自从Snow Leopard以来,QTKit现在从像QTMovies frameImageAtTime:withAttributes:error:这样的函数返回经过颜色校正的图像数据。对于未压缩的AVI文件,在Snow Leopard与Leopard中显示相同的图像数据具有更大的像素值。
目前我正在使用frameImageAtTime获取NSImage,然后请求该图像的tiffRepresentation。在执行此操作后,在Snow Leopard中像素值略高。
例如,在Leopard中具有以下像素值的文件:
目前我正在使用frameImageAtTime获取NSImage,然后请求该图像的tiffRepresentation。在执行此操作后,在Snow Leopard中像素值略高。
例如,在Leopard中具有以下像素值的文件:
[0 180 0]
现在的像素值如下:
[0 192 0]
有没有办法向QTMovie请求未进行颜色校正的视频帧?我应该请求CGImageRef、CIImage或CVPixelBufferRef吗?在读取视频文件之前是否有一种完全禁用颜色校正的方法?
我尝试通过使用NSCalibratedColroSpace绘制到NSBitmapImageRep中来解决此问题,但这只是部分解决:
// Create a movie
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys :
nsFileName, QTMovieFileNameAttribute,
[NSNumber numberWithBool:NO], QTMovieOpenAsyncOKAttribute,
[NSNumber numberWithBool:NO], QTMovieLoopsAttribute,
[NSNumber numberWithBool:NO], QTMovieLoopsBackAndForthAttribute,
(id)nil];
_theMovie = [[QTMovie alloc] initWithAttributes:dict error:&error];
// ....
NSMutableDictionary *imageAttributes = [NSMutableDictionary dictionary];
[imageAttributes setObject:QTMovieFrameImageTypeNSImage forKey:QTMovieFrameImageType];
[imageAttributes setObject:[NSArray arrayWithObject:@"NSBitmapImageRep"] forKey: QTMovieFrameImageRepresentationsType];
[imageAttributes setObject:[NSNumber numberWithBool:YES] forKey:QTMovieFrameImageHighQuality];
NSError* err = nil;
NSImage* image = (NSImage*)[_theMovie frameImageAtTime:frameTime withAttributes:imageAttributes error:&err];
// copy NSImage into an NSBitmapImageRep (Objective-C)
NSBitmapImageRep* bitmap = [[image representations] objectAtIndex:0];
// Draw into a colorspace we know about
NSBitmapImageRep *bitmapWhoseFormatIKnow = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:getWidth()
pixelsHigh:getHeight()
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bitmapFormat:0
bytesPerRow:(getWidth() * 4)
bitsPerPixel:32];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:bitmapWhoseFormatIKnow]];
[bitmap draw];
[NSGraphicsContext restoreGraphicsState];
这确实将转换回一个“非校色”颜色空间,但颜色值并不完全与我们测试的未压缩AVI文件中存储的内容相同。此外,由于它是从RGB ->“设备RGB” -> RGB进行转换,因此效率要低得多。
另外,我正在64位应用程序中工作,因此不考虑使用Quicktime-C API。
感谢您的帮助。