AVMutableVideoCompositionLayerInstruction 中的等功率交叉淡入淡出
Equal-Power Crossfade in AVMutableVideoCompositionLayerInstruction
如何在 AVVideoComposition
中获得等功率交叉淡入淡出?我正在使用类似下面的方法在视频轨道之间淡入淡出,但是当一遍又一遍地循环播放相同的视频时,由于 setOpacityRamp
.[= 内部使用的任何曲线,在过渡期间会出现非常明显的亮度下降。 13=]
let videoInstruction = AVMutableVideoCompositionInstruction()
let fromLayerInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: fromCompositionTrack)
fromLayerInstruction.setOpacityRamp(fromStartOpacity: 1, toEndOpacity: 0, timeRange: timeRange)
let toLayerInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: toCompositionTrack)
toLayerInstruction.setOpacityRamp(fromStartOpacity: 0, toEndOpacity: 1, timeRange: timeRange)
videoInstruction.timeRange = timeRange
videoInstruction.layerInstructions = [fromLayerInstruction, toLayerInstruction]
这是不可能的。 AVMutableVideoCompositionLayerInstruction
的 setOpacityRamp
方法列出了以下描述:
During an opacity ramp, opacity is computed using a linear interpolation.
不过,我在 Learning AV Foundation: A Hands-on Guide to Mastering the AV Foundation 书中找到了一个更简单的解决方案 — 淡出当前视频轨道,但不要淡入新视频轨道。这本书将此称为普通 溶解 而不是 交叉溶解。
let videoInstruction = AVMutableVideoCompositionInstruction()
let fromLayerInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: fromCompositionTrack)
fromLayerInstruction.setOpacityRamp(fromStartOpacity: 1, toEndOpacity: 0, timeRange: timeRange)
let toLayerInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: toCompositionTrack)
// toLayerInstruction.setOpacityRamp(fromStartOpacity: 0, toEndOpacity: 1, timeRange: timeRange)
videoInstruction.timeRange = timeRange
videoInstruction.layerInstructions = [fromLayerInstruction, toLayerInstruction]
如何在 AVVideoComposition
中获得等功率交叉淡入淡出?我正在使用类似下面的方法在视频轨道之间淡入淡出,但是当一遍又一遍地循环播放相同的视频时,由于 setOpacityRamp
.[= 内部使用的任何曲线,在过渡期间会出现非常明显的亮度下降。 13=]
let videoInstruction = AVMutableVideoCompositionInstruction()
let fromLayerInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: fromCompositionTrack)
fromLayerInstruction.setOpacityRamp(fromStartOpacity: 1, toEndOpacity: 0, timeRange: timeRange)
let toLayerInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: toCompositionTrack)
toLayerInstruction.setOpacityRamp(fromStartOpacity: 0, toEndOpacity: 1, timeRange: timeRange)
videoInstruction.timeRange = timeRange
videoInstruction.layerInstructions = [fromLayerInstruction, toLayerInstruction]
这是不可能的。 AVMutableVideoCompositionLayerInstruction
的 setOpacityRamp
方法列出了以下描述:
During an opacity ramp, opacity is computed using a linear interpolation.
不过,我在 Learning AV Foundation: A Hands-on Guide to Mastering the AV Foundation 书中找到了一个更简单的解决方案 — 淡出当前视频轨道,但不要淡入新视频轨道。这本书将此称为普通 溶解 而不是 交叉溶解。
let videoInstruction = AVMutableVideoCompositionInstruction()
let fromLayerInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: fromCompositionTrack)
fromLayerInstruction.setOpacityRamp(fromStartOpacity: 1, toEndOpacity: 0, timeRange: timeRange)
let toLayerInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: toCompositionTrack)
// toLayerInstruction.setOpacityRamp(fromStartOpacity: 0, toEndOpacity: 1, timeRange: timeRange)
videoInstruction.timeRange = timeRange
videoInstruction.layerInstructions = [fromLayerInstruction, toLayerInstruction]