我正在使用 AVAssetWriterInputPixelBufferAdaptor 将一些帧写入视频,当我写入大量帧时,我的应用程序由于内存分配而崩溃。我怎样才能防止这种情况?这是代码:
AVAssetWriterInput *writerInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings];
NSDictionary *sourcePixelBufferAttributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kCVPixelFormatType_32ARGB], kCVPixelBufferPixelFormatTypeKey, nil];
AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor
assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput
sourcePixelBufferAttributes:sourcePixelBufferAttributesDictionary];
CVPixelBufferRef buffer = NULL;
buffer = (CVPixelBufferRef)[self pixelBufferFromCGImage:[tmpImg CGImage] size:size];
if (buffer)
{
if(![adaptor appendPixelBuffer:buffer withPresentationTime:presentTime])
NSLog(@"FAIL");
else
NSLog(@"Success:%d",i);
CFRelease(buffer);
}
使用 Xcode Instruments 时,泄漏似乎发生在
if(![adaptor appendPixelBuffer:buffer withPresentationTime:presentTime])
( AVAssetWriterInputPixelBufferAdaptor )
真的可以使用一些帮助或指向一个工作示例的指针。谢谢!