资产编写器时间倒退并在 gpu 图像 swift 中获得零输出

问题描述

因此,我正在尝试使用 GPU 图像 2 创建视频,并且在电影输出中资产编写器向后移动的时间和几帧后,我收到此警告。大多数情况下,当我应用图像混合过滤器或视频混合过滤器时,它会发生。

WARNING: Trouble appending pixel buffer at time: CMTime(value: 80,timescale: 600,flags: __C.CMTimeFlags(rawValue: 1),epoch: 0) Optional(Error Domain=AVFoundationErrorDomain Code=-11800 "The operation Could not be completed" UserInfo={NSLocalizedFailureReason=An unkNown error occurred (-16364),NSLocalizedDescription=The operation Could not be completed,NSUnderlyingError=0x2828f7ed0 {Error Domain=NSOsstatusErrorDomain Code=-16364 "(null)"}})

请帮忙解决这个问题, 我还遇到了 this answer 这可能与我的问题有关

解决方法

在图像混合或视频混合中,GPU 图像需要多一点时间来计算帧缓冲区的正确时间温度,因此您必须在 movieoutput.init() 函数和 startrecording() 之间手动创建延迟

通过使用

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
// your code here
}