PHP's exec() not executing command for

2019-08-14 05:46发布

I have installed ffmpeg on my server and it works fine via my terminal. I'm able to successfully convert a file to webm format, so I'm sure the installation is fine. I'm also sure that I only have one installation of ffmpeg installed on my machine.

A problem arises when I try to convert files through PHP via PHP's exec(). When I run the same commands, I ran in the terminal, nothing happens. I looked around stackoverflow and other parts of the net for some help. I tried this to see the output:

exec($cmd, $out, $rv);
echo "output is:\n".implode("\n", $out)."\n exit code:$rv\n";

The output is: "output is: exit code:127"

The command I'm using is in this format:

ffmpeg -i "sample.mov" -vcodec libvpx  -r 30 -b "644k" -acodec libvorbis -ab 128000   -ar "44100" -ac 2 -s "352x198" "sample.webm"

I've tried replacing "ffmpeg" with the full path to FFmpeg but that did not work.

Why isn't the script running the command correctly and converting the files?

Thank you!

2条回答
在下西门庆
2楼-- · 2019-08-14 06:12

I have similar problem with ant target executions from php. I can't get whole output from ant command only first few rows and ant target was not executed. In other words is partial executed.

With bellow command I've managed to run it but output of the command is append to log_file.log.

$commandString = 'you_command_here >> log_file.log 2>&1 &';
$command = exec($commandString);

Hope this will work for you.

查看更多
Rolldiameter
3楼-- · 2019-08-14 06:14

Error code 127 means the executable (ffmpeg) couldn't be found. Try specifying the whole path (you can that out find in your terminal with which ffmpeg) or compare the value of the PATH environment variable in your php script and terminal.

查看更多
登录 后发表回答