如何在没有AVMutableVideoComposition的情况下直接保存AVMutableComposition到相机胶卷/图库/照片-Swift 5

问题描述

我距离完成第一个原始应用程序只有一步之遥,所以我非常渴望得到答案。

我创建了一个包含多个剪辑的AVMutableComposition(不是AVMutableVideoComposition)。我要做的就是将其保存到相机胶卷或相册中。我知道如何做到这一点的唯一方法是使用AVMutable 视频组合,但是在我目前的情况下,由于我构建应用的方式需要很长时间。我也使用了PHPhotoLibrary,但这仅适用于URL视频。 (是否可以将AVMutableComposition转换为URL?)

这是我尝试过的无效的方法

var mixComposition = AVMutableComposition() //trying to save this

  func savetogallery() {
        let savePathUrl: URL = URL(fileURLWithPath: NSHomeDirectory() + "/Documents/newVideo.mp4")
        do { 
            try FileManager.default.removeItem(at: savePathUrl)
        } catch { print(error.localizedDescription) }

        let assetExport: AVAssetExportSession = AVAssetExportSession(asset: mixComposition,presetName: AVAssetExportPresetHighestQuality)!
        assetExport.outputFileType = AVFileType.mp4
        assetExport.outputURL = savePathUrl
        assetExport.shouldOptimizeforNetworkUse = true

        assetExport.exportAsynchronously { () -> Void in
            switch assetExport.status {
            case AVAssetExportSessionStatus.completed:
                print("successfully saved")  // but it still prints this 
                
            case AVAssetExportSessionStatus.Failed:
                print("Failed")
                
            case AVAssetExportSessionStatus.cancelled:
                print("cancelled")
                
            default:
                print("complete")
                
            }
        }
    }

  @IBAction func SaveButtonDidTouch(_ sender: Any) {

        savetogallery() //??
        
    }

即使我的图库/相机胶卷未添加任何内容,它仍会打印“成功保存”。

那么保存AVMutableComposition的最有效方法是什么?我在哪里错了?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)