question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create a pipe of input and output for wav to mp3 encoding

See original GitHub issue

I 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:open
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
RobertLuciancommented, Jul 6, 2020

@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 the stdin.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:

process = (
        ffmpeg.input("pipe:", format="rawvideo", pix_fmt="rgb24", s=f"{width}x{height}")
        .output("pipe:", format="matroska", pix_fmt="yuv420p")
        .run_async(pipe_stdin=True, pipe_stdout=True)
)

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:

process = (
        ffmpeg.input("pipe:", format="rawvideo", pix_fmt="rgb24", s=f"{width}x{height}")
        .output(file_path, pix_fmt="yuv420p")
        .run_async(pipe_stdin=True)
)
2reactions
Vulcanostrolcommented, Apr 10, 2021

Is there an update on this? I would imagine piping is something we would want to have working well?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found