Has anyone managed to get Monkeybread AVFoundation working on iOS?

The Monkeybread AVFoundation classes are mostly marked as working on iOS and so I am keen to use them to provide more access to camera controls than I can get using the AVFoundation classes within iOSKit.

But I’m stuck on a problem – the JPEG image returned by the captureStillImageAsynchronouslyCompleted event is always oriented incorrectly except for one of the landscape orientations.

I’ve exchanged half-a-dozen emails with Christian over the past two years about this (that’s not a typo – that’s how long we’ve been discussing this) but without any solution. The closest we got was a little over a year ago when Christian suggested converting the returned image into a CIImage and using the orientation property of that object. Unfortunately the converted CIImage has no orientation property. So we are back to square one.

I have emailed Christian again but, while I wait for a reply, I was wandering whether anybody on the forum had any other suggestions to correctly orient the image?

1 Like

I am not using AVFoundation in my projects, sorry.

All I know is that the Xojo image picker has issues with orientation but Christian’s plug-ins don’t so I’m using that now.

I guess you tried searching stackoverflow to find similar issues in swift/objective-c?

I think we fixed that… :roll_eyes:

3 Likes

This looks like the same problem: Image orientation when capturing a… | Apple Developer Forums

And this looks like another: ios - AVCAPTURE image orientation - Stack Overflow

Christian has been in touch to say that he will take another look at it – which I am most grateful for – but in the meantime I will experiment with ways to determine the orientation rather than relying on the returned image to be correct. I already have some code using UIDevice to get the orientation so will try that first.

Looking into this, it seems to be quite complicated.

First you device which orientations an application accepts. So why the device is rotated, your app may not be, if you declaring that. See in layout editor for the switches.

Then you can query Orientation from UIDevice class. I’ll add UIDeviceMBS class to our plugin to query it and get OrientationDidChange event to react on it.

Then AVCaptureConnectionMBS class has a videoOrientation property to get/set orientation of video. That orientation may be rotated for the video independent of the device rotation.

Then we also have automaticallyAdjustsVideoMirroring and VideoMirrored properties playing a role to decide whether it’s mirrored.

With all the properties, it seems to be difficult to find the right combination.

Recently I made a little project to make pictures on a wedding and I ended up frustrated myself. I finally decided to put in switches for user to switch different combinations until the preview was right (seeing videoOrientation) and then also applying mirror + rotation on the taken pictures until they were correctly.

As a developer of video apps (Swift and Obj-C) for iOS, I’m familiar with the problem and have a set of code that fixes the orientation. It’s a two pass approach. I can share the code if that will help the AVFoundation plugin.

2 Likes

That sounds great @John_Balestrieri ! :pray:

If @Christian_Schmitz doesn’t take you up on the offer, please share it with me and I’ll make sure he gets it. :slight_smile:

@Christian_Schmitz was John’s code helpful?

John may post something for us soon.

@John_Balestrieri any chance you could share that code? :slight_smile:

I’ll share with @Christian_Schmitz if he needs to improve the plugin, but it’s production code that I use in my commercial software, and I don’t want it found by my competition. :slightly_smiling_face:

I see @Christian_Schmitz 's comment now—I missed it before. I’ll forward what I have by email.

Thanks. I’ll check it out.