I'm writing some frames to video with AVAssetWriterInputPixelBufferAdaptor, and when I write a lot of frames my app crashes because of memory allocation. How can I prevent that? Here is the code:
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);
}
When using Xcode Instruments, the leak seems to occur in
if(![adaptor appendPixelBuffer:buffer withPresentationTime:presentTime])
(the AVAssetWriterInputPixelBufferAdaptor )
Could really use some assistance or a pointer to a working example. Thanks!