Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export portrait video to square but with scaleAspectFit ratio

In my app I allow users to record videos in portrait mode. I use that within the app and that is fine. However, I'm implementing a feature to share the videos on Instagram, where videos must be square.

Cropping the video to square, lets say the center part, is an option, however as the user doesn't consider this when taking the video, it usually turns out bad.

Therefore, I'd like to export the video square, but with an aspect fit ratio and with two bars left and right. Optimally, is there any way to define the colors of the background (either by code or by UIImage).

The closest thing I was able to find is this, however I can't make much use of it as I'm unclear on how to set up the transformation.

Example (red box just to mark the image bounds): Example

like image 232
Martin Herman Avatar asked Nov 10 '22 09:11

Martin Herman


1 Answers

Beside trying to add black bars and re-render the video you can use the cameraOverlayView property of UIImagePickerController.

So you can create a view that has 2 black bars in OR you can create a view that has a square frame over the camera view so they know to frame it in there because it will share to instagram.

like image 83
jacob bullock Avatar answered Nov 14 '22 22:11

jacob bullock