Skip to content

Instantly share code, notes, and snippets.

@Tokariew
Last active November 24, 2019 17:13
Show Gist options
  • Save Tokariew/01910c6931f4e7de539c338251999ffd to your computer and use it in GitHub Desktop.
Save Tokariew/01910c6931f4e7de539c338251999ffd to your computer and use it in GitHub Desktop.
Simple function to encode wav/flac to opus in given folder
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