Create a pipe of input and output for wav to mp3 encoding
See original GitHub issueI have to pipe a wave data
stream to ffmpeg in Python. I can easily create an output pipe from an input mp3
file like:
process = (
ffmpeg
.input(path)
.output('pipe:', **output_kwargs)
.run_async(pipe_stdout=True, pipe_stderr=True))
buffer, _ = process.communicate()
# because of we need (n_channels, samples)
waveform = np.frombuffer(buffer, dtype='<f4').reshape(-1, n_channels)
if not waveform.dtype == np.dtype(dtype):
waveform = waveform.astype(dtype)
Here waveform
will contain the wave audio file.
Now, I want to pipe the same data, but from an input stream, but for some reason it does not work as expected:
# data shape is like (9161728, 2) for two channels audio data
input_kwargs = {'ar': sample_rate, 'ac': data.shape[1]}
output_kwargs = {'ar': sample_rate, 'strict': '-2'}
n_channels = 2
process = (
ffmpeg
.input('pipe:', format='f32le', **input_kwargs)
.output('pipe:', **output_kwargs)
.run_async(pipe_stdin=True, quiet=True))
buffer, err = process.communicate(input=data.astype('<f4').tobytes())
The output buffer
is empty here after getting the results from process.communicate
, while err
is
Unable to find a suitable output format for 'pipe:'\npipe:: Invalid argument\n"
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
Create a pipe of input and output for wav to mp3 encoding
I have to pipe a wave data stream to ffmpeg in Python. I can easily create an output pipe from an input mp3...
Read more >Convert to WAV using FFMPEG for pipe into LAME?
I'm trying to convert an AAC file into WAV in order to pipe the output into LAME. I' ...
Read more >Generate LAME-encoded audio MP3 from text - Mac OS X Hints
So I wrote this little script that takes a plain text file as input, and generates an audio MP3 using Vicki's voice.
Read more >ear-pipe - Pipe audio streams to your ears - Dan Motzenbecker
If your input encoding isn't mp3, make sure you set it to one of the formats ... true implies default output encoding (wav)...
Read more >A simple way to read and write audio and video files in C ...
wav ") and passes raw 16-bit signed integer samples into this program via a pipe. The other receives modified samples from this program...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@loretoparisi, @kkroening has this issue been addressed? When I pipe in and out, I also have this issue where if I write a couple of times to
stdin
then at some point thestdin.write()
call just hangs indefinitely - it’s slightly different from @loretoparisi’s issue, but I think it’s the same issue at its core.Mine looks like this:
Then doing
process.stdin.write(<bytes object from image>)
repeatedly will hang after some time - this is very consistent behavior, as it happens for every video that I pass in.When a single pipe is used (either for the input or the output), it then starts working again. An example of this is the following:
Is there an update on this? I would imagine piping is something we would want to have working well?