我正在使用AVAssetWriterInputPixelBufferAdaptor中的pixelBufferPool創建像素緩衝區以便與append方法一起使用。創建4個緩衝區後,pixelBufferPool屬性變爲NULL;AVAssetWriterInputPixelBufferAdaptor pixelBufferPool在一段時間後變爲NULL
設置我的作家,輸入和適配器這樣的:
- (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;
}
,我伸手這個像素緩衝區:
- (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;
}
當我做像素緩衝區傳遞給appendPixelBuffer我用CVPixelBufferRelease釋放像素緩衝區。在這之前沒有任何一個NULL,我可以調用markAsFinished,endSessionAtSourceTime或finishWriting。此外,適配器本身不會變爲NULL。
我讀過的大多數帖子都談到由於配置錯誤的適配器而導致游泳池缺席,但是我的遊戲在那裏,但只有很短的時間。其他人看過這種行爲?
你是否曾經能夠跟蹤這個?現在有同樣的問題。 – RSully
有一個內部錯誤。現在已經很長時間了,我不記得那是什麼。謝謝。 – davidbitton
我的hacky解決方案是在追加它之前對我讀取的第一個像素緩衝區進行重新編碼,這似乎解決了適配器/池所具有的內部問題。嘗試其他方法仍然是因爲我不喜歡那樣。 – RSully