ios - 使用 Swift/Objective-C 减少色带以从最多 200 个视频帧创建 GIF
问题描述
我想从视频帧制作 GIF。每帧(UIImage)大小最多为960 * 540。由于 GIF 绑定到 256 种颜色,我遇到了更多颜色问题。帧生成不佳。经过这么多研究,我发现了可以减少色带的抖动方法。我没有采用这种方法,因为抖动的默认时间复杂度是 O(N^2),其中 N 是图像宽度和高度的乘积。我不知道如何在不抖动 200 帧的情况下有效地减少色带。是否有任何其他可用的技术或过滤器可以有效地减少色带?
原始视频:原始视频
我制作的 GIF:我
的 GIF 我需要的 GIF:better-GIF
我的方法:首先,我将所有帧保存为来自 Video 的 UIImage。然后我使用以下代码创建了 GIF:
func generateImagesToGif(photos: [UIImage], filename: String) -> Bool {
let documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let path = documentsDirectoryPath.appending(filename)
let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: 0]]
let gifProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: 0.5]]
let cfURL = URL(fileURLWithPath: path) as CFURL
if let destination = CGImageDestinationCreateWithURL(cfURL, kUTTypeGIF, photos.count, nil) {
CGImageDestinationSetProperties(destination, fileProperties as CFDictionary?)
for photo in photos {
CGImageDestinationAddImage(destination, photo.cgImage!, gifProperties as CFDictionary?)
}
return CGImageDestinationFinalize(destination)
}
return false
}
更新:看看这个(高质量 GIF)。他们的 GIF 看起来像原始视频。非常低的色带!
解决方案
推荐阅读
- math - 垂直定位传感器的磁力计航向计算
- java - java中的哈希函数
- arrays - Swiftui - 我如何在 Firestore 中查询我的数组?
- snowflake-cloud-data-platform - 如何用数组转置雪花表
- javascript - Selection: incorrect isCollapsed value for deselecting by clicking on selected text
- c++ - Ray and Plane Intersection in C++ (Plane defined as normal and D)
- python-3.x - An issues with running "pip install Beautifulsoup" on cmd
- machine-learning - Pytorch VNet final softmax activation layer for segmentation. Different channel dimensions to labels. How do I get prediction output?
- python-3.x - How should I implement List annotation, which contains any type of objects?
- cmake - Linking mingw libs with cmake