PHP 的 exec() 不执行 FFmpeg 命令
我已经在我的服务器上安装了 ffmpeg,它通过我的终端运行良好。我能够成功将文件转换为 webm 格式,因此我确信安装没问题。我还确定我的机器上只安装了一个 ffmpeg。
当我尝试通过 PHP 的 exec() 通过 PHP 转换文件时出现问题。当我运行相同的命令时,我在终端中运行,没有任何反应。我查阅了 stackoverflow 和网络的其他部分来寻求帮助。我尝试这样做来查看输出:
exec($cmd, $out, $rv);
echo "output is:\n".implode("\n", $out)."\n exit code:$rv\n";
输出是:“输出是:退出代码:127”
我正在使用的命令采用以下格式:
ffmpeg -i "sample.mov" -vcodec libvpx -r 30 -b "644k" -acodec libvorbis -ab 128000 -ar "44100" -ac 2 -s "352x198" "sample.webm"
我尝试将“ffmpeg”替换为 FFmpeg 的完整路径,但没有工作。
为什么脚本不能正确运行命令并转换文件?
谢谢你!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
错误代码 127 表示无法找到可执行文件 (ffmpeg)。尝试指定整个路径(您可以使用
which ffmpeg
在终端中找到该路径)或比较 php 脚本和终端中的PATH
环境变量的值。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 thePATH
environment variable in your php script and terminal.我对 php 的 ant 目标执行有类似的问题。我无法从 ant 命令仅获取前几行的完整输出,并且 ant 目标未执行。换句话说,是部分执行的。
使用下面的命令,我已成功运行它,但命令的输出附加到 log_file.log 中。
希望这对你有用。
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.
Hope this will work for you.