Reputation: 463
I have an upload.php
script to upload & convert videos where I use FFMPEG. (LAMP Ubuntu 16.04)
However as soon as FFMPEG starts to convert the video, the all website becomes unresponsive so I guess FFMPEG uses all my CPU.
Here is the 3 lines I use to convert source video:
* 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
Is there anyway to limit CPU ressources for FFMPEG while converting videos?
Thanks
EDIT :
I tried to use -threads 1
without success
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');
I tried to use nice -n 15
without success as well
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 is still eating 100% of my CPU while converting
Upvotes: 1
Views: 108
Reputation: 187
This happened because you didn't send FFMPEG process to background. you can do this by using nohup.
shell_exec("nohup ffmpeg (...) > foo.out 2> foo.err < /dev/null &");
Upvotes: 1
Reputation: 163272
You can always execute FFmpeg with nice
. Something like this...
shell_exec('nice -n 15 ffmpeg...
Note that your system may actually be starved for some other resource, like disk I/O. Use top
to find out.
Upvotes: 0