diff options
Diffstat (limited to 'recode.py')
-rw-r--r-- | recode.py | 36 |
1 files changed, 19 insertions, 17 deletions
@@ -1,4 +1,5 @@ -import subprocess, tempfile, threading +import subprocess, tempfile, threading, os +from config import config decoders = {} encoders = {} @@ -29,21 +30,22 @@ class Codec(object): # end of metastuff -class FFmpeg(Codec): +class FFmpeg(Decoder): decoder_name = 'ffmpeg' - encoder_name = 'ffmpeg' def decode(self, source, dest, *args): - ret = subprocess.call((x.format(infile = source, outfile = dest) for x in 'ffmpeg -loglevel quiet -i {infile} -y {outfile}'.split())) - print 'decoding returned', ret + cmd = (x.format(infile = source, outfile = dest) for x in 'ffmpeg -loglevel quiet -i {infile} -y {outfile}'.split()) + p = subprocess.Popen(cmd, stderr = subprocess.PIPE, close_fds = True) + p.stderr.close() + p.wait() - def encode(self, source, dest, *args): - ret = subprocess.call((x.format(infile = source, outfile = dest) for x in 'ffmpeg -loglevel quiet -i {infile} -y {outfile}'.split())) - print 'encoding returned', ret +class Ogg(Encoder): + encoder_name = 'ogg' - def recode(self, source, dest, *args): - ret = subprocess.call((x.format(infile = source, outfile = dest) for x in 'ffmpeg -loglevel quiet -i {infile} -y {outfile}'.split())) - print 'recoding returned', ret + def encode(self, source, dest, *args): + options = config.get('options', 'encoder/ogg', '') + cmd = ['oggenc', '-Q'] + options.split() + [source, '-o', dest] + subprocess.call(cmd) class Recoder(object): def __init__(self, decoder, encoder): @@ -56,12 +58,12 @@ class Recoder(object): print self.decoder self.decoder.recode(source, dest) else: - temp = tempfile.NamedTemporaryFile(mode = 'wb', prefix = 'foo', suffix = os.path.splitext(dest)[1], delete = True) - print 'decoding' - self.decoder.decode(source, temp.name) - print 'encoding' - self.encoder.encode(temp.name, dest) - temp.close() + with tempfile.NamedTemporaryFile(mode = 'wb', prefix = 'foo', suffix = '.wav', delete = True) as temp: + print 'temp file:', temp.name + print 'decoding' + self.decoder.decode(source, temp.name) + print 'encoding' + self.encoder.encode(temp.name, dest) class RecodeThread(threading.Thread): lock = threading.Lock() |