【问题标题】:VideoComposition not honoring instructionsVideoComposition 不遵守说明
【发布时间】:2019-09-23 16:45:13
【问题描述】:

自从更新到 iOS 13 后,我用来淡入淡出视频的视频合成已损坏。这是我的代码,在安装 iOS 13 之前可以正常工作。

现在,当我导出视频时,有声音,只是黑屏。

let urlAsset = AVURLAsset(url: inputURL, options: nil)      
guard let exportSession = AVAssetExportSession(asset: urlAsset, presetName: AVAssetExportPresetHighestQuality) else { handler(nil)
     return
}
exportSession.outputURL = outputURL
exportSession.outputFileType = AVFileType.m4v
exportSession.shouldOptimizeForNetworkUse = true

let composition = AVMutableVideoComposition(propertiesOf: urlAsset)

let clipVideoTrack = urlAsset.tracks(withMediaType: AVMediaType.video)[0]

let timeDuration = CMTimeMake(value: 1, timescale: 1)

let layer = AVMutableVideoCompositionLayerInstruction(assetTrack: clipVideoTrack)

// MARK: Fade in effect
layer.setOpacityRamp(fromStartOpacity: 0.0, toEndOpacity: 1.0, timeRange: CMTimeRange(start: CMTime.zero, duration: timeDuration))

// MARK: Fade out effect
let startTime = CMTimeSubtract(urlAsset.duration, CMTimeMake(value: 1, timescale: 1))

layer.setOpacityRamp(
       fromStartOpacity: 1.0,
       toEndOpacity: 0.0,
       timeRange: CMTimeRangeMake(start: startTime, duration: timeDuration)
)

let instruction = AVMutableVideoCompositionInstruction()
instruction.layerInstructions = [layer]
instruction.timeRange = CMTimeRange(start: CMTime.zero, duration: urlAsset.duration)


composition.instructions = [instruction]

exportSession.videoComposition = composition

exportSession.exportAsynchronously { () -> Void in
       handler(exportSession)
       print("composition has completed")
}

【问题讨论】:

  • 所以通过苹果开发者论坛我读到有一个影响 setTransformRamp 的错误,所以我假设它也会影响 setOpacityRamp。它应该在 2019 年 9 月 30 日发布的 iOS 13.1 中得到修复。

标签: swift avvideocomposition


【解决方案1】:

Apple 表示存在影响某些合成指令的错误。这已在 iOS 13.1 中修复。我更新并运行了该功能,并且淡入和淡出功能与 iOS 13 更新之前一样。

【讨论】:

  • 这仍然对您有用吗?我无法获得在 13.3.1 上可靠工作的不透明指令...
  • iOS 13.4 对你们有用吗?我的不透明度斜坡指令被完全忽略了。 @DanHalliday
  • @Matthew 可以分享一下源码吗?
  • 我最终意识到 AVComposition 播放在模拟器中非常有问题。我(像往常一样)有一个复杂的错误,导致它在设备上失败,但一旦我修复它,我意识到这是一个模拟器问题。
猜你喜欢
  • 1970-01-01
  • 2016-08-29
  • 2023-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-02
  • 2013-06-09
  • 2014-12-05
相关资源
最近更新 更多