From: Paul Brossier Date: Fri, 15 Apr 2011 09:49:26 +0000 (+0000) Subject: timeside/decoder/subprocess.py: moved subprocess classes to own file X-Git-Tag: 0.3.2~43 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=c57ae7b894b80bb07ccd2b8e689aad61b0ae45f7;p=timeside.git timeside/decoder/subprocess.py: moved subprocess classes to own file --- diff --git a/timeside/decoder/subprocess.py b/timeside/decoder/subprocess.py new file mode 100644 index 0000000..203c49a --- /dev/null +++ b/timeside/decoder/subprocess.py @@ -0,0 +1,49 @@ + +class SubProcessPipe: + + def __init__(self, command, stdin=None): + """Read media and stream data through a generator. + Taken from Telemeta (see http://telemeta.org)""" + + self.buffer_size = 0xFFFF + + if not stdin: + stdin = subprocess.PIPE + + self.proc = subprocess.Popen(command.encode('utf-8'), + shell = True, + bufsize = self.buffer_size, + stdin = stdin, + stdout = subprocess.PIPE, + close_fds = True) + + self.input = self.proc.stdin + self.output = self.proc.stdout + + +class DecoderSubProcessCore(Processor): + """Defines the main parts of the decoding tools : + paths, metadata parsing, data streaming thru system command""" + + def __init__(self): + self.command = 'ffmpeg -i "%s" -f wav - ' + + def process(self, source, options=None): + """Encode and stream audio data through a generator""" + + command = self.command % source + proc = SubProcessPipe(command) + return proc.output + + #while True: + #__chunk = proc.output.read(self.proc.buffer_size) + #status = proc.poll() + #if status != None and status != 0: + #raise ExportProcessError('Command failure:', command, proc) + #if len(__chunk) == 0: + #break + #yield __chunk + + + +