【发布时间】:2015-11-08 03:53:31
【问题描述】:
我正在尝试将包含从每像素 16 位 TIFF 文件加载的数据的 CGImage 写入 ProRes 44444 QuickTime 文件,同时保持位深度。
我正在像这样加载数据:
NSImage* image = [[NSImage alloc] initWithContentsOfFile:@"/whatever/test.tif"];
CGImageRef temp = [image CGImageForProposedRect:nil context:nil hints:nil];
我有一个 AVAssetWriterInputPixelBufferAdaptor 设置如下:
NSDictionary *sourcePixelBufferAttributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kCVPixelFormatType_64ARGB], kCVPixelBufferPixelFormatTypeKey,
[NSNumber numberWithBool:YES], kCVPixelBufferCGImageCompatibilityKey,
[NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey,
nil];
AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput
sourcePixelBufferAttributes:sourcePixelBufferAttributesDictionary];
然后我将图像写入 CVPixelBuffer:
CVPixelBufferRef pxbuffer = NULL;
CVReturn status = CVPixelBufferPoolCreatePixelBuffer(NULL, adaptor.pixelBufferPool, &pxbuffer);
CVPixelBufferLockBaseAddress(pxbuffer, 0);
void *pxdata = CVPixelBufferGetBaseAddress(pxbuffer);
CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = (CGBitmapInfo) kCGImageAlphaPremultipliedLast;
CGContextRef context = CGBitmapContextCreate(pxdata, size.width, size.height, 16, 8*size.width, rgbColorSpace, bitmapInfo);
CGContextDrawImage(context, CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image)), image);
CGColorSpaceRelease(rgbColorSpace);
CGContextRelease(context);
CVPixelBufferUnlockBaseAddress(pxbuffer, 0);
然后将其附加到电影中:
[adaptor appendPixelBuffer:pxbuffer withPresentationTime:CMTimeMake(frame, 24)]
这对 8 位/像素图像(适当调整了值)非常有效,但是对于 16 位/像素图像,我在生成的 QuickTime 电影中得到了奇怪的颜色。看起来有些频道可能会被交换,但各种交换它们的尝试都没有产生有用的结果。有没有人有将大于 8 位/像素的图像数据写入 QuickTime 电影的工作示例?
【问题讨论】:
标签: macos cocoa core-graphics avfoundation