Last active
November 24, 2019 17:13
-
-
Save Tokariew/01910c6931f4e7de539c338251999ffd to your computer and use it in GitHub Desktop.
Simple function to encode wav/flac to opus in given folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def to_opus(folder='.', ext='flac', bitrate=48): | |
from os import cpu_count | |
from pathlib import Path | |
from concurrent.futures import ThreadPoolExecutor | |
from subprocess import call | |
file_list = [file.name for file in Path(folder).iterdir() if file.is_file() and ext in file.name] | |
commands = [f'opusenc --bitrate {bitrate} --framesize 60 --discard-pictures --quiet "{file}" "{file.replace(ext, "opus")}"' for file in file_list] | |
with ThreadPoolExecutor(max_workers=cpu_count()) as executor: | |
for command in executor.map(call, commands): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment