PHP - Executing ffmpeg using exec() and shell_exec() does nothing
-
04-06-2021 - |
题
I'm trying to convert an audio file in PHP using ffmpeg, I get the audio file via post as a m4a and I want to turn it into mp3. I do the following to do this:
$commandOutput = shell_exec('ffmpeg -i '.$filePath.' -ar 8000 -ab 16000 '.str_replace('m4a', 'mp3', $filePath));
Yet it does nothing, and commandOutput also contains nothing. The file is saved properly but not converted to mp3, when I run the same command in terminal it converts the file properly. Any idea what might be happening?
解决方案
Try wrapping commands like this:
exec($cmd." 2>&1", $out, $ret);
if ($ret){
echo "There was a problem!\n";
print_r($out);
}else{
echo "Everything went better than expected!\n";
}
exec()
lets you capture all output and get the exit code. Adding 2>&1
makes sure to redirect STDERR
to STDOUT
so you can see any error messages.
其他提示
You could use the ffmpeg-php extension: http://sourceforge.net/projects/ffmpeg-php/
不隶属于 StackOverflow