"Invalid image format!" error help

  1. Please try converting the path of the deepAR filter as follows:
extension String {
    // Returns the device's internal path for a file name (with extension)
    var path: String? {
        return Bundle.main.path(forResource: self, ofType: nil)
    }
}

and the slot should be like
“effect” → “face” or “background”

and you should try converting

  1. Before executing deepAR.processFrame(pixelBuffer, mirror: false), try converting the pixelBuffer to an image and saving it to the gallery. If the applied filter does not appear in this part, there may be another problem.
func imageFromSampleBuffer(sampleBuffer: CMSampleBuffer) -> UIImage? {
        if let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) {
            let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
            let context = CIContext()
            if let cgImage = context.createCGImage(ciImage, from: ciImage.extent) {
                return UIImage(cgImage: cgImage)
            }
        }
        return nil
    }

Also, I’m curious where you are applying the sample buffer received in frameAvailable?

2 Likes