+-
如何使用swift从Xcode coco app运行像FFMPEG这样的终端程序?

我正在使用swift制作一个Xcode应用程序。我试图在有人点击按钮时运行FFMPEG。在终端,它看起来像

ffmpeg -i input.mp4 output.mp4

但在搜索到处后,我似乎无法找到如何运行命令,就好像你在终端输入命令一样。

所以我的问题是,你如何运行命令(可能来自文本字段)就像你在终端输入一样?

到目前为止,这是我的代码:

import Foundation
import Cocoa
class ViewController: NSViewController {
@IBOutlet weak var inURL: NSTextField!
@IBOutlet weak var inText: NSTextField!

override func viewDidLoad() {
    super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    override var representedObject: Any? {
        didSet {
            // Update the view, if already loaded.
        }
    }
    @IBAction func clickURL(_ sender: Any) {
        var musicURL = inURL.stringValue
        if musicURL.isEmpty {
            musicURL = "No URL entered!"
        }
        let textReplace = "Downloading music from: \(musicURL)..."
        inText.stringValue = textReplace
        Process.launchedProcess(launchPath: "/usr/local/Cellar/ffmpeg/4.0.2/bin/ffmpeg", arguments: ["-i","input.mp4","output.mp4"])
    }
}

我也将使用来自GitHub的youtube-dl,如果我能让FFMPEG工作的话。

0
投票
var p = Process.launchedProcess(launchPath: "/a/path/to/ffmpeg", arguments: ["-i", "input.mp4", "output.mp4"])