I have two phones running different iOS, one with iOS 12.4.1 and one with iOS 13. I have a AVMutableVideoComposition that adds fade in and out on a video. This function has always works and still currntly works on 12.4.1 but with iOS 13 it just creates a black video with sound.
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 = CMTimeRangeMake(start: CMTime.zero, duration: urlAsset.duration)
composition.instructions = [instruction]
exportSession.videoComposition = composition
exportSession.exportAsynchronously { () -> Void in
handler(exportSession)
print("compress video has completed")
}