2016-10-29 6 views
1

self.videoOutput = AVCaptureVideoDataOutput() self.videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as AnyHashable : kCVPixelFormatType_32BGRA]AVCaptureVideoDataOutput setVideoSettings: Nicht unterstützte Pixelformattyp in iOS10

wirft

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureVideoDataOutput setVideoSettings:] Unsupported pixel format type - use -availableVideoCVPixelFormatTypes'

Okay, so dass ich dachte die verfügbaren Pixelformattypen zu überprüfen.

(lldb) po self.videoOutput.availableVideoCVPixelFormatTypes ▿ Optional<Array<Any>> ▿ some : 3 elements - 0 : 875704438 - 1 : 875704422 - 2 : 1111970369

Das ist nicht viel geholfen hat. Glücklicherweise gibt es in this answer eine Kategorie, die die PixelFormat-Namen aus NSNumbers ausgibt.

(lldb) po (self.videoOutput.availableVideoCVPixelFormatTypes[2] as! NSNumber).descriptivePixelFormat() Optional<String> - some : "kCVPixelFormatType_32BGRA"

Hmm, also denke ich, 32BGRA schließlich unterstützt wird? Also habe ich versucht, Werte direkt aus dem Array der verfügbaren Formattypen bekommen:

self.videoOutput.videoSettings = [ kCVPixelBufferPixelFormatTypeKey as AnyHashable : self.videoOutput.availableVideoCVPixelFormatTypes.first!]

und

self.videoOutput.videoSettings = [ kCVPixelBufferPixelFormatTypeKey as AnyHashable : self.videoOutput.availableVideoCVPixelFormatTypes.last!]

und beide warfen die gleiche Ausnahme.

Ich habe kein zweites Gerät auf ATM zu testen. aber ich erinnere mich, dass ich vor einem Jahr denselben Code auf iOS9 und einem anderen Gerät verwendet habe.

IOS 10, XCode 8, iPhone SE

Antwort

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 (@ "Support 420f ist% d", supportsFullYUVRange);

traf ich das gleiche Problem, und ich bekomme das Ergebnis iOS 10.2 in Xcode 8.2 mit meinem iPhone SE und iPhone 7.

Support Y420 is 0 
Support 420f is 1 

So ... es scheint, dass Y420 ist nicht mehr verfügbar in iOS läuft 10 ... Sie sollten stattdessen 420f verwenden ... und es funktioniert ... kCVPixelFormatType_32BGRA funktioniert auch gut.

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]]; 

} 
Verwandte Themen