VideoComposition не соблюдает инструкции - PullRequest
0 голосов
/ 23 сентября 2019

С момента обновления до 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")
}

1 Ответ

0 голосов
/ 25 сентября 2019

Apple сказала, что была ошибка, влияющая на некоторые инструкции для композиций.Это было исправлено в iOS 13.1.Я обновил и запустил функцию, и постепенное увеличение и уменьшение работали так, как это было до обновления iOS 13.

...