Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set ffmpeg pipe output?

I need to read ffmpeg output as pipe. There is a code example:

    public static void PipeTest()
    {
        Process proc = new Process();
        proc.StartInfo.FileName = Path.Combine(WorkingFolder, "ffmpeg");
        proc.StartInfo.Arguments = String.Format("$ ffmpeg -i input.mp3 pipe:1");
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.RedirectStandardInput = true;
        proc.StartInfo.RedirectStandardOutput = true;
        proc.Start();

        FileStream baseStream = proc.StandardOutput.BaseStream as FileStream;
        byte[] audioData;
        int lastRead = 0;

        using (MemoryStream ms = new MemoryStream())
        {
            byte[] buffer = new byte[5000];
            do
            {
                lastRead = baseStream.Read(buffer, 0, buffer.Length);
                ms.Write(buffer, 0, lastRead);
            } while (lastRead > 0);

            audioData = ms.ToArray();
        }

        using(FileStream s = new FileStream(Path.Combine(WorkingFolder, "pipe_output_01.mp3"), FileMode.Create))
        {
            s.Write(audioData, 0, audioData.Length);
        }
    }

It's log from ffmpeg, the first file is readed:

Input #0, mp3, from 'norm.mp3': Metadata: encoder : Lavf58.17.103 Duration: 00:01:36.22, start: 0.023021, bitrate: 128 kb/s Stream #0:0: Audio: mp3, 48000 Hz, stereo, fltp, 128 kb/s Metadata: encoder : Lavc58.27

Then pipe:

[NULL @ 0x7fd58a001e00] Unable to find a suitable output format for '$' $: Invalid argument

If I run "-i input.mp3 pipe:1", the log is:

Unable to find a suitable output format for 'pipe:1' pipe:1: Invalid argument

How do I set correct output? And how should ffmpeg know what the output format is at all?

like image 349
mr_blond Avatar asked Mar 27 '26 13:03

mr_blond


2 Answers

Whenever you use a pipe out in ffmpeg, you need the -f fmt parameter to avoid the error you are seeing.

You can get a list of possible formats by typing ffmpeg -formats.

If you want a wav file for instance, add -f wav.

In your example, arguments should be:

-i input.mp3 -f wav pipe:1

You can replace wav with flac or any other audio format you like.

like image 126
PRMan Avatar answered Mar 30 '26 02:03

PRMan


Looks to me like there's a typo in "$ ffmpeg -i input.mp3 pipe:1". If you just want to invoke ffmpeg with options like -i and so on, leave out the $ character. Just "ffmpeg -i input.mp3 pipe:1".. You already pass the main program name in StartInfo.FileName. So you should probably leave that out too. Try just "-i input.mp3 pipe:1" as your Arguments.

like image 34
omajid Avatar answered Mar 30 '26 01:03

omajid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!