【问题标题】:Equal-Power Crossfade in AVMutableVideoCompositionLayerInstructionAVMutableVideoCompositionLayerInstruction 中的等功率淡入淡出
【发布时间】:2020-07-01 16:39:29
【问题描述】:

如何在AVVideoComposition 中实现等功率交叉淡入淡出?我正在使用类似以下的方法在视频轨道之间淡入淡出,但是当一遍又一遍地循环播放相同的视频时,由于setOpacityRamp 内部使用了任何曲线,因此在过渡期间会出现非常明显的亮度下降。

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]

【问题讨论】:

    标签: ios swift avvideocomposition avcomposition


    【解决方案1】:

    这是不可能的。 AVMutableVideoCompositionLayerInstructionsetOpacityRamp 方法列出了以下描述:

    在不透明度渐变期间,使用线性插值计算不透明度。

    不过,我在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]
    

    【讨论】:

      猜你喜欢
      • 2012-04-27
      • 2012-07-11
      • 1970-01-01
      • 2019-09-08
      • 2011-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多