我使用CIFilters以这种方式创建一个AVVideoComposition:
videoComposition = AVMutableVideoComposition(asset: asset, applyingCIFiltersWithHandler: {[weak self] request in
// Clamp to avoid blurring transparent pixels at the image edges
let source = request.sourceImage.clampedToExtent()
let output:CIImage
if let filteredOutput = self?.runFilters(source, filters: filters)?.cropped(to: request.sourceImage.extent) {
output = filteredOutput
} else {
output = source
}
// Provide the filter output to the composition
request.finish(with: output, context: nil)
}) 然后为了正确地处理旋转,我创建了一个在透视层上设置身份转换的透传指令。
let passThroughInstruction = AVMutableVideoCompositionInstruction()
passThroughInstruction.timeRange = CMTimeRangeMake(start: CMTime.zero, duration: asset.duration)
let passThroughLayer = AVMutableVideoCompositionLayerInstruction(assetTrack: videoTrack)
passThroughLayer.setTransform(CGAffineTransform.identity, at: CMTime.zero)
passThroughInstruction.layerInstructions = [passThroughLayer]
videoComposition.instructions = [passThroughInstruction] 问题是它崩溃了,错误如下:
'*** -[AVCoreImageFilterCustomVideoCompositor startVideoCompositionRequest:] Expecting video composition to contain only AVCoreImageFilterVideoCompositionInstruction' 我的问题是,如果我不指定这个passThroughInstruction,如果输入资源的videotrack包含一个指定旋转90度的preferredTransform,则输出是不正确的。如何通过核心图像滤镜正确处理视频轨道的preferredTransform来使用视频合成?
编辑:问题看起来很相似,但与其他涉及播放的问题不同。在我的例子中,回放是可以的,但是渲染会产生失真的视频。
发布于 2018-10-13 16:15:56
好吧,我找到了真正的问题所在。问题是应用由AVMutableVideoComposition(asset:,applyingCIFiltersWithHandler:)返回的videoComposition函数隐式地创建一个合成指令,该指令在通过preferredTransform在视频轨道上应用旋转变换的情况下物理地旋转CIImages。它是否应该这样做是有争议的,因为preferredTransform是在播放器级别应用的。作为一种解决方法,除了this answer中建议的内容之外。我必须调整通过AVVideoWidthKey传递的宽度和高度,videoSettings中的AVVideoHeightKey传递给AVAssetReader/Writer。
https://stackoverflow.com/questions/52781691
复制相似问题