Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于对视频添加字幕和动画的实现讨论? #27

Closed
rayn0r126 opened this issue Jul 2, 2019 · 5 comments
Closed

关于对视频添加字幕和动画的实现讨论? #27

rayn0r126 opened this issue Jul 2, 2019 · 5 comments

Comments

@rayn0r126
Copy link

你好,首先非常感谢vitoziv的无私分享!大致把Cabbage的中文说明和源代码梳理了一下,但对Cabbage的设计思路和使用还有一些不太清楚的地方希望请教讨论一下。目前,项目需要实现给视频添加字幕和动画贴图的功能,我不太清楚是通过timeline上的overlays实现,还是使用CALayer去实现。但如果使用CALayer但的话,预览和渲染需要维护两套业务逻辑感觉比较麻烦。想请教一下vitoziv,Cabbage对这方面需求的支持是怎样考虑的以及你的建议?

@vitoziv
Copy link
Contributor

vitoziv commented Jul 5, 2019

不建议使用 CALayer,可以参考这里的说得贴纸部分的使用方式:中文使用文档

@rayn0r126
Copy link
Author

rayn0r126 commented Jul 5, 2019

非常感谢vitoziv的回复!但是如果直接使用ImageOverlayItem实现字幕和动画贴图,我有几个问题比较疑惑:

1.如果不使用CALayer怎样支持类似GIF的动效贴图。

2.字幕和动效贴图在编辑时的预览显示,是交由Cabbage直接渲染到视频上,还是根据Timeline自己去控制显示和动画的位置。现在预览是生成CALayer交由AVSynchronizedLayer来处理的。还有就是通过ImageOverlayItem实现每次编辑调整后都需要Build PlayerItem这样可能会导致播放器闪烁一下。

3.我通过加载Image来创建一个TackItem,然后添加到overlays上面也可以实现叠加字幕的效果,不知道这种方式和你示例上通过TimeLine的passingThroughVideoCompositionProvider和ImageOverlayItem添加有什么区别。

@vitoziv
Copy link
Contributor

vitoziv commented Jul 6, 2019

你可以继承 ImageResource,实现一个 GIFResource,在内部根据时间返回 gif 的画面。
编辑的时候,你可以用 AVSynchronizedLayer 来做预览,禁用 Cabbage 的渲染,等到截图和导出的时候使用 Cabbage 渲染。
添加到 overlays 上会有个数限制,在底层其实是添加了视频轨道,所以适合添加视频类型的 TrackItem 到 overlays 上。纯图片贴纸用 passingThroughVideoCompositionProvider,可以减少视频轨道使用。

@rayn0r126
Copy link
Author

好的,非常感谢!

@JackMayx
Copy link

我的做法很简单,不知道合不合适。
原本我也想使用AVSynchronizedLayer来做预览,发现不太好使,因为添加的字幕和贴图有需求需要拖动改变大小以及旋转等各种操作。所以我在预览的时候做的一个假view,只是添加到playverView上面,方便操作等各种处理,至于显示和隐藏全部是基于当初设置的时间范围做调整,在合成视频的时候把所有的CALayer统一放到AVVideoCompositionCoreAnimationTool上去渲染出来。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants