5

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

Community
  • 1
  • 1
Martin Herman
  • 888
  • 13
  • 34
  • 1
    You will need to look at AVVideoCompositionInstruction where you can set the backgoundColor property. You will also need to create a AVVideoCompositionLayerInstruction with an applied transform to translate and possibly scale your video and add that layer instruction to your video composition instruction. – SheffieldKevin Jul 18 '15 at 13:47

1 Answers1

1

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.

jacob bullock
  • 651
  • 4
  • 14