AVPlayer playback fails while AVAssetExportSession is active as of iOS 10

后端 未结 2 1204
野的像风
野的像风 2020-12-05 05:56

AVPlayer will randomly just play audio, not showing the video track...

Playing video correctly with AVPlayer while having an active compres

2条回答
  •  [愿得一人]
    2020-12-05 06:22

    I found a solution to my problem. Like Sami said, the issue appears to be in AVVideoCompositionCoreAnimationTool which I was using to watermark my video. I shifted to using a CIFilter, which actually had cleaner code anyway.

    I removed everything with CoreAnimationTool and used this (mixComposition is my AVMutableComposition):

    let watermarkFilter = CIFilter(name: "CISourceOverCompositing")!
    let watermarkImage = CIImage(image: #imageLiteral(resourceName: "watermark"))!
    let videoComposition = AVVideoComposition(asset: mixComposition) { (filteringRequest) in
        let source = filteringRequest.sourceImage.clampingToExtent()
        watermarkFilter.setValue(source, forKey: "inputBackgroundImage")
        let transform = CGAffineTransform(translationX: filteringRequest.sourceImage.extent.width - watermarkImage.extent.width - 2, y: 0)
        watermarkFilter.setValue(watermarkImage.applying(transform), forKey: "inputImage")
        filteringRequest.finish(with: watermarkFilter.outputImage!, context: nil)
    }
    

    and then in the AVAssetExportSession added this:

    exporter!.videoComposition = videoComposition
    

    Hope that helps somebody!

提交回复
热议问题