Encode multiple tracks concurrently
This commit is contained in:
parent
4633505b98
commit
a65b6dd6e3
24
src/main.py
24
src/main.py
|
@ -3,6 +3,7 @@ import subprocess
|
|||
import shutil
|
||||
from subprocess import CalledProcessError
|
||||
from pathlib import Path
|
||||
from multiprocessing import Pool
|
||||
|
||||
|
||||
def get_args():
|
||||
|
@ -30,15 +31,22 @@ def skip_album(path: Path):
|
|||
return False
|
||||
|
||||
|
||||
def transcode(transcode_list: list, encoder: Path):
|
||||
def transcode(transcode_list: list, encoder: Path, workers=8):
|
||||
worker_args = [(row[0], row[1], encoder) for row in transcode_list]
|
||||
with Pool(workers) as p:
|
||||
print(p.starmap_async(transcode_worker, worker_args))
|
||||
p.close()
|
||||
p.join()
|
||||
|
||||
|
||||
def transcode_worker(in_track, out_track, encoder):
|
||||
additional_args = ('--bitrate', '128', '--music')
|
||||
for in_track, out_track in transcode_list:
|
||||
subprocess_args = (str(encoder),) + additional_args + (in_track, out_track)
|
||||
try:
|
||||
result = subprocess.run(subprocess_args, capture_output=True, text=True, check=True)
|
||||
except CalledProcessError:
|
||||
print(f"ERROR: Transcoding of '{in_track}' failed with errors:")
|
||||
print(result.stderr)
|
||||
subprocess_args = (str(encoder),) + additional_args + (in_track, out_track)
|
||||
try:
|
||||
result = subprocess.run(subprocess_args, capture_output=True, text=True, check=True)
|
||||
return f"Transcoded '{in_track}' successfully"
|
||||
except CalledProcessError:
|
||||
return f"ERROR: Transcoding of '{in_track}' failed with errors:\n{result.stderr}"
|
||||
|
||||
|
||||
def main(input_dir: Path, output_dir: Path, encoder: Path):
|
||||
|
|
Loading…
Reference in New Issue
Block a user