AVAssetWriterInputPixelBufferAdaptor pixelBufferPool goes through NULL after a while

I am using pixelBufferPool in AVAssetWriterInputPixelBufferAdaptor to create pixel buffers for use with the add method. After creating 4 buffers, the pixelBufferPool property becomes NULL;

I configure my script, input, and adapter as follows:

- (BOOL) setupRecorder { NSError *error = nil; if([[NSFileManager defaultManager] fileExistsAtPath:[[self tempFileURL] path]]) [[NSFileManager defaultManager] removeItemAtURL:[self tempFileURL] error:&error]; assetWriter = [[AVAssetWriter alloc] initWithURL: [self tempFileURL] fileType:AVFileTypeQuickTimeMovie error:&error]; if (error) { NSLog(@"Error creating asset writer: %@", error); [assetWriter release]; return NO; } // writer NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys: AVVideoCodecH264, AVVideoCodecKey, [NSNumber numberWithInt:videoWidth], AVVideoWidthKey, [NSNumber numberWithInt:videoHeight], AVVideoHeightKey, nil]; assetWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings]; NSDictionary *bufferAttributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:kCVPixelFormatType_32BGRA], kCVPixelBufferPixelFormatTypeKey, nil]; adaptor = [[AVAssetWriterInputPixelBufferAdaptor alloc] initWithAssetWriterInput:assetWriterInput sourcePixelBufferAttributes:bufferAttributes]; [adaptor retain]; assetWriterInput.expectsMediaDataInRealTime = YES; [assetWriter addInput:assetWriterInput]; return YES; } 

and I am handing out pixel buffers as follows:

 - (CVPixelBufferRef) createPixelBufferRef { CVPixelBufferPoolRef pixelBufferPool = adaptor.pixelBufferPool; CVPixelBufferRef pixelBuffer = NULL; CVReturn cvReturn = CVPixelBufferPoolCreatePixelBuffer(NULL, pixelBufferPool, &pixelBuffer); if(cvReturn != kCVReturnSuccess) NSLog(@"CVPixelBuffePoolCreatePixelBuffer: %d", cvReturn); bufferCreatedCount++; return pixelBuffer; } 

when I finished passing the pixel buffer to appendPixelBuffer, I release the pixel buffer using CVPixelBufferRelease. In no case, before this happens, NULL I call markAsFinished, endSessionAtSourceTime or finishWriting. In addition, the adapter itself is not NULL.

Most of the messages that I read say that the pool is missing at the beginning due to an incorrectly configured adapter, but mine is there, but only for a short time. Has anyone else seen this behavior?

+8
ios iphone avassetwriter
source share
2 answers

This can happen if the pixel buffer adapter fails. The pixel buffer adapter may fail because frames are out of order or have the same presentation time.

+3
source share

I had the same problem. As I understand it, this happens if some of the CMTime s placed in appendPixelBuffer:withPresentationTime: are equal. This can happen, for example, if you use CMTimeMakeWithSeconds with a too coarse time scale.

+4
source share

All Articles