views:

163

answers:

1

I want to do something like this

ffmpeg -i audio.mp3 -f flac - | oggenc2.exe - -o audio.ogg

i know how to do ffmpeg -i audio.mp3 -f flac using the process class in .NET but how do i pipe it to oggenc2?

Any example of how to do this (it doesnt need to be ffmpeg or oggenc2) would be fine.

+3  A: 

OK, I wrote the following code to do this:

    Process ffmpeg = new Process
    {
        StartInfo = new ProcessStartInfo
        {
            FileName = "ffmpeg.exe",
            Arguments = "-i audio.mp3 -f flac -",
            UseShellExecute = false,
            RedirectStandardOutput = true,
            WindowStyle = ProcessWindowStyle.Hidden
        }
    };
    Process oggenc2 = new Process
    {
        StartInfo = new ProcessStartInfo
        {
            FileName = "oggenc2.exe",
            Arguments = "- -o audio.ogg",
            UseShellExecute = false,
            RedirectStandardInput = true,
            WindowStyle = ProcessWindowStyle.Hidden
        }
    };

    ffmpeg.Start();
    oggenc2.Start();

    int bufferLength = 4096;
    var input = oggenc2.StandardInput.BaseStream;
    var output = ffmpeg.StandardOutput.BaseStream;

    using (BinaryWriter writer = new BinaryWriter(input))
    {
        using (BinaryReader r = new BinaryReader(output))
        {
            byte[] buffer = new byte[bufferLength];
            int bytesRead;
            do
            {
                bytesRead = r.Read(buffer, 0, bufferLength);
                writer.Write(buffer, 0, bytesRead);
            } while (bytesRead > 0);
        }
    }

    ffmpeg.WaitForExit();

Hope, this helps.

Alex
amazing answer thanks a lot! :| !! :)
acidzombie24