0
私は迅速に新しいです。私は、ビデオファイルからオーディオを削除し、URL経由で再生する必要があります。私はこれらを通過しましたlink1 & link2 ...私は迅速にそれらを変換しようとしたときに多くのエラーがあった。 ご協力いただければ幸いです。Swift - ビデオからオーディオを削除する
私は迅速に新しいです。私は、ビデオファイルからオーディオを削除し、URL経由で再生する必要があります。私はこれらを通過しましたlink1 & link2 ...私は迅速にそれらを変換しようとしたときに多くのエラーがあった。 ご協力いただければ幸いです。Swift - ビデオからオーディオを削除する
私はこれが私のために働いていた、このコード&を書いた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)")
}
}
}
}
あなたのリンク2からの迅速な使用にそのヘルプ変換Objective-Cのコードswiftifyと呼ばれるツールは、それがあるそのコードを取りますそして、そのコードが何をしているのか理解しよう。 –
ありがとう...しかし、私は迅速にしようとしたと理解していない(多くのエラー) –
誰かがSwift 3にコードを変換しました。あなたはそれをチェックアウトする必要があります。 – HDT