I'm trying to pipe some stream to ffmpeg and capture it's output so that I can pass on another stream in my code.
Here is a code example, that just stops the process from continuing after I write to its StandardInput.BaseStream
.
internal class Program
{
private static void Main(string[] args)
{
var inputFile = @"C:\Temp\test.mp4";
var outputFile = @"C:\Temp\test.mp3";
var process = new Process
{
StartInfo = new ProcessStartInfo
{
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
Arguments = "-i - -f mp3 -",
FileName = "ffmpeg.exe"
},
EnableRaisingEvents = true
};
process.ErrorDataReceived += (sender, eventArgs) => Console.WriteLine(eventArgs.Data);
process.Start();
process.BeginErrorReadLine();
using (var input = new FileStream(inputFile, FileMode.Open))
using (var output = new FileStream(outputFile, FileMode.Create))
{
input.CopyTo(process.StandardInput.BaseStream);
process.StandardOutput.BaseStream.CopyTo(output);
}
process.WaitForExit();
Console.WriteLine("done");
Console.ReadLine();
}
}
This example is pretty much the same as in the answer in this question: https://stackoverflow.com/a/8999542/2277280
What am I doing wrong? Why does the process not continue? Is it ffmpeg specific?