使用 youtube-dl 将 youtube 视频转换为 mp3 时限制 cpu 的使用

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

我在 nginx 服务器上使用带有 php 的 youtube-dl 和 avconv 将 youtube 视频转换为 mp3。使用 htop 我注意到当几个 avconv 进程同时 运行 时 cpus 的使用率达到 100% 的峰值,并且一旦我的服务器因此崩溃。

我遇到的第一个解决方案 cpulimit 但经过一些研究,我发现 cpu limit 不够智能,无法同时处理多个实例。

从此 answer 我了解到我可以使用 -threads 选项限制 cpu 线程的数量。 我的基本命令:youtube-dl --extract-audio --audio-format mp3 <video URL>

我想知道是否可以在 youtube-dl 命令中添加 -threads 选项,我不确定是否可行。

我有 2 个内核 cpu 服务器,我正在考虑升级到 4 个内核 cpu 并将 avconv 限制为仅使用 2 个内核,您怎么看?这是最好的方法吗(使用线程选项)?

你可以试试--postprocessor-args '-threads N'

如果您使用的是 youtube-dl 嵌入式添加

'postprocessor_args': ['-threads', 'some_integer']

到ydl_opts字典