ios – AVAssetWriterInputPixelBufferAdaptor pixelBufferPool在一段时间后变为NULL

我在AVAssetWriterInputPixelBufferAdaptor中使用pixelBufferPool来创建像素缓冲区以与append方法一起使用.创建4个缓冲区后,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释放像素缓冲区.在此之前的任何时候,我都不会调用markAsFinished,endSessionAtSourceTime或finishWriting.此外,适配器本身不会为NULL.

我读过的大多数帖子都谈到了由于配置错误配置而导致池从一开始就缺席,但是我的存在,但只是很短的时间.其他人看到过这种行为?

解决方法

在像素缓冲适配器错误的情况下可能会发生这种情况.像素缓冲适配器可能会因错误推出的帧或具有相同的显示时间而进入错误状态.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...