次のように CVPixelBuffer バッファを作成して使用します。
//Create buffer
CVPixelBufferRef conversionBuffer = nil;
if (indx < [self.sideImageList count] - 1)
{
UIImageView *tempImageView = [self.sideImageList objectAtIndex:indx + 1];
CGRect originalBackgroundFrame = [tempImageView frame];
UIView *tempView = [tempImageView.subviews objectAtIndex:0];
[tempView removeFromSuperview];
tempImageView.layer.borderColor = [UIColor clearColor].CGColor;
[tempImageView setFrame:CGRectMake(0, 0, kVideoWidth, kVideoHeight)];
UIImage *backgroundImage = [UIImage imageFromView:tempImageView];
[tempImageView addSubview:tempView];
tempImageView.layer.borderColor = [UIColor yellowColor].CGColor;
[tempImageView setFrame:originalBackgroundFrame];
UIImage *resizedBackground = [ICVideoViewController imageWithImage:backgroundImage
scaledToSize:CGSizeMake(kVideoWidth, kVideoHeight)];
UIImage *appendedImage = [ICVideoViewController appendImage:resizedBackground
to:conversionImage
atPoint:CGPointMake((kVideoWidth - conversionImage.size.width)/2,
(kVideoHeight - conversionImage.size.height)/2)
otherPoint:CGPointZero];
//Fill Buffer
conversionBuffer = [ICVideoViewController pixelBufferFromCGImage:[appendedImage CGImage] size:CGSizeMake(kVideoWidth, kVideoHeight)];
}
else
{
//Fill buffer
conversionBuffer = [ICVideoViewController pixelBufferFromCGImage:[conversionImage CGImage] size:CGSizeMake(kVideoWidth, kVideoHeight)];
}
while (adaptor.assetWriterInput.readyForMoreMediaData==NO)
{
[NSThread sleepForTimeInterval:0.1];
}
if (indx == [self.sideImageList count] - 1)
{
break;
}
[adaptor appendPixelBuffer:conversionBuffer withPresentationTime:CMTimeMake((frameRate*i)+frames-1, frameRate)];
while (adaptor.assetWriterInput.readyForMoreMediaData==NO)
{}
//release buffer
CVPixelBufferRelease(conversionBuffer);
バッファを設定するために使用するメソッドは..どこかからこのメソッドを取得しましたが、何か問題があるようには見えません..
+ (CVPixelBufferRef) pixelBufferFromCGImage:(CGImageRef)image size:(CGSize)size
{
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], kCVPixelBufferCGImageCompatibilityKey,
[NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey,
nil];
CVPixelBufferRef pxbuffer = NULL;
CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, size.width,
size.height, kCVPixelFormatType_32ARGB, (CFDictionaryRef) options,
&pxbuffer);
NSParameterAssert(status == kCVReturnSuccess && pxbuffer != NULL);
CVPixelBufferLockBaseAddress(pxbuffer, 0);
void *pxdata = CVPixelBufferGetBaseAddress(pxbuffer);
NSParameterAssert(pxdata != NULL);
CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(pxdata, size.width,
size.height, 8, 4*size.width, rgbColorSpace,
kCGImageAlphaNoneSkipFirst);
NSParameterAssert(context);
CGContextDrawImage(context, CGRectMake(0, 0, CGImageGetWidth(image),
CGImageGetHeight(image)), image);
CGColorSpaceRelease(rgbColorSpace);
CGContextRelease(context);
CVPixelBufferUnlockBaseAddress(pxbuffer, 0);
return pxbuffer;
}
このメソッドでリークが発生しているようです(礼儀のリークツール)が、何が間違っているのかまだわかりません。