4

I have a animation created using normal core animation methods. If there any way to create a movie file using avassetwriter? Ive seen other questions which show the how to use avassetwriter to create a movie using images, but i would like to create a movie using a animation created with core animation.

Thank in advance

1 Answers1

4

Run a timer (or whatever) to periodically convert the animation's CALayer to a UIImage (see here), then write that image to the AVAssetWriter as seen in the other examples you cite. You'll also need to keep track of elapsed time, because ultimately what you're trying to do is set up a call to -[AVAssetWriterPixelBufferAdapter appendPixelBuffer:atPresentationTime:].

I did a talk a few months back that did regular screen grabs and made a movie of it, called VTM_ScreenRecorder.zip. Only difference for you might be that my code is getting the window's CALayer, and you seem to be interested in some other layer (the one you're animating).

Community
  • 1
  • 1
invalidname
  • 3,175
  • 21
  • 18
  • Thanks @invalidname. It sounds like your screen recorder captures the `CALayer` while it animates in a window. If the `CALayer` is not plugged into a view hierarchy, do you know how to increment its animation time? I haven't found a way to drive the time of a CALayer directly. There's a layer method called `-applyForTime:presentationObject:modelObject:`, but it's private API. Without that ingredient, it's not clear how I'd use your solution for offscreen export. – otto Jun 14 '12 at 23:23
  • @otto did you find a solution to this? – Crashalot Feb 06 '16 at 11:30