2016-04-23 50 views
1

我有一個錯誤和問題。我想將修改後的視頻導出到相機膠捲,但導出的視頻與相機膠捲不兼容。AVAssetExportSession - 導出的視頻不兼容相機膠捲

我也想刪除最初錄製的視頻,這樣我可以多次錄製,但它會產生一個錯誤,並且沒有意義。如果我取消註釋代碼,將會有錯誤告訴我最終路徑不存在。我假設這會刪除導出修改版本之前的初始影片。但我不明白爲什麼會發生這種情況,因爲刪除代碼在下面的導出代碼。

下面的代碼:

// Create Date Formatter 
    let dateFormatter = NSDateFormatter() 
    dateFormatter.dateFormat = "yyyy-MM-dd-hh-mm-ss" 

    // Create Export Session 
    let exportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetHighestQuality) 
    exportSession?.videoComposition = videoComposition 
    do { 
     try exportSession?.outputURL = NSFileManager.defaultManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true).URLByAppendingPathComponent(dateFormatter.stringFromDate(NSDate())).URLByAppendingPathExtension("mov") 
    } 
    catch { 
     print(error) 
    } 
    exportSession?.outputFileType = AVFileTypeQuickTimeMovie 
    exportSession?.exportAsynchronouslyWithCompletionHandler({ 
     print("Output File Type: \(exportSession?.outputFileType)") 
     print("Output URL: \(exportSession?.outputURL?.absoluteString)") 
     print("Video Compatible W/ Camera Roll: \(exportSession?.asset.compatibleWithSavedPhotosAlbum)") 
     //-----SAVE----- 
     if exportSession?.status == AVAssetExportSessionStatus.Completed 
      { 
      print("Export Finished") 
      if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum((exportSession?.outputURL?.absoluteString)!) //Returns false... 
      { 
       UISaveVideoAtPathToSavedPhotosAlbum((exportSession?.outputURL?.absoluteString)!, self, nil, nil) 
       print("Video Saved") 
       // Show Message 
       self.showMessage() 
      } 
      else 
      { 
       print("Video Not Saved") 
      } 
     } 
     else if exportSession?.status == AVAssetExportSessionStatus.Failed 
     { 
      print("Export Error: \(exportSession?.error)") 
      print("Export Failed") 
     } 
     else 
     { 
      print("Export Cancelled") 
     } 
    }) 

    // The code below generates an error 
    // Remove Temporary Video 
//  do 
//  { 
//   try NSFileManager.defaultManager().removeItemAtURL(initialOutputURL) 
//  } 
//  catch 
//  { 
//   print(error) 
//  } 

那麼,是不兼容的?我想指出日誌顯示QuickTime格式和720x720分辨率。

回答

0

好吧,所以我最終找到了答案......這也沒有多大意義。也許它會幫助其他人遇到這個問題。

所以刪除初始視頻的代碼必須放置在裏面exportAsynchronouslyWithCompletionHandler而不是之後。

保存我剛剛使用的視頻ALAssetLibrary,.videoAtPathIsCompatibleWithSavedPhotosAlbum.writeVideoAtPathToSavedPhotosAlbum。我知道它已被棄用,但我也希望與iOS 7兼容。如果您想從iOS 8開始使用,請使用PHPhotoLibrary。這很奇怪,因爲我的初始代碼和ALAssetLibrary版本完全相同。另外,有趣的是日誌仍然顯示視頻與相機膠捲不兼容。

最後一個修正是在旋轉視頻時使用CGFloat(M_PI_2)而不是90

相關問題