2015-07-01 3 views
0

Я преобразовал this код Swift язык, но я получаю этувидео Обрезка Сбой блока AVAssetExportSessionStatus.Failed

Error: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x174278600 {NSUnderlyingError=0x170241d10 "The operation couldn’t be completed. (OSStatus error -12780.)", NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed} in (case AVAssetExportSessionStatus.Failed).

Пожалуйста, помогите мне решили эту

func cropVideo(sourceURL: NSURL) 
    { 
     let asset = AVURLAsset(URL: sourceURL, options: nil) 

     let exportSession = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetHighestQuality) 
       var error : NSError? 
    let file = "Finaloutput.mp4" 
    /* let paths : AnyObject = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask,true)[0] 
     let outputURL1 = paths[0] as? String*/ 
     let nsDocumentDirectory = NSSearchPathDirectory.DocumentDirectory 
     let nsUserDomainMask = NSSearchPathDomainMask.UserDomainMask 
     let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true) 

     let outputURL1 = paths[0] as? String 

     let filemgr = NSFileManager.defaultManager() 
     filemgr.createDirectoryAtPath(outputURL1!, withIntermediateDirectories: true, attributes: nil, error: &error) 
     var outputURL = outputURL1!.stringByAppendingPathComponent(file) 
     filemgr.removeItemAtPath(outputURL, error: &error) 

     let FinalUrlTosave = NSURL(string: outputURL) 
     exportSession.outputURL=FinalUrlTosave 
     exportSession.shouldOptimizeForNetworkUse = true 
     // exportSession.outputFileType = AVFileTypeQuickTimeMovie 
     exportSession.outputFileType = AVFileTypeQuickTimeMovie; 
     let start:CMTime 
     let duration:CMTime 
     start = CMTimeMakeWithSeconds(1.0, 600) 
     duration = CMTimeMakeWithSeconds(19.0, 600) 
     // let timeRangeForCurrentSlice = CMTimeRangeMake(start, duration) 
     let range = CMTimeRangeMake(start, duration); 
     exportSession.timeRange = range 

     let destinationURL1 = NSURL(string: outputURL) 

     exportSession.exportAsynchronouslyWithCompletionHandler({ 
      switch exportSession.status{ 
      case AVAssetExportSessionStatus.Failed: 

       println("failed \(exportSession.error)") 
      case AVAssetExportSessionStatus.Cancelled: 
       println("cancelled \(exportSession.error)") 
      default: 
       println("complete....complete") 
       self.SaveVideoToPhotoLibrary(destinationURL1!) 

      } 
     }) 
    } 

func SaveVideoToPhotoLibrary(outputFileURL: NSURL) 

    { 


     assetsLibrary = ALAssetsLibrary() 

     let videoURL = outputFileURL as NSURL? 

     if let library = assetsLibrary{ 

      if let url = videoURL{ 

       library.writeVideoAtPathToSavedPhotosAlbum(url, 
        completionBlock: {(url: NSURL!, error: NSError!) in 

         print(url) 

         if let theError = error{ 
          print("Error happened while saving the video") 
          print("The error is = \(theError)") 
         } else { 
          print("no errors happened") 
         } 

       }) 
      } else { 
       print("Could not find the video in the app bundle") 
      } 

     } 


    } 

ответ

1

Найдено Я изменил эту линию, и она работает для меня

let FinalUrlTosave = NSURL(fileURLWithPath: outputURL) 

вместо

let FinalUrlTosave = NSURL(string: outputURL) 

я не получаю точный путь.