facebookarchive / Keyframes

A library for converting Adobe AE shape based animations to a data format and playing it back on Android and iOS devices.
https://facebookincubator.github.io/Keyframes/
Other
5.34k stars 302 forks source link

Embed animations in AVFoundation #115

Open mbarnach opened 7 years ago

mbarnach commented 7 years ago

Hi,

I've tried to play an animation inside a video composition. I'm using the MacOS version with AVFoundation. I'm able to play any other (made by me) animations embedded in CALayer. Using the KFVectorLayer, I can load the animation and get the first frame, but I cannot play the animation within the video. I'm using the default animation (sample_logo) to test. It seems the animations are not synced with the video timeline. I try to play the animation with startAnimation, but it doesn't work. Is it me doing something wrong or is it a missing feature that may be interesting to add to this nice library?

Thanks

renyu-io commented 7 years ago

Hi @mbarnach, I am not sure I fully understand your question. What do you mean by playing within a video? Could you show us the code you are playing with? Thanks

mbarnach commented 7 years ago

Hi, My goal is to export the animations loaded with Keyframes into my video file with AVFoundation. I'm using AVVideoCompositionCoreAnimationTool for that purpose to use the CALayer loaded from Keyframes. By settings the beginning of the animation to AVCoreAnimationBeginTimeAtZero in the KFVectorLayer.m file, I'm able to play the animation in a video composition. Unfortunately, I cannot get the full control on the animation loaded: how to show it only at a specified time? How to hide it after a certain amount of time? How to play it only once (or twice or X times) in the video composition? Etc. All these options rely on a writting access to the animations it seems, and this is not possible in the current stage. I think this could be an interesting option to set (on demand) the beginning of the animation and to expose the animations in order to use them directly in video composition. Therefore, we can use Keyframes to also load After Effects animations into videos.

vkozikov-tt commented 7 years ago

In case if someone else will be struggling with the issue that Keyframes animation keeps rendering only the first frame when is used in AVVideoComposition and extending mbarnach's comment above - one of the solutions to make it work is setting '.beginTime = AVCoreAnimationBeginTimeAtZero' for animations that are re-added within 'resetAnimations' methods in all 'KFVector...Layer.m' files that have it. Maybe there's some more laconic way though.