# "Invalid image format!" error help

**URL:** <https://forum.deepar.ai/t/invalid-image-format-error-help/572>\
**Category:** Help & Questions\
**Created:** [February 14, 2024, 9:42pm UTC](https://forum.deepar.ai/t/invalid-image-format-error-help/572 "2024-02-14T21:42:26Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![arintegrate](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@arintegrate](https://forum.deepar.ai/u/arintegrate)\
**Post date:** [February 14, 2024, 9:42pm UTC](https://forum.deepar.ai/t/invalid-image-format-error-help/572/1 "2024-02-14T21:42:26Z")

</div>

Hi,

I’d like to echo what @rafaelnobrekz said here ["Invalid image format!" is printed when call processFrame - #4 by rafaelnobrekz](https://forum.deepar.ai/t/invalid-image-format-is-printed-when-call-processframe/332/4)

> what are the supported pixel buffer input formats for `processFrame` and `enqueueCameraFrame` SDK methods? I’m getting invalid pixel format for 420f capture straight from the camera (I would hope the enqueueCameraFrame would work with that?)

I am also getting “Invalid image format!” from the default 420f format coming from my iPad camera. What format should we be using instead?

---

<div class="post-metadata">

**Author:** ![arintegrate](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@arintegrate](https://forum.deepar.ai/u/arintegrate)\
**Post date:** [February 14, 2024, 10:40pm UTC](https://forum.deepar.ai/t/invalid-image-format-error-help/572/2 "2024-02-14T22:40:36Z")

</div>

I’m no longer seeing the error after converting my pixel buffer to kCVPixelFormatType\_32BGRA … however, `frameAvailable` is not being called. Any tips here would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![arintegrate](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@arintegrate](https://forum.deepar.ai/u/arintegrate)\
**Post date:** [February 14, 2024, 11:30pm UTC](https://forum.deepar.ai/t/invalid-image-format-error-help/572/3 "2024-02-14T23:30:43Z")

</div>

I believe this might be related [A very serious issue has occurred. I urgently request a prompt response. "initializeOffscreen dosent work with new version of deepAR"](https://forum.deepar.ai/t/a-very-serious-issue-has-occurred-i-urgently-request-a-prompt-response-initializeoffscreen-dosent-work-with-new-version-of-deepar/546)

Please help… this is an urgent issue. I also can’t seem to find any older releases of the deepAR iOS sdk to use as a workaround.

---

<div class="post-metadata">

**Author:** ![arintegrate](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@arintegrate](https://forum.deepar.ai/u/arintegrate)\
**Post date:** [February 15, 2024, 1:42am UTC](https://forum.deepar.ai/t/invalid-image-format-error-help/572/4 "2024-02-15T01:42:17Z")

</div>

I’ve also tried using `processFrameAndReturn` however this function does not seem to properly set `outputBuffer`. I’ve tried it both with Swift and Objective C.

---

<div class="post-metadata">

**Author:** ![olly](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.deepar.ai/olly/32/672_2.png) [@olly](https://forum.deepar.ai/u/olly)\
**Post date:** [February 15, 2024, 2:21am UTC](https://forum.deepar.ai/t/invalid-image-format-error-help/572/5 "2024-02-15T02:21:45Z")

</div>

As seen in the link [A very serious issue has occurred. I urgently request a prompt response. "initializeOffscreen dosent work with new version of deepAR"](https://forum.deepar.ai/t/a-very-serious-issue-has-occurred-i-urgently-request-a-prompt-response-initializeoffscreen-dosent-work-with-new-version-of-deepar/546), currently, versions including and below 5.2.0 cannot be downloaded. Furthermore, if you check the update modifications here [https://docs.deepar.ai/deepar-sdk/platforms/ios/changelog](https://docs.deepar.ai/deepar-sdk/platforms/ios/changelog), starting from version 5.4.2, a priority-related issue has been resolved. However, when initializing Offscreen, there is a side effect that frames are not coming out through frameAvailable as they should.

The current solution is to use version 5.4.1 with initializeOffscreen and use the encoded frames (note, however, that you may encounter thread priority errors [in purple] in Xcode. The app may not crash during use, but there could be performance issues, which I cannot guarantee).

The second method is to use the metalview or, unless there is a special reason not to, use the UIView created by deepAR, specifically the createARView function for rendering. This seems to be the best option at the moment, allowing the use of the latest SDK from deepAR.

Personally, I feel that using the second method seems to be faster.

---

<div class="post-metadata">

**Author:** ![arintegrate](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@arintegrate](https://forum.deepar.ai/u/arintegrate)\
**Post date:** [February 15, 2024, 3:03am UTC](https://forum.deepar.ai/t/invalid-image-format-error-help/572/6 "2024-02-15T03:03:53Z")

</div>

Thanks for the tips! I didn’t realize 5.4.1 was available – I’ll try that first.

My app has a lot of custom work done on the video capture front, so being able to process frame-by-frame is ideal, as opposed to using createARView.

Can you elaborate on what you mean by using the metalview?

---

<div class="post-metadata">

**Author:** ![olly](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.deepar.ai/olly/32/672_2.png) [@olly](https://forum.deepar.ai/u/olly)\
**Post date:** [February 15, 2024, 5:53am UTC](https://forum.deepar.ai/t/invalid-image-format-error-help/572/7 "2024-02-15T05:53:50Z")

</div>

Essentially, through the camera delegate, we receive a new frame each time and encode it through deepAR before displaying it on the screen. Therefore, there is a passive method where the frame received in frameAvailable is shown on the screen each time a new frame is updated through the draw function of the metalView.

By feeding the sample buffer received from the camera into enqueueCameraFrame or processFrame, it automatically renders through the createARView that was registered initially.

========================================================================

For now, please match the version to 5.4.1 and follow the guide below. It should work.

> **[Offscreen rendering guide | DeepAR](https://docs.deepar.ai/deepar-sdk/platforms/ios/offscreen/)**
>
> Follow this guide to enable DeepAR iOS SDK to produce frames in pixel buffer format.

========================================================================

In my opinion, there seem to be two main reasons for using offscreen and createARView. Basically, you use createARView, and the reasons for using offscreen are:

1. Not only for deepAR but also when each frame needs the developer’s special filter or additional work.
2. To minimize resources and enhance performance.

However, since there is still an issue with version 5.4.1, the second point is not certain. Despite this, if the first point is applicable, then it makes sense to use offscreen for direct control, and otherwise, it’s appropriate to use it as is.

Of course, this is just a personal opinion.

---

<div class="post-metadata">

**Author:** ![arintegrate](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@arintegrate](https://forum.deepar.ai/u/arintegrate)\
**Post date:** [February 15, 2024, 6:08am UTC](https://forum.deepar.ai/t/invalid-image-format-error-help/572/8 "2024-02-15T06:08:01Z")

</div>

Thanks! 5.4.1 is working for me using offscreen and processFrame, however when I call `switchEffect`, the effects are not being applied. I am trying different things but any thoughts are appreciated!

---

<div class="post-metadata">

**Author:** ![olly](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.deepar.ai/olly/32/672_2.png) [@olly](https://forum.deepar.ai/u/olly)\
**Post date:** [February 15, 2024, 6:09am UTC](https://forum.deepar.ai/t/invalid-image-format-error-help/572/9 "2024-02-15T06:09:45Z")

</div>

Can you show me how you are using switchEffect?

And also, are you using processFrame to send frames and then displaying them on the screen through FrameAvailable? I think that the frames coming from the camera are just being rendered directly on the screen, so essentially, the encoded [=with deepAR effects] images are just being discarded.

====================================================================

The order is as follows:

1. Receive a new frame from the cameraDelegate.
2. Use the frame received in step 1 with deepAR.processFrame(CMSampleBuffer).
3. Receive the newly encoded frame from deepAR in FrameAvailable.
4. Display the new frame received on the screen.

---

<div class="post-metadata">

**Author:** ![arintegrate](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@arintegrate](https://forum.deepar.ai/u/arintegrate)\
**Post date:** [February 15, 2024, 6:41am UTC](https://forum.deepar.ai/t/invalid-image-format-error-help/572/10 "2024-02-15T06:41:36Z")

</div>

I think I am following that order. I see the DeepAR watermark but no effects.

I initialize deepAR like this

```auto
deepAR = DeepAR()
deepAR.setLicenseKey("my-key-here")
deepAR.changeLiveMode(false)
deepAR.initializeOffscreen(withWidth: 1, height: 1)
deepAR.delegate = self

deepAR.switchEffect(withSlot: "effect", path: "viking_helmet.deepar")

```

Then in my `AVCaptureVideoDataOutputSampleBufferDelegate`

```auto
if let ciImage = sampleBuffer.ciImage {
    if deepAR.renderingResolution.width != ciImage.extent.size.width {
        deepAR.setRenderingResolutionWithWidth(Int(ciImage.extent.size.width), height: Int(ciImage.extent.size.height))
    }
    if let pixelBuffer = ciImage.toPixelBuffer(
        using: context,
        pixelBufferAttributes: [
            kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA
        ]
    ) {
        deepAR.processFrame(pixelBuffer, mirror: false)
    }
}

```

I’m converting the sample buffer to a pixel buffer, avoiding 420f format (see the start of this post).

Then in `frameAvailable` I pass along the `sampleBuffer` to my app’s further filtering.

I’ve also tried calling `switchEffect` in several other places.

---

<div class="post-metadata">

**Author:** ![olly](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.deepar.ai/olly/32/672_2.png) [@olly](https://forum.deepar.ai/u/olly)\
**Post date:** [February 15, 2024, 7:19am UTC](https://forum.deepar.ai/t/invalid-image-format-error-help/572/11 "2024-02-15T07:19:25Z")

</div>

1. Please try converting the path of the deepAR filter as follows:

```auto
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.

```auto
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?

---

<div class="post-metadata">

**Author:** ![arintegrate](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@arintegrate](https://forum.deepar.ai/u/arintegrate)\
**Post date:** [February 15, 2024, 5:41pm UTC](https://forum.deepar.ai/t/invalid-image-format-error-help/572/12 "2024-02-15T17:41:51Z")

</div>

Converting the path did the trick! Thank you!

As for #2, I didn’t try it but I don’t think the filter would apply if the image was generated before `processFrame`?

To answer your last question - I am applying the sample buffer received in frameAvailable to further processing before it is rendered onscreen. This app is a “photo booth”-style app and already has several processing options built-in such as exposure, brightness, zoom, etc.

---

<div class="post-metadata">

**Author:** ![arintegrate](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@arintegrate](https://forum.deepar.ai/u/arintegrate)\
**Post date:** [February 15, 2024, 10:57pm UTC](https://forum.deepar.ai/t/invalid-image-format-error-help/572/13 "2024-02-15T22:57:13Z")

</div>

Almost everything is working really nice now! Just one more question – any idea why processFrame might result in an all-black image? This only happens occasionally during a photo capture, and honestly, may not be Deep AR related. Just thought I’d float it here in case you have any idea off the top of your head.

Really appreciate all this help! And no worries if you have no idea regarding the black image … I’ll figure it out eventually.

---

<div class="post-metadata">

**Author:** ![jelena](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.deepar.ai/jelena/32/14_2.png) [@jelena](https://forum.deepar.ai/u/jelena)\
**Post date:** [February 16, 2024, 3:05pm UTC](https://forum.deepar.ai/t/invalid-image-format-error-help/572/14 "2024-02-16T15:05:57Z")

</div>

Usually that would happen if the input frame was black or empty.

If it’s consistently the first frame that does this you can try changing this line deepAR.initializeOffscreen(withWidth: 1, height: 1)  
to anticipate a most likely input resolution to see if that helps.

As @olly suggested you can try saving your input frames as images to check their content.
