8

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!

idmean
  • 14,540
  • 9
  • 54
  • 83
Igor Bidiniuc
  • 1,540
  • 1
  • 16
  • 27
  • Have a look at my answer you will get the clue. http://stackoverflow.com/questions/13523535/avassetwriterinputpixelbufferadaptor-appendpixelbuffer/13523676#comment18517260_13523676 – Harshal Chaudhari Dec 25 '12 at 10:42

0 Answers0