What's the best way to composite frame-based animated stickers over recorded video?

╄→гoц情女王★ 提交于 2019-12-08 06:45:22

问题


We want to allow the user to place animated "stickers" over video that they record in the app and are considering different ways to composite these stickers.

  1. Create a video in code from the frame-based animated stickers (which can be rotated, and have translations applied to them) using AVAssetWriter. The problem is that AVAssetWriter only writes to a file and doesn't keep transparency. This would prevent us from being able to overly it over the video using AVMutableComposition.

  2. Create .mov files ahead of time for our frame based stickers and composite them using AVMutableComposition and layer instructions with transformations. The problem with this is that there are no tools for easily converting our PNG based frames to a .mov while maintaining an alpha channel and we'd have to write our own.

  3. Creating separate CALayers for each frame in the sticker animations. This could potentially create a very large number of layers per frame rate of the video.

Or any better ideas?

Thanks.


回答1:


I would suggest that you take a look at my blog post on this specific subject. Basically, this example shows how RGBA video data can be loaded from a file attached to the app resources. This is imported from a .mov that contains Animation RGBA data on the desktop. A conversion step is required to get the data from the Desktop into iOS, since plain H.264 cannot support an Alpha channel directly (as you have discovered). Note that older hardware may have issues decoding a H.264 user recorded video and then another one on top of that, so this approach of using the CPU instead of the H.264 hardware for the sticker is actually better.



来源:https://stackoverflow.com/questions/38131274/whats-the-best-way-to-composite-frame-based-animated-stickers-over-recorded-vid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!