I'm writing a PHP script that converts uploaded video files to FLV on the fly, but I only want it to run that part of the script if the user has FFmpeg installed on the server.
Would there be a way to detect this ahead of time? Could I perhaps run an FFmpeg command and test whether it comes back "command not found?"
Verify FFmpeg Path To check if FFmpeg is properly added to the Windows path, open the Command Prompt or PowerShell window, type ffmpeg , and press Enter. If everything goes well, you will see FFmpeg details like the version number, default configuration, etc.
/usr/bin/ffmpeg is the correct path to the ffmpeg binary. Based on your whereis command that should be the correct path. You can try and verify it's location by running /usr/bin/ffmpeg -h from the command line.
If ffmpeg is in the path, use which ffmpeg to find its path. If it's not in the path, use locate ffmpeg . The fact that it's a server should not change the path where it is installed if you installed it with packages, so it should probably be in /usr/bin/ffmpeg .
Try:
$ffmpeg = trim(shell_exec('which ffmpeg')); // or better yet:
$ffmpeg = trim(shell_exec('type -P ffmpeg'));
If it comes back empty ffmpeg is not available, otherwise it will hold the absolute path to the executable, which you may use in the actual ffmpeg call:
if (empty($ffmpeg))
{
die('ffmpeg not available');
}
shell_exec($ffmpeg . ' -i ...');
The third parameter to the exec()
function is the return value of the executed program. Use it like this:
exec($cmd, $output, $returnvalue);
if ($returnvalue == 127) {
# not available
}
else {
#available
}
This works on my Ubuntu box.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With