我无法让它发挥作用。结果我几乎有一部空电影。如果我用GPUImagePixellateFilter替换GPUImageAlphaBlendFilter,视频就可以正常呈现。
func convertVideo(source: URL, destination: URL, encodingPreferenses: VideoEncodingParams = .profileMedium,
overlayImage: UIImage?, completion: @escaping ExportAsyncBlock = { _, _ in }) {
let movieFile = GPUImageMovie(url: source)
movieFile?.runBenchmark = true
let alphaFilter = GPUImageAlphaBlendFilter()
alphaFilter.mix = 1.0
let markerInput = GPUImagePicture(image: ImageUtils.sharedUtils.resizeImage(overlayImage!, newSize: encodingPreferenses.videoSize, scaleFactor: 1.0))
movieFile?.addTarget(alphaFilter)
markerInput?.addTarget(alphaFilter)
let movieWriter = GPUImageMovieWriter(movieURL: destination, size: encodingPreferenses.videoSize)
alphaFilter.addTarget(movieWriter)
movieWriter?.shouldPassthroughAudio = true
movieFile?.audioEncodingTarget = movieWriter
movieFile?.enableSynchronizedEncoding(using: movieWriter)
movieWriter?.startRecording()
movieFile?.startProcessing()
movieWriter?.completionBlock = {
print("Ahoy")
movieFile?.removeAllTargets()
movieWriter?.finishRecording {
print("Ahoy")
}
}
}
答案 0 :(得分:1)
电影播放/录制过程异常发生。因此,在上述方法完成之前,它将无法完成。
您的markerInput
GPUImagePicture实例是在该方法中分配的,并且在该方法之外没有为其提供强引用。因此,ARC将在退出此方法时取消分配此图片,并将其输入拆分到处理链中。此方法完成后,您的电影录制将会出现乱码。
一个简单的解决方案是在拥有此方法的类中为markerInput
创建一个实例变量,以便它超出方法本身。