self.videoOutput = AVCaptureVideoDataOutput()
self.videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as AnyHashable : kCVPixelFormatType_32BGRA]
引发
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureVideoDataOutput setVideoSettings:] Unsupported pixel format type - use -availableVideoCVPixelFormatTypes'
好的,所以我想检查可用的像素格式类型。
(lldb) po self.videoOutput.availableVideoCVPixelFormatTypes
▿ Optional<Array<Any>>
▿ some : 3 elements
- 0 : 875704438
- 1 : 875704422
- 2 : 1111970369
这没什么用。幸运的是,在this answer中,有一个类别可以打印出NSNumbers中的pixelFormat名称。
(lldb) po (self.videoOutput.availableVideoCVPixelFormatTypes[2] as! NSNumber).descriptivePixelFormat()
Optional<String>
- some : "kCVPixelFormatType_32BGRA"
self.videoOutput.videoSettings = [ kCVPixelBufferPixelFormatTypeKey as AnyHashable : self.videoOutput.availableVideoCVPixelFormatTypes.first!]
和
self.videoOutput.videoSettings = [ kCVPixelBufferPixelFormatTypeKey as AnyHashable : self.videoOutput.availableVideoCVPixelFormatTypes.last!]
并且都抛出了同样的例外。
我没有第二台设备可以测试atm。但我记得一年前在iOS9和其他设备上使用相同的代码。
iOS 10,XCode 8,iPhone SE
答案 0 :(得分:0)
@property (nonatomic,strong) AVCaptureVideoDataOutput *avCaptureVideoDataOutput;
BOOL supportsFullYUVRange = NO;
BOOL supportsY420 = NO;
_avCaptureVideoDataOutput = [[AVCaptureVideoDataOutput alloc] init];
NSArray *supportedPixelFormats = _avCaptureVideoDataOutput.availableVideoCVPixelFormatTypes;
for (NSNumber *currentPixelFormat in supportedPixelFormats){
if ([currentPixelFormat intValue] == kCVPixelFormatType_420YpCbCr8Planar)
{
supportsY420 = YES;
}
}
NSLog(@"Support Y420 is %d",supportsY420);
for (NSNumber *currentPixelFormat in supportedPixelFormats){
if ([currentPixelFormat intValue] == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange)
{
supportsFullYUVRange = YES;
}
}
NSLog(@“支持420f是%d”,supportsFullYUVRange);
我遇到了同样的问题,我使用iPhone SE和iPhone 7在xcode 8.2中运行iOS 10.2运行结果。
Support Y420 is 0
Support 420f is 1
所以...似乎Y420在iOS 10中不再可用了...你应该使用420f而不是......它的工作原理...... kCVPixelFormatType_32BGRA也能正常工作。
if (supportsFullYUVRange){
[_avCaptureVideoDataOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange] forKey:(id)kCVPixelBufferPixelFormatTypeKey]];
}else{
[_avCaptureVideoDataOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange] forKey:(id)kCVPixelBufferPixelFormatTypeKey]];
}