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?
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.
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.