1

This question comes about because I have been working on a CD ripping script in Python that utilizes a few subprocess calls. Currently, I have the following Python 3 code:

for x in range(number_of_tracks):
    cdparanoia = subprocess.Popen(['cdparanoia', '-B', x, '-'], stdout=subprocess.PIPE)
    flac = subprocess.run(['flac', '--best', '-o' 'output_path', '-'], stdin=cdparanoia.stdout)

While this is a little bit of a watered down excerpt of my main code, this gets the idea across.

But this got me thinking, is there any way I could 'tee' the output of the cdparanoia call to another encoder? I've used programs like dbpoweramp before that have multi-encoder options, so I would like to do something like that. But is it even plausible? If so, how would you go about it?

In advance, thanks for your time.

Hai Vu
  • 37,849
  • 11
  • 66
  • 93
tedm1106
  • 127
  • 1
  • 10
  • do you want to implement something like [GraphEdit's Tee filter](https://msdn.microsoft.com/en-us/library/windows/desktop/dd377612(v=vs.85).aspx) or [GStreamer's tee plugin](https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer-plugins/html/gstreamer-plugins-tee.html)? (you could call the latter via the command-line or using its API directly (here's [code example that plays a .flac file using GStreamer](http://ru.stackoverflow.com/a/384902/23044)) – jfs Jun 13 '16 at 13:43
  • unrelated to audio (I would not recommend it for audio streams) but related to "how to tee subprocess' output": [Python subprocess get children's output to file and terminal?](http://stackoverflow.com/a/4985080/4279) – jfs Jun 13 '16 at 13:45
  • unrelated: the implementation of the shell pipeline in your question is incorrect (it is missing `cdparanoia.stdout.close()`)—if `flac` dies `cdparanoia` may hang indefinitely). See [How do I use subprocess.Popen to connect multiple processes by pipes?](http://stackoverflow.com/q/295459/4279) – jfs Jun 13 '16 at 13:54
  • I would like to do something similar to the GStreamer plugin, but without the GStreamer dependency. On the other hand, I believe that the other two examples are writing to files. I could simply write the cdparanoia file to the disk, but I would prefer not to, so I can extend the hard disk's lifetime. – tedm1106 Jun 13 '16 at 16:29
  • if you don't want specialized tools, you could try a bash command (I have no idea whether it will work inside an audio streaming pipeline): `cdparanoia | tee (>encoder) | flac`. Here's how to [emulate it without `bash`](http://stackoverflow.com/q/28840575/4279). Have you tried asyncio or thread -based [solutions I've linked above](http://stackoverflow.com/questions/37779522/writing-an-audio-stream-to-multiple-files-using-python-3?noredirect=1#comment63048986_37779522)? – jfs Jun 13 '16 at 17:49
  • I have found out that FFmpeg can pipe out to multiple files using different encoders, so I have opted towards piping to FFmpeg instead and dealing with it from there. – tedm1106 Jun 14 '16 at 19:49

0 Answers0