I am writing multiple frames for a video using AVAssetWriterInputPixelBufferAdaptor, and when I write a lot of frames, my application crashes due to memory allocation. How can I prevent this? 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, a leak appears in
if(![adaptor appendPixelBuffer:buffer withPresentationTime:presentTime])
(AVAssetWriterInputPixelBufferAdaptor)
May really use some help or a pointer to a working example. Thank!
source
share