2013-03-28 10 views
2

CMSampleBufferRef의 특정 크기로 이미지 자르기를 시도하고 있습니다. SampleBufferPixelBuffer 부착 PixelBuffer 5. 다시 CIImage 렌더링 CIImage 4. 자르기 CIImage 3. PixelBuffer 변환 SampleBuffer 2에서 1. PixelBuffer하기 - 나는 5 단계를 만들고있다. 지금까지는 4 단계에서 문제가 발생했습니다 - PixelBuffer (이 시점을 넘어서 확인할 수 없음)으로 렌더링되는 이미지는 버퍼에 렌더링되지 않습니다 (동일한 CIImage imageWithCVPixelBuffer을 사용하여 검사하고 리턴으로 NULL을 얻음). 팁이나 도움을 크게 주시면 감사하겠습니다.자르기 CMSampleBufferRef

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); 
+0

당신이 문제가 무엇 :

다음
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에 인수로이 사전을 통과해야 : 사람이이 문제에 실수를 한단다 경우 여기 코드는 데? 여기에 질문이 없습니다. – Aurelius

+0

ciContext가 버퍼에 아무 것도 렌더링하지 않습니다. 동일한 ciimage imageWithCVPixelBuffer로 확인하고 NULL을 가져옵니다. – Laz

+0

안녕하세요. 나는 또한 너와 같은 곳에 붙어있다. AVFoundation을 사용하여 비디오를 캡처 중입니다. Avcapture 대리자 "didOutputSampleBuffer"에서 확대/축소를 구현해야합니다. CMSampleBufferRef/CVImageBufferRef를 스케일하고 자르는 방법을 알려주십시오. –

답변