1

I can run FFmpeg.exe -i test.flv -f flv - | ffplay -i - in the cmd, But I can't run it in the c# codes when "|" is in argument.

This code works :

  Process process = new Process();
  process process .StartInfo.FileName = "FFmpeg.exe";
  process process .StartInfo.Arguments =" -i test.flv "
  process .Start();

But this code is not working :

  Process process = new Process();
  process process .StartInfo.FileName = "FFmpeg.exe";
  process process .StartInfo.Arguments =" -i test.flv -f flv - | ffplay -i -"
  process .Start();

I tried this codes but did not effect:

   process process .StartInfo.Arguments =" -i test.flv -f flv - \| ffplay -i -"

   process process .StartInfo.Arguments =" -i test.flv -f flv - \\| ffplay -i -"

   process process .StartInfo.Arguments =@" -i test.flv -f flv - | ffplay -i -"

   process process .StartInfo.Arguments ="\" -i test.flv -f flv - \| ffplay -i -\""

Please tell me how can I run FFmpeg.exe -i test.flv -f flv - | ffplay -i - in the C# codes.

Maria
  • 344
  • 8
  • 30

1 Answers1

4

Piping the output from one command to another is a feature of the shell in which you execute those commands. In .NET, using the Process class you need to use a shell (usually cmd.exe) to achieve the same effect.

// usually expands to `C:\Windows\System32\cmd.exe`
process.StartInfo.FileName = Environment.ExpandEnvironmentVariables("%COMSPEC%"); 
// Build a command line passed to CMD.EXE
process.StartInfo.Arguments = "/C FFmpeg.exe -i test.flv -f flv - | ffplay -i -"

Additionally, depending on your use case, you normally want to wait for the process to finish:

process.WaitForExit();

And possible evaluate the exit code

if (process.ExitCode != 0) // Convention only! Usually, an exit of 0 means error. YMMV.

Finally, note that for pipelines, the exit code returned here is the exit code of the last command (in your case ffplay).

Christian.K
  • 47,778
  • 10
  • 99
  • 143