1

Iam making an app which does a basic video processing . Ive successfully managed to merge to video (video over video) . enter image description here how can I crop the up-left small video into a circle ?

user3703910
  • 624
  • 1
  • 5
  • 25
  • Possible duplicate of https://stackoverflow.com/questions/28258270/how-to-crop-a-video-to-a-circle-in-ios This might be of some help to you. – Aaqib Hussain Jun 26 '17 at 17:19
  • Ive looked at this before posting it doesnt confirm to AVMutableVideoCompositionLayerInstruction that I add to AVMutableVideoCompositionInstruction – user3703910 Jun 26 '17 at 17:54

1 Answers1

1

If You want to export that video You need to:

  1. Create CALayer which would be the parent of Your video layers
  2. Add two CALayers as sublayers of parent layer
  3. Create a CAShapeLayer circle and mask the video layer you want
  4. Create AVMutableVideoComopsition and setup it (frameDuration, renderSize, instructions, ... etc)
  5. Create an AVVideoCompositionCoreAnimationTool instance with init(postProcessingAsVideoLayers:in:) method
  6. Assign it to AVMutableVideoComopsition's animationTool property
  7. Export it with AVAssetExportSession (with setting AVMutableVideoComopsition to property videoCompostion of export session)

This is only for post processing not for preview.

For preview You can try to create two AVPlayerLayers with masking one of them, if this doesn't work You can create a custom video compositor and render each frame as you wish

Tiko
  • 485
  • 4
  • 10
  • How can we put videos in individual layers – Talha Ahmad Khan Feb 15 '19 at 11:46
  • @TalhaAhmadKhan while exporting? if yes then you need to look at `AVVideoCompositionCoreAnimationTool` documentation. for example: https://medium.com/@dzungnguyen.hcm/add-overlay-image-to-video-21d9cc03c9eb . Its in Objective C, but I think it would not be a problem to translate it. – Tiko Mar 04 '19 at 18:32
  • yes while exporting, but the link you gave shows us to overlay image instead I am interested in overlaying video on top of other video. – Talha Ahmad Khan Mar 05 '19 at 11:36
  • I will suggest to try with https://developer.apple.com/documentation/avfoundation/avvideocompositing . – Tiko Mar 05 '19 at 14:28