Last active
May 10, 2024 09:51
-
-
Save whitekid/21f903515f4721fa597b to your computer and use it in GitHub Desktop.
convert ogg to mp3 with ffmpeg
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
import os, sys | |
import fnmatch | |
import subprocess | |
import multiprocessing | |
from multiprocessing.pool import ThreadPool | |
def iter_files(root, pattern): | |
for root, dirs, files in os.walk(root): | |
for f in files: | |
if not fnmatch.fnmatch(f, pattern): continue | |
yield root, f | |
def burn(x): | |
infile = os.path.join(x[0], x[1]) | |
outfile = os.path.join(os.path.splitext(infile)[0], '.mp3') | |
subprocess.call(["ffmpeg", "-i", infile, "-map_metadata", "0:s:0", "-b:a", "192k", outfile, "-y"]) | |
def main(): | |
path = '.' | |
if len(sys.argv) > 0: | |
path = sys.argv[0] | |
cpus = multiprocessing.cpu_count() | |
#pool = multiprocessing.Pool(cpus) | |
pool = ThreadPool(cpus) | |
pool.map(burn, iter_files(path, '*.ogg')) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment