Search code examples
phpnginxavconvyoutube-dl

Limit the cpu usage when converting youtube videos to mp3 using youtube-dl


I am using youtube-dl & avconv with php on nginx server to convert youtube video into mp3. Using htop I noticed the usage of cpus peak at 100% when couple of avconv processes are running at the same time, and once my server crushed down because of that.

The first solution that I encountered cpulimit but after some research,I've found cpu limit is not smart enough to handle multiple simultaneous instances.

From this answer I learned that I can limit the number of cpu threads using -threads option. My basic command: youtube-dl --extract-audio --audio-format mp3 <video URL>

I wonder if I can add -threads option to the youtube-dl command, I am not sure if that is possible.

I have 2 cores cpu server, I am thinking of upgrading to 4 cores cpu and limit the avconv to use just 2 cores, what do you think ? Is that the best way to go (using thread option) ?


Solution

  • You may try --postprocessor-args '-threads N'.