5

CMSampleBufferRef画像を特定のサイズにトリミングしようとしています。私は5つのステップを作っています - 1. 2から取得PixelBuffer. 3にSampleBuffer変換. これまでのところ、ステップ4で問題が発生しています-画像をレンダリングして戻します(この時点を超えてチェックできません)バッファには何もレンダリングされません(同じものを使用してチェックし、戻り値としてNULLを取得します)。ヒントや助けをいただければ幸いです。PixelBufferCIImageCIImageCIImagePixelBufferPixelBufferSampleBufferPixelBufferCIImage imageWithCVPixelBuffer

CGRect cropRect = CGRectMake(0, 0, 640, 480);

CIImage *ciImage = [CIImage imageWithCVPixelBuffer:(CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer)]; //options: [NSDictionary dictionaryWithObjectsAndKeys:[NSNull null], kCIImageColorSpace, nil]];
ciImage = [ciImage imageByCroppingToRect:cropRect];    

CVPixelBufferRef pixelBuffer;
CVPixelBufferCreate(kCFAllocatorSystemDefault, 640, 480, kCVPixelFormatType_32BGRA, NULL, &pixelBuffer);

CVPixelBufferLockBaseAddress( pixelBuffer, 0 );

CIContext * ciContext = [CIContext contextWithOptions: nil];
[ciContext render:ciImage toCVPixelBuffer:pixelBuffer];
CVPixelBufferUnlockBaseAddress( pixelBuffer, 0 );

CMSampleTimingInfo sampleTime = {
    .duration = CMSampleBufferGetDuration(sampleBuffer),
    .presentationTimeStamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer),
    .decodeTimeStamp = CMSampleBufferGetDecodeTimeStamp(sampleBuffer)
};

CMVideoFormatDescriptionRef videoInfo = NULL;
CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, &videoInfo);

CMSampleBufferRef oBuf;
CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, true, NULL, NULL, videoInfo, &sampleTime, &oBuf);
4

1 に答える 1

5

それで、私が問題を抱えている理由を見つけました。どうやら、辞書を作成して初期化子に渡すことにより、ピクセルバッファを初期化するときに kCVPixelBufferIOSurfacePropertiesKey キーを追加する必要があります。誰かがこの問題に遭遇した場合のコードは次のとおりです。

CFDictionaryRef empty; // empty value for attr value.
CFMutableDictionaryRef attrs;
empty = CFDictionaryCreate(kCFAllocatorDefault, // our empty IOSurface properties dictionary
                           NULL,
                           NULL,
                           0,
                           &kCFTypeDictionaryKeyCallBacks,
                           &kCFTypeDictionaryValueCallBacks);
attrs = CFDictionaryCreateMutable(kCFAllocatorDefault,
                                  1,
                                  &kCFTypeDictionaryKeyCallBacks,
                                  &kCFTypeDictionaryValueCallBacks);

CFDictionarySetValue(attrs,
                     kCVPixelBufferIOSurfacePropertiesKey,
                     empty);

次に、この辞書を引数として CVPixelBufferCreate に渡すだけです。

ここでこのソリューションを見つけました:http://allmybrain.com/2011/12/08/rendering-to-a-texture-with-ios-5-texture-cache-api/

于 2013-03-29T22:35:32.883 に答える