Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8617

Re: Trying to chain processes together on a pipeline

Date 2011-06-30 20:40 -0500
From Andrew Berg <bahamutzero8825@gmail.com>
Subject Re: Trying to chain processes together on a pipeline
References <4E096D3B.3080300@gmail.com> <iubshf$dus$1@dough.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.532.1309484420.1164.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Trying to chain processes together on a pipeline Andrew Berg <bahamutzero8825@gmail.com> - 2011-06-30 20:40 -0500
  Re: Trying to chain processes together on a pipeline Peter Otten <__peter__@web.de> - 2011-07-01 09:26 +0200
    Re: Trying to chain processes together on a pipeline Andrew Berg <bahamutzero8825@gmail.com> - 2011-07-01 03:02 -0500
    Re: Trying to chain processes together on a pipeline Chris Rebert <clp2@rebertia.com> - 2011-07-01 01:24 -0700

csiph-web