Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"CIImage initWithCVPixelBuffer:options:" failed because its pixel format p422 is not supported in iOS 10

In ios10 , I want to get video capture, but get an error "[CIImage initWithCVPixelBuffer:options:] failed because its pixel format p422 is not supported."

My code is this:

func previewImage(handle: (image: UIImage?) -> Void) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
            dispatch_async(dispatch_get_main_queue(), { () -> Void in
                guard let time = self.player?.currentTime() else {
                    return
                }
                guard let pixelBuffer = self.output?.copyPixelBufferForItemTime(time,
                    itemTimeForDisplay: nil) else {
                        return
                }
                let ciImage = CIImage(CVPixelBuffer: pixelBuffer)
                let temporaryContext = CIContext(options: nil)
                let rect = CGRectMake(
                    0,
                    0,
                    CGFloat(CVPixelBufferGetWidth(pixelBuffer)),
                    CGFloat(CVPixelBufferGetHeight(pixelBuffer))
                )

                let image: UIImage?
                if let videoImage = temporaryContext.createCGImage(ciImage, fromRect: rect) {
                    image = UIImage(CGImage: videoImage)
                }
                else {
                    image = nil
                }
                handle(image: image)
            })
        })

    }

get an error like this :

enter image description here

what should I do 😲😲😲😲😲😲😲?

like image 217
Shannon Yang Avatar asked Oct 11 '25 21:10

Shannon Yang


1 Answers

Can you show how you're setting up your AVPlayerItemVideoOutput?

It looks like you're using some (unknown to me, p422?) kind of 4:2:2 format instead of a more compatible one like kCVPixelFormatType_420YpCbCr8BiPlanarFullRange or kCVPixelFormatType_32BGRA.

like image 153
Rhythmic Fistman Avatar answered Oct 16 '25 06:10

Rhythmic Fistman