# \[MacOS\] frameAvailable returns empty CMSampleBuffer

**URL:** <https://forum.deepar.ai/t/macos-frameavailable-returns-empty-cmsamplebuffer/223>\
**Category:** SDK\
**Created:** [March 8, 2023, 5:02pm UTC](https://forum.deepar.ai/t/macos-frameavailable-returns-empty-cmsamplebuffer/223 "2023-03-08T17:02:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jon\_Davis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.deepar.ai/jon_davis/32/328_2.png) [@Jon\_Davis](https://forum.deepar.ai/u/Jon_Davis)\
**Post date:** [March 8, 2023, 5:02pm UTC](https://forum.deepar.ai/t/macos-frameavailable-returns-empty-cmsamplebuffer/223/1 "2023-03-08T17:02:33Z")

</div>

Hi,

My end goal is to convert the `CMSampleBuffer` within `func frameAvailable(_ sampleBuffer: CMSampleBuffer!)` to a `CGImage`.

I’m initializing DeepAR with:

```auto
let cgFrame = NSRectToCGRect(NSScreen.main!.frame)
self.arView = self.deepAR.initializeView(withFrame: cgFrame)
self.deepAR.startCapture(withOutputWidth: 1280, outputHeight: 720, subframe: cgFrame)
self.deepAR.delegate = self

```

`captureOutput` only enqueues the sampleBuffer. At this point, I can read the video sampleBuffer fine.

```auto
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
    self.deepAR.enqueueCameraFrame(sampleBuffer, mirror: true)
}

```

`frameAvailable` doesn’t return any processed video feed. The sampleBuffer isn’t nil, but theres nothing to convert to an image.

```auto
func frameAvailable(_ sampleBuffer: CMSampleBuffer!) {
  let ciImage = CIImage(cvImageBuffer: sampleBuffer.imageBuffer!)
  guard let cgImage = context.createCGImage(ciImage, from: ciImage.extent) else { return }
        
  DispatchQueue.main.async { [unowned self] in
    self.frame = cgImage
  }
}

```

Any tips on how I can get the processed feed to convert to an image would be appreciated.

Thanks,  
Jon

---

<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:** [March 8, 2023, 7:18pm UTC](https://forum.deepar.ai/t/macos-frameavailable-returns-empty-cmsamplebuffer/223/2 "2023-03-08T19:18:15Z")

</div>

Hi, i think the problem here is just an invalid subframe size. It should be in [0-1] range, like so:  
Example from our github:  
` self.deepAr.startCapture(withOutputWidth: 720, outputHeight: 1280, subframe: CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0))`

---

<div class="post-metadata">

**Author:** ![Jon\_Davis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.deepar.ai/jon_davis/32/328_2.png) [@Jon\_Davis](https://forum.deepar.ai/u/Jon_Davis)\
**Post date:** [March 9, 2023, 1:45am UTC](https://forum.deepar.ai/t/macos-frameavailable-returns-empty-cmsamplebuffer/223/3 "2023-03-09T01:45:39Z")

</div>

Thanks for the response. That got me closer.

In frameAvailable, there is still no feed in the CIImage, but the properties look correct now (image attached from debugger). Im not seeing any errors or output, so I’m at a loss. I’m curious if I’m not processing the sampleBuffer correctly? I’m not convinced the videoBuffer is being dropped, but it’s a bit of a black box.

Thanks for the help,  
Jon

 ![ciImage](https://europe1.discourse-cdn.com/flex017/uploads/deepar/original/1X/fbf77c7b2f1fa05dfe2e5cf7767fa70c074c0471.png)

---

<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:** [March 9, 2023, 4:21pm UTC](https://forum.deepar.ai/t/macos-frameavailable-returns-empty-cmsamplebuffer/223/4 "2023-03-09T16:21:12Z")

</div>

Have you checked this code for reference? We convert buffers to CIImage in this example

> <https://github.com/DeepARSDK/videoprocessing-ios-objc/blob/2f2232043e3ecc96c9daef71a4124b380c163240/videoprocessing-ios-objc/ViewController.m>

---

<div class="post-metadata">

**Author:** ![Jon\_Davis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.deepar.ai/jon_davis/32/328_2.png) [@Jon\_Davis](https://forum.deepar.ai/u/Jon_Davis)\
**Post date:** [March 9, 2023, 7:25pm UTC](https://forum.deepar.ai/t/macos-frameavailable-returns-empty-cmsamplebuffer/223/5 "2023-03-09T19:25:33Z")

</div>

Thanks for sharing. I can’t get this to work with the macos github sample you provide either, but it seems to work fine on iOS.

I’ll keep exploring other options.

Jon
