2013-03-08 64 views
0

我正在開發具有最新SDK的iOS應用程序並在iPhone 3GS上進行測試。iPhone 3GS和kCVPixelFormatType_420YpCbCr8BiPlanarFullRange格式?

我在init()方法這樣做:

CFDictionaryRef formatDictionary = CVPixelFormatDescriptionCreateWithPixelFormatType(kCFAllocatorDefault, kCVPixelFormatType_420YpCbCr8BiPlanarFullRange); 
CFNumberRef val = (CFNumberRef) CFDictionaryGetValue(formatDictionary, kCVPixelFormatBitsPerBlock); 
if (val != nil) 
{ 
    CFNumberGetValue(val,kCFNumberSInt8Type, &_bytesPerPixel); 
    _bytesPerPixel /= 8; 
} 
else 
    _bytesPerPixel = 4; 

但VAL始終是零。

在這裏:

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
     fromConnection:(AVCaptureConnection *)connection 
{ 
    CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); 

    //Lock the image buffer// 
    CVPixelBufferLockBaseAddress(imageBuffer,0); 
    //Get information about the image// 
    uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer); 

    size_t width = CVPixelBufferGetWidth(imageBuffer); 
    size_t height = CVPixelBufferGetHeight(imageBuffer); 
    //size_t stride = CVPixelBufferGetBytesPerRow(imageBuffer); 

    //put buffer in open cv, no memory copied 
    cv::Mat image = cv::Mat(height, width, CV_8UC4, baseAddress); 

    // copy the image 
    //cv::Mat copied_image = image.clone(); 
    [_previewBufferLock lock]; 

    memcpy(baseAddress, _lastFrame, _previewSurfaceHeight * _previewSurfaceWidth * _bytesPerPixel); 

    [_previewBufferLock unlock]; 

    //We unlock the image buffer// 
    CVPixelBufferUnlockBaseAddress(imageBuffer,0); 
} 

我對memcpy的行添加一個斷點,我這些都是我瓦爾值:

enter image description here

但是我在這裏得到一個EXEC_BAD_ACCESS:memcpy(baseAddress, _lastFrame, _previewSurfaceHeight * _previewSurfaceWidth * _bytesPerPixel);

iPhone 3GS是否支持kCVPixelFormatType_420YpCbCr8BiPlanarFullRange?

回答

4

不,iPhone 3GS不支持kCVPixelFormatType_420YpCbCr8BiPlanarFullRange作爲攝像機的輸出緩衝類型,只有kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange。 iPhone 4S和iPhone 5支持全範圍YUV輸出,但較舊的設備不支持。

您可以用下面的代碼測試此可用性:

videoOutput = [[AVCaptureVideoDataOutput alloc] init]; 

BOOL supportsFullYUVRange = NO; 
NSArray *supportedPixelFormats = videoOutput.availableVideoCVPixelFormatTypes; 
for (NSNumber *currentPixelFormat in supportedPixelFormats) 
{ 
    if ([currentPixelFormat intValue] == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) 
    { 
     supportsFullYUVRange = YES; 
    } 
}