Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect FFmpeg installation and Version

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?"

like image 639
Aaron Avatar asked May 06 '09 18:05

Aaron


People also ask

How do I know if I have ffmpeg on Windows?

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.

Where can I find ffmpeg in Linux?

/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.

Where is ffmpeg installed?

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 .


2 Answers

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 ...');
like image 72
Alix Axel Avatar answered Sep 27 '22 18:09

Alix Axel


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.

like image 38
Peter Stuifzand Avatar answered Sep 27 '22 17:09

Peter Stuifzand