Group Group Group Group Group Group Group Group Group

Does anyone here have any experience writing apps that use FFmpeg?

Hi. I’ve only been coding for a few weeks.

I’m trying to write an app that is a very simple front-end for FFmpeg with a very limited scope. Basically, it will be used to convert audiobooks from one format to another, so it doesn’t involve a lot of complicated encoding bells and whistles.

I built ffmpeg into my app using this technique (XCode managed to guide me through updating it for the current version of Swift without actually breaking it) and my app successfully launches ffmpeg. It didn’t seem to be coping well with the arguments being written in a separate method and then calling the array created by that method in the process to launch ffmpeg. So I switched things up to get closer to the code I borrowed from for my app:

func ffmpegConvert() {
	guard let launchPath = Bundle.main.path(forResource: "ffmpeg", ofType: "") else { return }
	do {
		let conversionChoice = conversionOptionsPopup.indexOfSelectedItem
		switch conversionChoice {
			case 1 :
				let convertTask: Process = Process()
				convertTask.launchPath = launchPath
				convertTask.arguments = [
					"-y",
					"-i", "\(inputFilePath)",
					"-c:a", "libmp3lame",
					"-ac", "1",
					"-ar", "22050",
					"-q:a", "9",
					"\(outputFilePath)"
				]
				convertTask.standardInput = FileHandle.nullDevice
				convertTask.launch()
				convertTask.waitUntilExit()
			case 2 :
				let convertTask: Process = Process()
				convertTask.launchPath = launchPath
				convertTask.arguments = [
					"-y",
					"-i", "\(inputFilePath)",
					"-c:a", "libmp3lame",
					"-ac", "2",
					"-ar", "44100",
					"-q:a", "5",
					"\(outputFilePath)"
				]
				convertTask.standardInput = FileHandle.nullDevice
				convertTask.launch()
				convertTask.waitUntilExit()
			case 3 :
				let convertTask: Process = Process()
				convertTask.launchPath = launchPath
				convertTask.arguments = [
					"-y",
					"-i", "\(inputFilePath)",
					"-c:a", "libmp3lame",
					"-ac", "1",
					"-ar", "22050",
					"-b:a", "32k",
					"\(outputFilePath)"
				]
				convertTask.standardInput = FileHandle.nullDevice
				convertTask.launch()
				convertTask.waitUntilExit()
			case 4 :
				let convertTask: Process = Process()
				convertTask.launchPath = launchPath
				convertTask.arguments = [
					"-y",
					"-i", "\(inputFilePath)",
					"-c:a", "flac",
					"\(outputFilePath)"
				]
				convertTask.standardInput = FileHandle.nullDevice
				convertTask.launch()
				convertTask.waitUntilExit()
			default :
				let convertTask: Process = Process()
				convertTask.launchPath = launchPath
				convertTask.arguments = [
					"-y",
					"-i", "\(inputFilePath)",
					"-c", "copy",
					"\(outputFilePath)"
				]
				convertTask.standardInput = FileHandle.nullDevice
				convertTask.launch()
				convertTask.waitUntilExit()
		}
	}
}

It violates the DRY rule left, right, and center, I know, but with the trouble I was having, at least this way is closer to the way I know worked for the original person who posted about it.

Now instead of errors relating to the arguments, instead I’m getting an “Operation not permitted” error. Which suggests that the arguments are acceptable, but either XCode or ffmpeg or both don’t have permission to do what I’m trying to get them to do?

@ncrusher Do you still have issues with this?

No, it turns out the issue was related to sandboxing and the fact that I hadn’t set any exceptions to it. I now have user-selected directories set to read/write and it works. Thank you.