2017-01-31 6 views
1

Может кто-нибудь помочь мне решить эту проблему, дает ошибку при сжатии видео, как:Отказ сжать .mp4 видео из фото галереи

NSLocalizedFailureReason = Произошла неизвестная ошибка (-12780)

let destinationPath = NSURL(string: VideoFilePath)!  
    let sourceAsset = AVURLAsset(url: inputURL as URL, options: nil) 

    let assetExport: AVAssetExportSession = AVAssetExportSession(asset: sourceAsset, presetName: AVAssetExportPresetLowQuality)! 
    assetExport.outputFileType = AVFileTypeQuickTimeMovie 
    assetExport.outputURL = savePathUrl as URL 
    assetExport.exportAsynchronously {() -> Void in 

     switch assetExport.status { 
     case AVAssetExportSessionStatus.completed: 
      DispatchQueue.main.async { 
       do { 
        let videoData = try NSData(contentsOf: savePathUrl as URL, options: NSData.ReadingOptions()) 
        // self.sendVideoMessage(sender: self.appDelegate.xmppStream!, vidoeData: videoData as NSData, senderJID: self.rosterInfo.jid!,duration: assetExport.asset.duration) 

       } catch { 
        print(error) 
       } 
      } 
     case AVAssetExportSessionStatus.failed: 
      print("failed \(assetExport.error)") 
     case AVAssetExportSessionStatus.cancelled: 
      print("cancelled \(assetExport.error)") 
     default: 
      print("Task Done") 
     } 
    } 

ответ

2

использовать этот способ:

заменить

let destinationPath = NSURL(string: VideoFilePath)!  

с

let destinationPath = NSURL(fileURLPath: VideoFilePath)!  

 Смежные вопросы

  • Нет связанных вопросов^_^