gpt4 book ai didi

swift - VideoComposition 不遵守指示

转载 作者:行者123 更新时间:2023-11-30 10:35:47 25 4
gpt4 key购买 nike

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

最佳答案

苹果公司表示存在一个错误,影响了一些合成指令。此问题已在 iOS 13.1 中修复。我更新并运行了该函数,淡入淡出效果与 iOS 13 更新之前一样。

关于swift - VideoComposition 不遵守指示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58066843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com