Sto lavorando con AVCaptureVideoDataOutput
e voglio convertire CMSampleBufferRef
in UIImage
. Molte risposte sono le stesse, come questo UIImage created from CMSampleBufferRef not displayed in UIImageView? e AVCaptureSession with multiple previewsConverti CMSampleBufferRef in UIImmagine con lo spazio colore YUV?
Funziona bene se ho impostato lo spazio colore VideoDataOutput a BGRA (accreditati a questa risposta CGBitmapContextCreateImage error)
NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
[dataOutput setVideoSettings:videoSettings];
Senza i videoSettings di cui sopra, io ricevo il seguenti errori
CGBitmapContextCreate: invalid data bytes/row: should be at least 2560 for 8 integer bits/component, 3 components, kCGImageAlphaPremultipliedFirst.
<Error>: CGBitmapContextCreateImage: invalid context 0x0
Lavorare con BGRA non è una buona scelta, poiché non v'è in testa conversione da YUV (spazio colore AVCaptureSession impostazione predefinita) per BGRA, come affermato da Brad e Codo i n How to get the Y component from CMSampleBuffer resulted from the AVCaptureSession?
Quindi c'è un modo per convertire CMSampleBufferRef
in UIImage
e lavorare con lo spazio colore YUV?
Qualsiasi soluzione per questo? –
@AdarshVC perché non voti la domanda per renderla più evidente? – onmyway133
spunta questa domanda http://stackoverflow.com/questions/3305862/uiimage-created-from-cmsamplebufferref-not-displayed-in-uiimageview –