ios - 使用 AVAssetWriter 的 UIImages to Video 为 < 800 个图像产生黑框闪烁
问题描述
我被困了好几个星期!
我在stackoverflow上尝试了所有解决方案,它们在大约0到500张图像或12 fps上50秒的情况下工作正常,但对于更长的视频,大约50秒后会出现黑色闪烁,具体取决于iphone,iphone 6在50后发生在 iphone 8 上秒它发生在 1:30 之后
我尝试了从这个链接 writeImagesAsMovie()
功能接受的答案
有时我遇到内存分配问题,有时我没有,但黑色闪烁仍然存在。
// MARK: - Fill Pixel Buffer -
private func fillPixelBufferFromImage(image: UIImage, pixelBuffer: CVPixelBuffer) {
CVPixelBufferLockBaseAddress(pixelBuffer, CVPixelBufferLockFlags(rawValue: 0))
let pixelData = CVPixelBufferGetBaseAddress(pixelBuffer)
let rgbColorSpace = CGColorSpaceCreateDeviceRGB()
// Create CGBitmapContext
let context = CGContext(
data: pixelData,
width: Int(720),
height: Int(720),
bitsPerComponent: 8,
bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer),
space: rgbColorSpace,
bitmapInfo: CGImageAlphaInfo.premultipliedFirst.rawValue
)
// Draw image into context"
context?.draw(image.cgImage!, in: CGRect(x: 0, y: 0, width: 720, height: 720))
CVPixelBufferUnlockBaseAddress(pixelBuffer, CVPixelBufferLockFlags(rawValue: 0))
//UIGraphicsEndImageContext()
}
解决方案
有助于获得所需结果的事情......使用 UIImageJPEGRepresentation 而不是 PNG,尺寸必须是 16 的倍数...... :) 并且较新的 iphone 可以处理更多图像
推荐阅读
- python - 安装python包在mac上不起作用
- haskell - 如何在多个条件下使用地图
- java - 不打印蓝牙连接的设备 (Android)
- azure - 尝试调用包装在 Docker 容器中的 Azure 函数时出现内部服务器错误 (500)
- c - 有人可以告诉我为什么我的chain1 在我第二次使用它时突然打印 99 吗?:)
- amazon-web-services - 1小时超时的无服务器python?
- c - makefile 遇到问题:它的行为不像我被教导的那样,我不知道该怎么做
- python-3.x - For x in Arra 给我 None 在 Array 的末尾
- python - 使用python计算softmax激活函数
- xamarin - Xamarin 形成错误?