zoukankan      html  css  js  c++  java
  • 导出相册视频-> 本地沙盒

    慢动作视频, 特殊处理 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")
    
                    }
                })
            }) }
  • 相关阅读:
    360云盘、百度云、微云……为什么不出 OS X(Mac 端)应用呢?(用户少,开发成本高)(百度网盘Mac版2016.10.18横空出世)
    其实 Dropbox 的缺点也很明显,速度慢,空间小(我对国内的网盘的建议)
    为什么百度云、360云盘等都取消了同步盘功能?
    验证API
    操作系统进程压榨案例
    查询功能
    JavaScript 动画库和开发框架
    指针
    Attribute Routing
    自定义验证特性
  • 原文地址:https://www.cnblogs.com/daxueshan/p/12808761.html
Copyright © 2011-2022 走看看