【发布时间】: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 中得到修复。