gpt4 book ai didi

ios - iPhone 3GS 和 kCVPixelFormatType_420YpCbCr8BiPlanarFullRange 格式?

转载 作者:行者123 更新时间:2023-11-28 19:11:14 25 4
gpt4 key购买 nike

我正在使用最新的 SDK 开发一个 iOS 应用程序并在 iPhone 3GS 上测试它。

我在 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 总是 nil。

在这里:

- (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 行上添加了一个断点,这些是我的 vars 值:

enter image description here

但我在这里得到一个 EXEC_BAD_ACCESS:memcpy(baseAddress, _lastFrame, _previewSurfaceHeight * _previewSurfaceWidth * _bytesPerPixel);

iPhone 3GS 是否支持 kCVPixelFormatType_420YpCbCr8BiPlanarFullRange?

最佳答案

不,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;
}
}

关于ios - iPhone 3GS 和 kCVPixelFormatType_420YpCbCr8BiPlanarFullRange 格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15291064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com