2017-02-22 12 views
0

私は迅速に新しいです。私は、ビデオファイルからオーディオを削除し、URL経由で再生する必要があります。私はこれらを通過しましたlink1 & link2 ...私は迅速にそれらを変換しようとしたときに多くのエラーがあった。 ご協力いただければ幸いです。Swift - ビデオからオーディオを削除する

+0

あなたのリンク2からの迅速な使用にそのヘルプ変換Objective-Cのコードswiftifyと呼ばれるツールは、それがあるそのコードを取りますそして、そのコードが何をしているのか理解しよう。 –

+0

ありがとう...しかし、私は迅速にしようとしたと理解していない(多くのエラー) –

+0

誰かがSwift 3にコードを変換しました。あなたはそれをチェックアウトする必要があります。 – HDT

答えて

0

私はこれが私のために働いていた、このコード&を書いたthis linkの助けを借りて...

var mutableVideoURL = NSURL() //final video url 
func removeAudioFromVideo(_ videoURL: URL) { 
     let inputVideoURL: URL = videoURL 
     let sourceAsset = AVURLAsset(url: inputVideoURL) 
     let sourceVideoTrack: AVAssetTrack? = sourceAsset.tracks(withMediaType: AVMediaTypeVideo)[0] 
     let composition : AVMutableComposition = AVMutableComposition() 
     let compositionVideoTrack: AVMutableCompositionTrack? = composition.addMutableTrack(withMediaType: AVMediaTypeVideo, preferredTrackID: kCMPersistentTrackID_Invalid) 
     let x: CMTimeRange = CMTimeRangeMake(kCMTimeZero, sourceAsset.duration) 
     _ = try? compositionVideoTrack!.insertTimeRange(x, of: sourceVideoTrack!, at: kCMTimeZero) 
     mutableVideoURL = NSURL(fileURLWithPath: NSHomeDirectory() + "/Documents/FinalVideo.mp4") 
     let exporter: AVAssetExportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetHighestQuality)! 
     exporter.outputFileType = AVFileTypeMPEG4 
     exporter.outputURL = mutableVideoURL as URL 
     removeFileAtURLIfExists(url: mutableVideoURL) 
     exporter.exportAsynchronously(completionHandler: 
      { 
       switch exporter.status 
       { 
        case AVAssetExportSessionStatus.failed: 
         print("failed \(exporter.error)") 
        case AVAssetExportSessionStatus.cancelled: 
         print("cancelled \(exporter.error)") 
        case AVAssetExportSessionStatus.unknown: 
         print("unknown\(exporter.error)") 
        case AVAssetExportSessionStatus.waiting: 
         print("waiting\(exporter.error)") 
        case AVAssetExportSessionStatus.exporting: 
         print("exporting\(exporter.error)") 
        default: 
         print("-----Mutable video exportation complete.") 
       } 
      }) 
    } 

    func removeFileAtURLIfExists(url: NSURL) { 
     if let filePath = url.path { 
      let fileManager = FileManager.default 
      if fileManager.fileExists(atPath: filePath) { 
       do{ 
        try fileManager.removeItem(atPath: filePath) 
       } catch let error as NSError { 
        print("Couldn't remove existing destination file: \(error)") 
       } 
      } 
     } 
    } 
関連する問題