You know, there is no shame when using subprocess to call external utilities. For example, you can create channels such as:
#!/usr/bin/env python import subprocess frommp3 = subprocess.Popen(['mpg123', '-w', '-', '/tmp/test.mp3'], stdout=subprocess.PIPE) toogg = subprocess.Popen(['oggenc', '-'], stdin=frommp3.stdout, stdout=subprocess.PIPE) with open('/tmp/test.ogg', 'wb') as outfile: while True: data = toogg.stdout.read(1024 * 100) if not data: break outfile.write(data)
In fact, this is probably your best approach. Note that in a multiprocessor system, the MP3 decoder and OGG encoder will work in separate processes and are likely to be scheduled on separate cores. If you tried to do the same with a single-threaded library, you could only re-encode as fast as only one core could process it.
Kirk Strauser
source share