Iam making an app which does a basic video processing .
Ive successfully managed to merge to video (video over video) .
how can I crop the up-left small video into a circle ?
Asked
Active
Viewed 951 times
1

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 Answers
1
If You want to export that video You need to:
- Create
CALayer
which would be the parent of Your video layers - Add two
CALayer
s as sublayers of parent layer - Create a
CAShapeLayer
circle and mask the video layer you want - Create
AVMutableVideoComopsition
and setup it (frameDuration
,renderSize
,instructions
, ... etc) - Create an
AVVideoCompositionCoreAnimationTool
instance withinit(postProcessingAsVideoLayers:in:)
method - Assign it to
AVMutableVideoComopsition
'sanimationTool
property - Export it with
AVAssetExportSession
(with settingAVMutableVideoComopsition
to propertyvideoCompostion
of export session)
This is only for post processing not for preview.
For preview You can try to create two AVPlayerLayer
s 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
-
-
@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