[FFmpeg-user] How can I reduce the cpu usage of ffmpeg?
voip at gmx.ca
voip at gmx.ca
Sat Jan 10 19:26:41 CET 2015
On Saturday, January 10, 2015 at 7:39 AM, "Moritz Barsnick" <barsnick at gmx.net> wrote:
> On Sat, Jan 10, 2015 at 10:41:07 +0100, voip at gmx.ca wrote:
> > /usr/bin/ionice -c 3 /usr/bin/nice -n 20 /usr/local/bin/ffmpeg -y -i "original_video" -c:v libx264 -b:v 16711680 -pix_fmt yuv420p -c:a copy -c:s copy "converted_video"
> > Note that I am running both ionice and nice to give ffmpeg the lowest
> > possible priority, yet it still maxes out my CPU.
> Software usually doesn't know how not to do that when doing actual
> stuff and not idling.
> "nice" changes priority (as the name implies), but if there's nothing
> else asking for the CPU (or the I/O), your ffmpeg process will still
> max it out.
> A tool often referenced to is "cpulimit", which is supposed to be able
> to do what you are looking for.
> Apart from that, Andy's mentioned cpufreq approach seems correct.
Of the two approaches, "cpulimit" seemed the easiest to implement although it confuses me. According to the documentation, if I run this:
cpulimit -z -e ffmpeg -l 95
It should limit CPU usage to 95%, which one would not think is a significant drop from 100%, yet just reducing it that much makes a huge difference. Running that, the CPU temperature stays at a much more reasonable 40 - 41 degrees Celsius.
Of course that comes at the expense of much longer running time, but my plan was to run ffmpeg from a shell script in the middle of the night anyway. And therein lies the problem. In order to work, cpulimit must be started AFTER ffmpeg, and when the shell script gets to ffmpeg it doesn't move on to the next command until ffmpeg is finished. And I would not really want it to, because the shell script will also do a file move/replace that can only be done after ffmpeg is finished.
So basically I would need to start ffmpeg, then without moving along in the shell script, start cpulimit a second or two later (just long enough to make sure ffmpeg has started). I can't really wrap my head around how to do that right now.
> > The problem with that is that my CPU temperature rather quickly rises
> > from a rather tepid 28 degrees Celsius to a blistering 58 degrees
> > Celsius rather quickly (yes, that is a full 30 Celsius degrees
> > higher!).
> I totally agree with Andy that that doesn't sound horrible, but depends
> on the CPU and system of course. But if the system could become
> endangered from running full load, it would be a badly designed system.
I'm not as worried about total failure as I am that because ffmpeg can take at the minimum a couple of hours to do one file, running at that temperature for that long a time could potentially shorten the lifespan of the CPU, and this is not a system where I would like to see any kind of hardware failure since we had such a horrendous time getting it to work in the first place.
Thanks to you guys for the info on cpulimit and cpufreq.
More information about the ffmpeg-user