2011-06-20 75 views
8

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

我讀過的大多數帖子都談到由於配置錯誤的適配器而導致游泳池缺席,但是我的遊戲在那裏,但只有很短的時間。其他人看過這種行爲?

+0

你是否曾經能夠跟蹤這個?現在有同樣的問題。 – RSully

+0

有一個內部錯誤。現在已經很長時間了,我不記得那是什麼。謝謝。 – davidbitton

+0

我的hacky解決方案是在追加它之前對我讀取的第一個像素緩衝區進行重新編碼,這似乎解決了適配器/池所具有的內部問題。嘗試其他方法仍然是因爲我不喜歡那樣。 – RSully

回答

3

它可能發生在像素緩衝適配器錯誤的情況下。像素緩衝器適配器可能會因錯誤排序的幀或相同的演示時間而進入錯誤狀態。

+0

謝謝。這正是我的錯誤。在我的代碼庫重構中,我引用了一個變量,該變量不再爲演示時間進行更新,並導致適配器爲像素緩衝池返回nil。 – Shiun

4

我有同樣的問題。正如我想象的那樣,如果CMTime中的某些值與appendPixelBuffer:withPresentationTime:相等,就會發生這種情況。例如,如果使用CMTimeMakeWithSeconds的時間過長,則可能會發生這種情況。

相關問題