Trying to chain processes together on a pipeline
Andrew Berg
bahamutzero8825 at gmail.com
Thu Jun 30 21:40:12 EDT 2011
Okay, so I've refactored those except WindowsError blocks into calls to
a function and fixed the os.devnull bug, but I still can't get the
triple chain working. I added calls to ffmpeg_proc.stdout.close() and
sox_proc.stdout.close(), but I really am not sure where to put them. The
following code works if SoX isn't part of the chain (that is, if vol ==
1), but not otherwise (the Nero encoder says "truncation error" after it
finishes; the same error I get if omit the close() calls):
> while True:
> if queue[position].audio:
> if queue[position].vol != 1:
> queue[position].ffmpeg_cmd = [
> queue[position].ffmpeg_exe,
> '-i', queue[position].ifile,
> '-f', 'sox', '-'
> ]
> queue[position].sox_cmd = [
> queue[position].sox_exe,
> '-t', 'sox', '-',
> '-t', 'wav', '-',
> 'vol', str(queue[position].vol)
> ]
> else:
> queue[position].ffmpeg_cmd = [
> queue[position].ffmpeg_exe,
> '-i', queue[position].ifile,
> '-f', 'wav', '-'
> ]
> queue[position].nero_aac_cmd = [
> queue[position].nero_aac_exe,
> '-ignorelength',
> '-q', str(queue[position].aac_quality),
> '-if', '-',
> '-of', queue[position].outdir + queue[position].prefix + '.m4a'
> ]
> print(queue[position].ffmpeg_cmd)
> print(queue[position].sox_cmd)
> print(queue[position].nero_aac_cmd)
> try:
> ffmpeg_proc = subprocess.Popen(queue[position].ffmpeg_cmd,
> stdout=subprocess.PIPE, stderr=open(os.devnull, 'w'))
> except WindowsError as exc:
> log_windows_error(exc, queue[position].ffmpeg_cmd, 'critical')
> break
> if queue[position].vol != 1:
> try:
> sox_proc = subprocess.Popen(queue[position].sox_cmd,
> stdin=ffmpeg_proc.stdout, stdout=subprocess.PIPE,
> stderr=open(os.devnull, 'w'))
> wav_pipe = sox_proc.stdout
> except WindowsError as exc:
> log_windows_error(exc, queue[position].sox_cmd, 'critical')
> break
> else:
> wav_pipe = ffmpeg_proc.stdout
> try:
> nero_aac_proc = subprocess.Popen(queue[position].nero_aac_cmd,
> stdin=wav_pipe)
> except WindowsError as exc:
> log_windows_error(exc, queue[position].nero_aac_cmd, 'critical')
> break
> finally:
> ffmpeg_proc.stdout.close()
> if queue[position].vol != 1:
> sox_proc.stdout.close()
> ffmpeg_proc.wait()
> if queue[position].vol != 1:
> sox_proc.wait()
> nero_aac_proc.wait()
> break
More information about the Python-list
mailing list