我跑FFmpeg在我的服务器上使用 PHP exec()
.
它目前在编码时使用 100% 的 cpu 线程。
我关注了this gude使用名为 cpulimit 的程序将其降低到 30%。
PHP
$args = "nice -19 cpulimit -l 30 -- ffmpeg -y -i intput.avi -vcodec libx264 -acodec aac -b:a 192k -threads 1 output.mp4"
exec(escapeshellcmd($args));
FFmpeg/PHP 有效,它可以与
nice
一起使用/cpulimit
通过终端,但添加后nice -19 cpulimit -l 30 --
到 PHP 脚本,它不再适用于 exec()
.输出
FFmpeg 输出返回空白。我无法看到完整的输出,我尝试使用:
$output = shell_exec($args);
echo "<p>$output</p>"
和
file_put_contents("/var/www/mysite/logs/$output.log", $line . PHP_EOL, FILE_APPEND);
但他们返回 1 个空行。
解决方案
我的想法是 www-data 运行 FFmpeg 和
nice
/cpulimit
可能需要root?如何获取 PHP
exec()
与 FFmpeg args 和 cpulimit 一起工作?或者有没有其他方法来限制使用百分比?
最佳答案
如果启用了安全模式,则程序的执行受到限制。在此处查看此文档,http://php.net/manual/en/function.exec.php
关于php - 使用 cpulimit 和 PHP 减少 FFmpeg CPU 使用率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43127243/