gpt4 book ai didi

ios - 设置 AVMutableVideoComposition 指令导致处理程序不被调用

转载 作者:搜寻专家 更新时间:2023-10-31 08:30:16 26 4
gpt4 key购买 nike

我有一个过滤 AVPlayerItem Assets 的功能。问题之一是设置视频的转换。但是,每当我设置 AVMutableVideoCompositionAVMutableVideoCompositionInstruction 时,处理程序就不再被调用。

这是我的代码:

private func filter(playerItem: AVPlayerItem) {

let videoComposition = AVMutableVideoComposition(asset: playerItem.asset, applyingCIFiltersWithHandler: { (request) in
print("Composing") // does not print whenever the instructions are added
if let filteredImage = filterImage(request.sourceImage) {
request.finish(with: filteredImage, context: nil)
} else {
request.finish(with: RenderError.couldNotFilter) // An error
}
})

guard let videoTrack = playerItem.asset.tracks(withMediaType: .video).first else { return }

let size = CGSize(width: videoTrack.naturalSize.height, height: videoTrack.naturalSize.width)
videoComposition.renderSize = size

let videoInstruction = AVMutableVideoCompositionInstruction()
videoInstruction.timeRange = CMTimeRange(start: kCMTimeZero, duration: playerItem.asset.duration)

let transformInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: videoTrack)
let translate = CGAffineTransform(translationX: size.width, y: size.height)
let rotate = CGAffineTransform(rotationAngle: CGFloat.pi)
transformInstruction.setTransform(translate.concatenating(rotate), at: kCMTimeZero)
videoInstruction.layerInstructions.append(transformInstruction)
videoComposition.instructions.append(videoInstruction)

playerItem.videoComposition = videoComposition
}

为什么不再调用处理程序,我该如何解决?

如果你能回答我就给你这么多加分!

最佳答案

我向 Apple 提交了错误报告,显然这种行为不是错误。这是他们的回应:

Engineering has provided the following information regarding this issue:

CoreImage filtering and layer instruction based composition can't be used simultaneously. Layer instructions won't be run when added to an AVMutableVideoComposition that it is initialized with +[videoCompositionWithAsset:applyingCIFiltersWithHandler:]. To use layer instructions in this case, move the functionality into the handler instead of adding the layer instructions to the AVMutableVideoComposition.

这解释了为什么指令似乎没有做任何事情,并且没有调用处理程序。他们说将转换功能移至处理程序而不是使用指令;不幸的是,我不太清楚如何实现这个解决方案——那是另一个问题。

关于ios - 设置 AVMutableVideoComposition 指令导致处理程序不被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45090477/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com