【发布时间】:2018-10-12 14:28:37
【问题描述】:
我正在以这种方式使用 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,如果输入资产的视频轨道包含指定旋转 90 度的 preferredTransform,则输出不正确。如何将视频合成与正确处理视频轨道的首选变换的 Core Image 过滤器一起使用?
编辑:这个问题看起来很相似,但与其他涉及播放的问题不同。就我而言,播放效果很好,但渲染会产生失真的视频。
【问题讨论】:
-
问题是播放没有问题。输出在渲染中失真。我会在那个答案中尝试建议。
标签: ios avfoundation avassetexportsession avvideocomposition