1

Can anyone help me out to fix this issue, gave error while compressing video like :

NSLocalizedFailureReason=An unknown error occurred (-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")
        }
    }
Sarabjit Singh
  • 1,814
  • 1
  • 17
  • 28
Bucket
  • 449
  • 3
  • 20

1 Answers1

2

use this way:

replace

let destinationPath =  NSURL(string: VideoFilePath)!     

with

let destinationPath =  NSURL(fileURLPath: VideoFilePath)!     
Rahul Patel
  • 1,822
  • 12
  • 21