Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process stalls when launched in .NET (ffmpeg)

I'm trying to launch ffmpeg as a Process in .NET (C#), but in some cases, depending on the arguments (specifically, if I omit video arguments in order to create an audio file), it's stalling. It launches, outputs some lines, but then just stalls (using 0% CPU). When the parent .NET process is killed, it continues, and if I let it continue, ffmpeg produces the file correctly. I thought it might be due to using Peek() to look at the stream, so I just simplified it to the following, which behaves the same:

_process = new Process
{
    StartInfo =
    {
        UseShellExecute = false,
        RedirectStandardOutput = false,
        RedirectStandardError = true,
        FileName = "c:\\ffmpeg.exe",
        Arguments = string.Format(
    "-i {0} {1} {2} {3} -y {4}", inputPath, videoArgs, audioArgs, options, outputPath)
    }
};
_process.Start();
_process.WaitForExit();

ffmpeg gets to the point where it outputs information about the input video/audio streams before stalling. Executing the command via the command prompt works as expected.

Does anyone know what the problem could be?

Edit:

Just to add, I tried UseShellExecute = true (and RedirectStandardError = false), and this works. I still need to read the output, however, so this doesn't really help me.

like image 317
Rhys Causey Avatar asked Nov 16 '11 17:11

Rhys Causey


1 Answers

Have a read of this MSDN on RedirectStandardError

Apparently this is a bit fiddly and can deadlock if the output or error stream buffers get filled up. Sit's there waiting for you to read what it's wrote...

like image 120
Tony Hopkinson Avatar answered Sep 23 '22 22:09

Tony Hopkinson