The iPhone 3GS and kCVPixelFormatType_420YpCbCr8Bi

2019-08-28 02:43发布

I'm developing an iOS application with latest SDK and testing it on an iPhone 3GS.

I'm doing this on init method:

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

But val is always nil.

And here:

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

I have add a breakpoint on memcpy line and I these are my vars values:

enter image description here

But I'm getting an EXEC_BAD_ACCESS here: memcpy(baseAddress, _lastFrame, _previewSurfaceHeight * _previewSurfaceWidth * _bytesPerPixel);

Does the iPhone 3GS support kCVPixelFormatType_420YpCbCr8BiPlanarFullRange?

1条回答
孤傲高冷的网名
2楼-- · 2019-08-28 03:01

No, the iPhone 3GS does not have support for kCVPixelFormatType_420YpCbCr8BiPlanarFullRange as an output buffer type from the camera, only kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange. The iPhone 4S and iPhone 5 have support for the full-range YUV output, but older devices do not.

You can test this availability using the following code:

videoOutput = [[AVCaptureVideoDataOutput alloc] init];

BOOL supportsFullYUVRange = NO;
NSArray *supportedPixelFormats = videoOutput.availableVideoCVPixelFormatTypes;
for (NSNumber *currentPixelFormat in supportedPixelFormats)
{
    if ([currentPixelFormat intValue] == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange)
    {
        supportsFullYUVRange = YES;
    }
}
查看更多
登录 后发表回答