我写了一个python脚本,可以使用mpg123
将mp3
转换为wav
。然后ffmpeg
获取mpg123
的输出并对其进行上采样。最后,ffmpeg
输出文件上传到云。所有这些步骤必须一致地运行。
subprocess.run(['mpg123', ...])
subprocess.run(['ffmpeg', ...])
upload()
假设我有很多mp3
文件,我想同时运行 10 个线程。我知道Python在subprocess.Popen
、threading
、concurrent.futures
和multiprocessing
模块中提供线程化。并行处理此过程的正确方法是什么?
您可以使用MPipe 库:
from mpipe import OrderedStage, Pipeline
def increment(value):
return value + 1
def double(value):
return value * 2
stage1 = OrderedStage(increment, 3)
stage2 = OrderedStage(double, 3)
pipe = Pipeline(stage1.link(stage2))
for number in range(10):
pipe.put(number)
pipe.put(None)
for result in pipe.results():
print(result)