VideoFlint / Cabbage

A video composition framework build on top of AVFoundation. It's simple to use and easy to extend.
MIT License
1.52k stars 221 forks source link

关于Timeline中的overlays轨道 #8

Closed xuzhenhao closed 5 years ago

xuzhenhao commented 5 years ago

没有找到关于overlayers轨道的demo。研究了下你的源码,不知道理解的对不对,请教一下。如果要使用overlays轨道,实现当前track中x:50,y,50的坐标中放一个size为50*50的overlay。参考了了ImageOverlayItem的实现方法,可以通过trackItem.configuration.videoConfiguration.transform配置来传相应的transform实现,这样可以实现,但使用起来不是很方便。

我的理解,overlays: [VideoProvider] ,overlays不只是VideoProvider协议,更合适的是进一步封装了frame的协议。

vitoziv commented 5 years ago

确实是有提供设置 frame 的设置比较方便。我重新思考了一下对 frame 的支持,你的建议提醒了我。在 videoConfiguration 里的 baseContentMode 其实会和 frame 有设置上的冲突,只有在 baseContentMode 为 custom 的时候才适合设置 frame。

所以我重构了一下 frame 的位置,ImageOverlayItem 里面不再有 frame 属性,而是在 videoConfiguration 的 baseContentMode 里设置 frame。

代码大概是这样

let frame = CGRect()
videoConfiguration.baseContentMode = .custom(frame)

这样,无论是视频还是图片都可以设置 frame 了

你可以拉最新的代码试试

xuzhenhao commented 5 years ago

确实是有提供设置 frame 的设置比较方便。我重新思考了一下对 frame 的支持,你的建议提醒了我。在 videoConfiguration 里的 baseContentMode 其实会和 frame 有设置上的冲突,只有在 baseContentMode 为 custom 的时候才适合设置 frame。

所以我重构了一下 frame 的位置,ImageOverlayItem 里面不再有 frame 属性,而是在 videoConfiguration 的 baseContentMode 里设置 frame。

代码大概是这样

let frame = CGRect()
videoConfiguration.baseContentMode = .custom(frame)

这样,无论是视频还是图片都可以设置 frame 了

你可以拉最新的代码试试

给效率点赞。另外请教一个问题,目前frame的效果是和CompositionGenerator的renderSize强关联的。不知道在实际项目中,是如何处理这种问题的。如果用户导出时,选择的尺寸改变了,是遍历一遍配置,进行相应的缩放修改还是有更好的方案。 另外,我参考了videoleap的交互体验,似乎也不是很理想,像从16:9调整成1:1,不是等比例的,所有的layer就会错位,需要用户重新手动修改一遍。

vitoziv commented 5 years ago

frame 是基于原始图像的大小进行缩放的,和 renderSize 没关系。只是 frame 的位置是基于 renderSize 的画布设置的,位置可能不是想要的。有想到可能可以引入对齐方式、anchorPoint 之类的东西,但是这种功能在 UI 上会比较复杂,现在我也还没有想到更好的方案哈。

xuzhenhao commented 5 years ago

frame 是基于原始图像的大小进行缩放的,和 renderSize 没关系。只是 frame 的位置是基于 renderSize 的画布设置的,位置可能不是想要的。有想到可能可以引入对齐方式、anchorPoint 之类的东西,但是这种功能在 UI 上会比较复杂,现在我也还没有想到更好的方案哈。

感谢解答