0

自从更新到 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")
}
4

1 回答 1

0

Apple 表示存在一个错误,该错误会影响某些作曲说明。这已在 iOS 13.1 中修复。我更新并运行了该功能,淡入和淡出就像在 iOS 13 更新之前一样工作。

于 2019-09-25T01:24:11.090 回答