Splime 是一个工具,让您能够 将视频拆分成帧。同时,它还允许您收集有关视频本身的一些信息。Splime 使用 AVFoundation 框架。
Splime 会返回一个完成块: (images: [UIImage]) -> (),让您获取拆分后的帧。还有一个可选的进度块: ((progress: Float) -> ())?,用于跟踪拆分器的进度。
videoSpliter = Splime(url: stringPath)
videoSpliter.split({ (images) -> () in
//use the [UIImage], images frames
}, progressBlock: { (progress) -> () in
print("current progress : [\(progress)]")
})
Splime 收集与视频相关的一些信息。同样地,您可以用于执行此类操作。您可以收集视频中的帧的总数、总时长(以秒为单位)、每帧的时间等。当您使用有效视频的 URL 初始化新的 Splime 对象,或设置新的 URL 时,Splime 会填充一个结构体,其中包含所有这些信息。所有这些信息都是为了安全起见而只读的。
videoSpliter = Splime(url: stringPath)
//Informations collected
videoSpliter.url = stringPath2
//new Informations collected
//get informations:
videoSpliter.assetInformations.timeScale
videoSpliter.assetInformations.timeValuePerFrame
videoSpliter.assetInformations.totalFrames
videoSpliter.assetInformations.totalSeconds
videoSpliter.assetInformations.frameRate
Splime 允许您配置帧分离的方式。您可以指定以下内容:
//For the time interval, CMTime is used, to let you use, a very high precision.
//You can use the same timeScale as the video, avalaible in the video information.
//Split the frames from the 4 secondes, to the 10 secondes.
videoSpliter.startInterval = CMTimeMake(4, videoSpliter.assetInformations.timeScale)
videoSpliter.endInterval = CMTimeMake(10, videoSpliter.assetInformations.timeScale)
//Keep only one frame, every 5.
videoSpliter.everyFrames = 5
//Keep only 35 maximum frames.
//Can be used to limit the memory usage, if the video can.
videoSpliter.totalFrames = 35