Hi all. I've only been learning Swift a few weeks. I did all the fundamentals tutorials I could find, and now I'm at the point of sort of monkey-see/monkey-do following the examples of others until I figure out how to accomplish what I'm trying to do. Please bear with my ignorance.
I'm building a very simple audio file conversion front-end for ffmpeg for MacOS. Followingthis example, I was able to get ffmpeg working in my app mostly through trial, error, and sheer dumb luck.
Now I need to do something similar with ffprobe, but I don't need it to actually convert a file and create a new one. I just need it to return data on the input file's duration, so that I can do a little math and trim off the last few seconds of the file when it's of indeterminate length, and insert that trim command into my ffmpeg arguments, like so:
func insertTrimArguments() {
conversionSelection()
if trimInOutClipsCheckbox.state == .on {
ffmpegArguments.insert(contentsOf: ["-ss", "00:00:02.000", /*"-t", "duration minus 4.2secs"*/], at: 3)
}
else {
}
}
Imitating the function to launch ffmpeg, I've got this, which uses the command for ffprobe to return a file's duration as the arguments:
// get file duration and subtract 4.2 seconds if "trim in/out clips is enabled, then insert additional arguments into conversionSelection arrays
func getFileDuration() {
guard let probePath = Bundle.main.path(forResource: "ffprobe", ofType: "") else { return }
do {
let probeTask: Process = Process()
probeTask.launchPath = probePath
probeTask.arguments = [
"-v", "error",
"-show_entries",
"format=duration", "-of",
"compact=p=0:nk=1",
"\(inputFilePath)"]
probeTask.standardInput = FileHandle.nullDevice
probeTask.launch()
probeTask.waitUntilExit()
}
}
But because I'm just imitating what I've seen and don't really understand how processes WORK, I'm sort of stuck at this point and don't know where to take it from here to get the information I need.
Where do I go from this point to accomplish this?