Swift 不遵守指示的录像作品

Swift 不遵守指示的录像作品,swift,avvideocomposition,Swift,Avvideocomposition,由于更新到iOS 13,我用来淡入淡出视频的视频合成被破坏。这是我的代码,在安装iOS 13之前一直正常工作 现在,当我导出视频时,有声音,只有一个黑屏 let urlAsset = AVURLAsset(url: inputURL, options: nil) guard let exportSession = AVAssetExportSession(asset: urlAsset, presetName: AVAssetExportPresetHighestQuality) e

由于更新到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")
}

苹果表示,有一个bug影响了一些构图说明。这在iOS 13.1中已修复。我更新并运行了该功能,淡入淡出与iOS 13更新之前一样有效。

因此,通过apple开发者论坛,我了解到有一个bug影响setTransformRamp,因此我假设它也影响setOpacityRamp。它应该在2019年9月30日发布的iOS 13.1中修复。这对您仍然有效吗?我无法在13.3.1上获得可靠的不透明度指令…它是否适用于iOS 13.4?我的指示完全被忽略了@DanHalliday@Matthew你能分享一下源代码吗?我最终意识到AVComposition回放在模拟器中是非常有缺陷的。我(像往常一样)有一个复合错误,使它在设备上失败,但一旦我修复了它,我意识到这是一个模拟器问题。