I'm having some issues with a script I'm trying to write to automate some of my ffmpeg video commands. I need to run ffmpeg via Process and in doing so, I've noticed that once it starts running it never does anything (as it never even creates the output file) and never stops running. I'm not entirely sure how to fix this, to get the full command to run and then exit once finished. Any insight on this would be much appreciated.
ffmpeg is installed on my system through Homebrew:
brew tap slhck/ffmpeg
brew install slhck/ffmpeg/ffmpeg --with-aom --with-fdk-aac
To test, replace the placeholders in the script with the path to the video and the path to it's output (usually, I just specify the same path as the input, but with an .mp4 extension instead) and run in Terminal using swift ~/path/to/FfmpegCommand.swift.
Have you tried using the -nostdin option of ffmpeg?
ffmpegenables interaction with stdin by default. On Mac OS X and Linux systems, this causes an ffmpeg job running in the background to suspend. Adding option -nostdin to the invocation causes ffmpeg to not enable stdin interaction, and so avoids suspending the background process.
Yes! This made it work with the original implementation! Thank you so much! I looked all over for flag options that might impact it, but ffmpeg has so many.
However, based on the “command not found” error you got, it does not look like ffmpeg is registered in $PATH in whatever environment you are in. The variant that bypasses the shell and interacts directly with the executable at a given path is this:
Note that since the arguments are passed directly, there is no intervening shell to interpret the quotation marks, so leave them out. (Also note that there is no shell to split the arguments at spaces, so ffmpeg will receive the arguments in exactly the form specified by the array.)
Never mind. For some reason the form never showed the intervening posts until after I responded. Sorry for the noise. Just ignore what I said. -nostdin was the real culprit; no sense experimenting with the threading.
I'm considering replacing my hodgepodge shell solution with your library, so this was all still helpful, thanks! I didn't realize until today that I don't know much about shells and processes outside of Bash
Glad I could help! I had the same issue some weeks ago.
BTW, ffmpeg is not a good candidate for swift bash functions that take an array of arguments. For some reason I failed to write the following command in the form bash.run(command: [...]):