0

I used code from here ( https://stackoverflow.com/a/46560615/13671576 ) to create and save animated video from UIImages. When I used mask to CALayer, it takes too much time to save the video. 118 seconds video take approximately 20 minutes for saving.

code for mask :

let imageLayer = CALayer()
imageLayer.frame = CGRect(x: 0, y: 0, width: self.outputSize.width, height: self.outputSize.height)
imageLayer.contents = nextPhoto.cgImage

let path = UIBezierPath()
.... then I drew a path......

let shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath
shapeLayer.lineCap = .round
shapeLayer.strokeColor = UIColor.white.cgColor
shapeLayer.backgroundColor = UIColor.clear.cgColor

imageLayer.mask = shapeLayer

I used 40 images and added animation. Then I used Layer in the Video. when I'm trying to save, it takes too much time. But without masking, it takes approximately 40 seconds to save the video.
Can you share any efficient code/approach or any other technique to crate and save video?

sagarthecoder
  • 137
  • 1
  • 9
  • You should use instruments to determine where all that time is spent. Maybe you can cache the shape that you draw if it doesn't chance? – de. May 27 '21 at 21:31
  • Could you use the same path over and over? You might be running that same code every time. Also building the video image array from the linked answer is an unnecessary step. You can add a video to you app and never show it. Run it behind the overlay layer in a place it is never seen. Then the exporter will run and you can just use images. – agibson007 May 29 '21 at 11:33
  • Can you share any efficient code/approach which create and save video quickly from UIImages? I pre-calculated all paths but no improve. – sagarthecoder May 30 '21 at 10:03

0 Answers0