2017-09-15 10 views
0

AVAssetExportでアセットをエクスポートしようとすると、おそらくwhatsappから受信したビデオに次のエラーが表示されます。 解決策を見つけることができませんでした。また、ビデオの長さを修正するコードを実装しようとしましたが、修正しませんでした。エラードメイン= NSOSStatusErrorDomainコード= -12780 \ "(ヌル)\" ここエラードメイン= NSOSStatusErrorDomainコード= -12780 "(null)"

コードここ

PHCachingImageManager().requestAVAsset(forVideo: asset.phAsset!, options: nil, resultHandler: { (AVAssetRecivied, audioMix, info) in 
       let AVAssetMy = AVAssetRecivied!.normalizingMediaDuration() 
       let exportSession : AVAssetExportSession? 
       if (AVAssetMy as? AVURLAsset) != nil { 
       exportSession = AVAssetExportSession(asset: (AVAssetMy as? AVURLAsset)!, presetName: AVAssetExportPresetMediumQuality) 
       } 
       else { 
       exportSession = AVAssetExportSession(asset: (AVAssetMy as? AVComposition)!, presetName: AVAssetExportPresetMediumQuality) 
       } 
       exportSession?.outputURL = URL(fileURLWithPath: NSTemporaryDirectory() + NSUUID().uuidString + ".m4v") 
       exportSession?.outputFileType = AVFileTypeQuickTimeMovie 
       exportSession?.audioMix = audioMix 
       exportSession?.shouldOptimizeForNetworkUse = true 
       exportSession?.exportAsynchronously {() -> Void in 
        if exportSession?.status == .completed { 
        self.getFileSize(url: exportSession!.outputURL!) 
        if self.myMediaArray == nil { 
         self.myMediaArray = [["Video" : AVAsset(url: exportSession!.outputURL!)]] 
         DispatchQueue.main.async { 
          self.collectionViewImage.reloadData() 
         } 
        } else { 
         self.myMediaArray?.append(["Video" : AVAsset(url: exportSession!.outputURL!)]) 
         DispatchQueue.main.async { 
          self.collectionViewImage.reloadData() 
         } 
        }} 
       } 
      }) 

は、ビデオ

func normalizingMediaDuration() -> AVAsset? { 
    let mixComposition : AVMutableComposition = AVMutableComposition() 
    var mutableCompositionVideoTrack : [AVMutableCompositionTrack] = [] 
    var mutableCompositionAudioTrack : [AVMutableCompositionTrack] = [] 
    let totalVideoCompositionInstruction : AVMutableVideoCompositionInstruction = AVMutableVideoCompositionInstruction() 

    guard let video = tracks(withMediaType: AVMediaTypeVideo).first else { 
     return nil 
    } 

    guard let audio = tracks(withMediaType: AVMediaTypeAudio).first else { 
     return nil 
    } 

    mutableCompositionVideoTrack.append(mixComposition.addMutableTrack(withMediaType: AVMediaTypeVideo, preferredTrackID: kCMPersistentTrackID_Invalid)) 
    mutableCompositionAudioTrack.append(mixComposition.addMutableTrack(withMediaType: AVMediaTypeAudio, preferredTrackID: kCMPersistentTrackID_Invalid)) 

    let duration = video.timeRange.duration.seconds > audio.timeRange.duration.seconds ? audio.timeRange.duration : video.timeRange.duration 

    do{ 
     try mutableCompositionVideoTrack[0].insertTimeRange(CMTimeRangeMake(kCMTimeZero,duration), of: video, at: kCMTimeZero) 
     try mutableCompositionAudioTrack[0].insertTimeRange(CMTimeRangeMake(kCMTimeZero, duration), of: audio, at: kCMTimeZero) 
    }catch{ 
     return nil 
    } 

    totalVideoCompositionInstruction.timeRange = CMTimeRangeMake(kCMTimeZero,duration) 

    return mixComposition 
} 

の継続時間を調整するための方法である: エラーがあります}

ファイル: 1)書き出し可能 2)プリセットとフォーマットは互換性があります 3)エクスポートする前にファイルをドキュメントに移動しようとしました。4)ファイル拡張子を変更しようとしました。

+0

私はちょうどtsi(インシデント)を費やし、私はいくつかの特定のビデオのエクスポートを許可しない方法でバグがあると報告されました。彼らは選択肢を歓迎する! – darkbit

答えて

0

同じ問題が発生し、同じエラーコード-12780が発生しました。 私のためにそれを修正したのは、 exportSession?outputURLにNSURL変数を送信し、URLとして入力することです。 なぜそれが機能しているのか分かりません。

関連する問題