Shannon Yang
Shannon Yang

Reputation: 111

"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 😲😲😲😲😲😲😲?

Upvotes: 4

Views: 2334

Answers (1)

Gordon Childs
Gordon Childs

Reputation: 36074

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.

Upvotes: 3

Related Questions