使用 Metal 的覆盖 alpha 通道视频动画播放视图。
示例
要运行示例项目,请克隆仓库,然后首先在 Example 目录中运行 pod install。
用法
确保在文件顶部导入 import Kitsunebi
import Kitsunebi
然后,在您的视图控制器中实例化 PlayerView
private lazy var playerView: PlayerView = PlayerView(frame: view.bounds)!
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(playerView)
}
您可以用任何帧率播放透明视频。baseVideo 是彩色视频,alphaVideo 是单色 alpha 通道视频。请参考示例视频文件。
let baseVideoURL = Bundle.main.url(forResource: "base", withExtension: "mp4")!
let alphaVideoURL = Bundle.main.url(forResource: "alpha", withExtension: "mp4")!
playerView.play(base: baseVideoURL, alpha: alphaVideoURL, fps: 30)
安装
Kitsunebi 通过 CocoaPods 可用。要安装它,只需在 Podfile 中添加以下行
pod 'Kitsunebi'
作者
Tomoya Hirano, [email protected]
许可证
Kitsunebi遵循MIT许可证。更多信息请参阅LICENSE文件。
示例视频文件
赞助商
使用ffmpeg分割视频
ffmpeg -i base.mp4 -i alpha.mp4 -filter_complex "nullsrc=size=1500x1334 [base];[0:v] setpts=PTS-STARTPTS, scale=750x1334 [left];[1:v] setpts=PTS-STARTPTS, scale=750x1334 [right];[base][left] overlay=shortest=1 [tmp1];[tmp1][right] overlay=shortest=1:x=750" output.mp4