2011-06-20 2 views
8

私は、AVAssetWriterInputPixelBufferAdaptor内でpixelBufferPoolを使用して、appendメソッドで使用するピクセルバッファを作成しています。 4つのバッファを作成した後、pixelBufferPoolプロパティはNULLになります。AVAssetWriterInputPixelBufferAdaptor pixelBufferPoolがしばらくしてNULLになる

Iセットアップこのような私の作家、入力およびアダプタ:

- (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; 
} 

、私はこれでピクセルバッファを配る:私はappendPixelBuffer私にピクセルバッファを渡す終わりだとき

- (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; 
} 

CVPixelBufferReleaseでピクセルバッファを解放します。これが終わる前の時点では、markAsFinished、endSessionAtSourceTimeまたはfinishWritingを呼び出しません。さらに、アダプター自体はNULLになりません。

ほとんどの記事私はプールが初めから間違って設定されているために不足していると話しましたが、私のところは間に合っていますが、短時間しかありません。誰もこの行動を見た?

+0

これをこれまでに追跡できましたか?今、同じ問題がある。 – RSully

+0

内部エラーが発生しました。それは私がそれが何であったか覚えていないので、今はずっとそうだった。ありがとう。 – davidbitton

+0

私のハックな解決策は、追加する前に読んだ最初のピクセルバッファを再エンコードすることです。これはアダプタ/プールの内部問題を修正するようです。私はそれが好きではないので、まだ他の方法を試してみてください。 – RSully

答えて

3

ピクセルバッファアダプタエラーの場合に発生することがあります。ピクセルバッファアダプタは、順不同にプッシュされたフレームまたは同じプレゼンテーション時間でエラー状態になる可能性があります。

+0

ありがとうございます。これはまさに私の誤りです。私のコードベースの私のリファクタリングでは、私はもはやプレゼンテーション時間のために更新されていない変数を参照していたので、アダプタはピクセルバッファプールのためにnilを返しました。 – Shiun

4

私は同じ問題を抱えていました。私が考え出したように、これは、CMTimeのいくつかがappendPixelBuffer:withPresentationTime:に入れば、等しくなります。例えば、CMTimeMakeWithSecondsをあまりに粗いタイムスケールで使用すると、これが起こります。

関連する問題