• 导出相册视频-> 本地沙盒


    慢动作视频, 特殊处理 https://www.jianshu.com/p/bbae60b21422

              https://www.jianshu.com/p/4ec00b289885 

    1, exportSession

    let option = PHVideoRequestOptions()
                    option.isNetworkAccessAllowed = true
                    option.deliveryMode = .highQualityFormat
                    PHCachingImageManager.default().requestExportSession(forVideo: asset, options: option, exportPreset: AVAssetExportPresetHighestQuality) { (exportSession, info) in
                        guard let exportSession = exportSession else {
                            single(.error(KimPhotoHelperError.sourceNotFound))
                            return
                        }
                        exportSession.outputURL = videoPath
                        exportSession.outputFileType = .mp4
                        exportSession.exportAsynchronously {
                            switch exportSession.status {
                            case .completed:
                                single(.success((videoPath.relativePath, size)))
                            case .failed:
                                print(exportSession.error)
                                single(.error(KimPhotoHelperError.sourceNotFound))
                            default:
                                break
                            }
                        }
                    }

    2,  PHAssetResourceManager

    let resourceManager = PHAssetResourceManager.default()
                    let option = PHAssetResourceRequestOptions()
                    option.isNetworkAccessAllowed = true
                    resourceManager.writeData(for: assetRescource, toFile: videoPath, options: option) { (error) in
                        guard let error = error else {
                            //single(.error(e))
                            exportSession(asset)
                            return
                        }
                        single(.success((videoPath.relativePath, size)))
                    }

     3,  先 requestDatqa -> 再 writeData

    let resourceManager = PHAssetResourceManager.default()
                      let option = PHAssetResourceRequestOptions()
                      option.isNetworkAccessAllowed = true
                      var videoData = Data()
                      resourceManager.requestData(for: assetRescource, options: option, dataReceivedHandler: { (data) in
                          videoData.append(data)
                      }) { (error) in
                          if let error = error {
                              print(error)
                              exportSession(asset)
      //                        single(.error(KimPhotoHelperError.sourceNotFound))
                          } else {
                              do {
                                  try videoData.write(to: videoPath)
                              } catch {
                                  
                              }
                              single(.success((videoPath.relativePath, size)))
                          }
                          
                      }

    4, 导出慢动作视频 AVCompostion 类型

    func ConvertAvcompositionToAvasset(avComp: AVComposition, completion:@escaping (_ avasset: AVAsset) -> Void){
            let exporter = AVAssetExportSession(asset: avComp, presetName: AVAssetExportPresetHighestQuality)
            let randNum:Int = Int(arc4random())
            //Generating Export Path
            let exportPath: NSString = NSTemporaryDirectory().appendingFormat("(randNum)"+"video.mov") as NSString
            let exportUrl: NSURL = NSURL.fileURL(withPath: exportPath as String) as NSURL
            //SettingUp Export Path as URL
            exporter?.outputURL = exportUrl as URL
            exporter?.outputFileType = AVFileTypeQuickTimeMovie
            exporter?.shouldOptimizeForNetworkUse = true
            exporter?.exportAsynchronously(completionHandler: {() -> Void in
                DispatchQueue.main.async(execute: {() -> Void in
                    if exporter?.status == .completed {
                        let URL: URL? = exporter?.outputURL
                        let Avasset:AVAsset = AVAsset(url: URL!)
                        completion(Avasset)
                    }
                    else if exporter?.status == .failed{
                        print("Failed")
    
                    }
                })
            }) }
  • 相关阅读:
    所谓的飞扬档案管理软件
    通过实例学习Virtools脚本语言VSL 解析字符串
    SQLite FAQ中文版
    通过实例学习Virtools脚本语言VSL 将物体排列于圆周上
    通过实例学习Virtools脚本语言VSL 解二次方程
    out 和 ref
    ASP.NET MVC深度接触:ASP.NET MVC请求生命周期
    ICSharpCode.SharpZipLib 压缩
    aspnet_regiis.exe 详解
    ASP.NET 配置文件 configSource 的用法
  • 原文地址:https://www.cnblogs.com/daxueshan/p/12808761.html
Copyright © 2020-2023  润新知