gpt4 book ai didi

php - FFMPEG 在转换视频时使我的网站关闭

转载 作者:行者123 更新时间:2023-12-04 22:59:30 25 4
gpt4 key购买 nike

我有一个 upload.php在我使用 FFMPEG 的地方上传和转换视频的脚本。 (灯 Ubuntu 16.04)

然而,一旦 FFMPEG 开始转换视频,所有网站都会变得无响应,所以我猜 FFMPEG 会使用我所有的 CPU。

这是我用来转换源视频的 3 行:

* Check format, size, ect..

shell_exec('ffmpeg -i '.$temp_path.' -r 1/1 '.$path_jpeg.'');
shell_exec('ffmpeg -i '.$temp_path.' -f webm -c:v libvpx -b:v 1M -acodec libvorbis '.$path_webm.' -hide_banner');
shell_exec('ffmpeg -i '.$temp_path.' -c:v libx264 -preset veryfast -c:a copy '.$path_mp4.' -hide_banner');

* Add video data to DB

无论如何在转换视频时限制 FFMPEG 的 CPU 资源?

谢谢

编辑 :

我尝试使用 -threads 1没有成功
shell_exec('ffmpeg -i '.$temp_path.' -f webm -c:v libvpx -threads 1 -b:v 1M -acodec libvorbis '.$path_webm.' -hide_banner');
shell_exec('ffmpeg -i '.$temp_path.' -c:v libx264 -threads 1 -preset veryfast -c:a copy '.$path_mp4.' -hide_banner');

我尝试使用 nice -n 15也没有成功
shell_exec('nice -n 15 ffmpeg -i '.$temp_path.' -f webm -c:v libvpx -b:v 1M -acodec libvorbis '.$path_webm.' -hide_banner');
shell_exec('nice -n 15 ffmpeg -i '.$temp_path.' -c:v libx264 -preset veryfast -c:a copy '.$path_mp4.' -hide_banner');

FFMPEG 在转换时仍然占用了我 100% 的 CPU

enter image description here

最佳答案

发生这种情况是因为您没有将 FFMPEG 进程发送到后台。你可以通过使用 nohup 来做到这一点。

shell_exec("nohup ffmpeg (...)  > foo.out 2> foo.err < /dev/null &");

关于php - FFMPEG 在转换视频时使我的网站关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51146561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com