AVAssetWriterInputPixelBufferAdaptor内存管理

时间:2011-12-23 16:13:25

标签: ios memory-management avfoundation avassetwriter core-video

我正在用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)

真的可以使用一些帮助或指向工作示例的指针。谢谢!

0 个答案:

没有答案