Created
December 10, 2014 10:53
-
-
Save itorres/ed88c06bfd990c83887a to your computer and use it in GitHub Desktop.
Quick script to transcode a flac music collection to opus
This file contains 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
#!/usr/bin/env python | |
import os | |
import sys | |
basedir = sys.argv[1] | |
for root, dirs, files in os.walk(basedir): | |
cmd = 'avconv -i "{infile}" -map 0:a -codec:a \ | |
opus -b:a 48k -vbr on "{outfile}"' | |
print "Visiting", root | |
for filename in files: | |
(f, ext) = filename.rsplit('.', 1) | |
if ext == 'flac': | |
outdir = os.path.join("opus", root[len(basedir):]) | |
try: | |
os.makedirs(outdir) | |
except OSError, e: | |
if e.errno != 17: | |
raise | |
infile = os.path.join(root, filename) | |
outfile = os.path.join(outdir, f + ".opus") | |
print "Infile: {infile}\n Outfile: {outfile}".format( | |
infile=infile, outfile=outfile) | |
if not os.path.exists(outfile): | |
os.system(cmd.format(infile=infile, outfile=outfile)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment