# Video Capture in iOS and MacOS

**URL:** <https://forum.juce.com/t/video-capture-in-ios-and-macos/42626>\
**Category:** MacOSX and iOS\
**Created:** [November 7, 2020, 2:52pm UTC](https://forum.juce.com/t/video-capture-in-ios-and-macos/42626 "2020-11-07T14:52:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nelroy](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@nelroy](https://forum.juce.com/u/nelroy)\
**Post date:** [November 7, 2020, 2:52pm UTC](https://forum.juce.com/t/video-capture-in-ios-and-macos/42626/1 "2020-11-07T14:52:46Z")

</div>

I’m trying to add video streaming to an audio app and have run across some problems with the iOS build. I’m using CameraDevice to capture the video with a listener to queue and encode frames. The project works fine in MacOS, but as soon as I try it on iOS the listener is called exactly once and never again. I also hear the simulated shutter sound on the device, which would suggest that it’s just taking a still picture. The preview component works fine. This is the relevant code:

```
void VideoCapture::openCameraAsync( int deviceNumber )
{
    SafePointer<VideoCapture> This (this);

    CameraDevice::openDeviceAsync ( deviceNumber,
                               [This] (CameraDevice* device, const String& error) mutable
                               {
                                    This->cameraDeviceOpenResult (device, error);
                               });
}

void VideoCapture::cameraDeviceOpenResult (CameraDevice* device, const String& error)
 {
    // If camera opening worked, create a preview component for it..
   cameraDevice.reset (device);

   if ( cameraDevice.get() != nullptr)
   {
       cameraDevice->addListener( this );
       cameraPreviewComp.reset (cameraDevice->createViewerComponent());
       addAndMakeVisible (cameraPreviewComp.get());
       resized ();
       DBG ( "Camera opened OK" );
   }
   else
   {
       AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "Camera open failed",
                                         "Camera open failed, reason: " + error);
       delete this;
   }
}
void VideoCapture::imageReceived (const Image &image)
{
    if ( image.getWidth() == 0 ) return;
    Image *imageCopy = new Image ( image.rescaled ( image.getWidth()/2, image.getHeight()/2) );
    encoderQueue->pushItem( imageCopy );
   frameCycle=0;
}

```

Any ideas?

---

<div class="post-metadata">

**Author:** ![nelroy](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@nelroy](https://forum.juce.com/u/nelroy)\
**Post date:** [November 16, 2020, 6:54am UTC](https://forum.juce.com/t/video-capture-in-ios-and-macos/42626/2 "2020-11-16T06:54:00Z")

</div>

Hi - anybody have any idea about this?

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [November 16, 2020, 6:57pm UTC](https://forum.juce.com/t/video-capture-in-ios-and-macos/42626/3 "2020-11-16T18:57:59Z")

</div>

Thanks, it looks like that behaviour was buggy. I’ve pushed a change which should provide equivalent behaviour on iOS and macOS:

> <https://github.com/juce-framework/JUCE/commit/f1362dbb9379902ac59e95d9ba96e60996d6dc14>

---

<div class="post-metadata">

**Author:** ![nelroy](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@nelroy](https://forum.juce.com/u/nelroy)\
**Post date:** [November 17, 2020, 10:14pm UTC](https://forum.juce.com/t/video-capture-in-ios-and-macos/42626/4 "2020-11-17T22:14:24Z")

</div>

Hi. I tried this out (same code as above) and it’s not quite the same behaviour as in MacOS. What happens is it takes a continual stream of photos (about 2 per second) and you can hear the simulated shutter sound with each photo.

---

<div class="post-metadata">

**Author:** ![nelroy](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@nelroy](https://forum.juce.com/u/nelroy)\
**Post date:** [January 15, 2021, 2:24pm UTC](https://forum.juce.com/t/video-capture-in-ios-and-macos/42626/5 "2021-01-15T14:24:07Z")

</div>

Just a quick update on this if anyone is watching - what I wanted was to capture video and stream H264, which isn’t what the module is intended for. Turns out that with a little hacking of the Juce code for recording video and a wrapper on the Video Toolbox, this works fine (although Video Toolbox is really obscure if you don’t know H264). Next stop Windows
