1

I am developing a Windows Form program that has callings to ffmpeg library through the class Process.

It works fine when I run it with the Debug in Visual Studio 2013. But when I install the program and I invoke the operation that call to the ffmpeg Process, it doesn't work. The cmd screen appears an disappears and nothing happens.

I have tried to know what can be happening getting a log file with the output of ffmpeg, in case it was a problem in the ffmpeg libraries. However, after executing it the log is empty, what means that the ffmpeg command has not been executed.

Can someone help me, please?

The code is this:

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/c " + ffmpegPath + " " + commandArguments;
using (Process processTemp = new Process())
{
    processTemp.StartInfo = startInfo;
    processTemp.EnableRaisingEvents = true;
    processTemp.Start();
    processTemp.WaitForExit();
}

I am invoking to cmd.exe (not directly ffmpeg.exe) because in the arguments sometimes there can be a pipe (that is why the command starts with "/c").

Reza Aghaei
  • 103,774
  • 12
  • 145
  • 300
Santi
  • 33
  • 4
  • where do you put your breakpoint when in debug ? Try setting it after the WaitForExit. Does it still works then ? – GuidoG Feb 05 '19 at 15:52
  • When I am debugging it always works fine, I mean, when I execute it from Visual Studio it always works fine (with breakpoints or without breakpoints), but when I execute the intalled program it doen't so. – Santi Feb 06 '19 at 10:02
  • I want to do an aclaration... After doing another tests, I have discovered that the problems is related to the Arguments value: When I take the value of Arguments and write it directly in a cmd window, it doesn't work, but, if I remove the "/c" of the beginning it works ok. However, if I remove "/c" from the code and I execute the program, when the Process is start the cmd windows is open but the command is not executed (the comand contains a pipe &&)... I don't understand it. Can someone help? – Santi Feb 06 '19 at 10:21
  • [Piping to ffmpeg.exe with C#](https://mathewsachin.github.io/blog/2017/07/28/ffmpeg-pipe-csharp.html). Simple: [C# and FFmpeg preferably without shell commands?](https://stackoverflow.com/a/1733516/7444103). – Jimi Feb 06 '19 at 10:56
  • [Unable to read Process.StandardOutput from FFMPEG process](https://social.msdn.microsoft.com/Forums/vstudio/en-US/0fdc2df8-12b9-47e4-817c-ff02d9f0063c/unable-to-read-processstandardoutput-from-ffmpeg-process?forum=csharpgeneral). [How can i calculate the percentages progress of Process and report to backgroundworker ?](https://social.msdn.microsoft.com/Forums/vstudio/en-US/98915570-ccf4-49ed-ab1e-a9794ef5154e/how-can-i-calculate-the-percentages-progress-of-process-and-report-to-backgroundworker-?forum=csharpgeneral) – Jimi Feb 06 '19 at 10:56
  • BTW, `EnableRaisingEvents` is only used to raise (and handle) the `Exited` event (asynchronous processing). Not compatible with `WaitForExit()` (synchronous). Read from `StandardError`. As an alternative, use a FFMPEG library for .Net (or go directly to [Accord.NET](http://accord-framework.net/)). – Jimi Feb 06 '19 at 10:58
  • Or (redux) [FFmpeg.AutoGen](https://www.nuget.org/packages/FFmpeg.AutoGen/). – Jimi Feb 06 '19 at 11:22
  • Thank you very much, Jimi. All the information you have given me is very usefull. However, the fact it is that the first command in the pipe is a command ffmpeg (to create a HLS video) and the second one is a "echo" command. I am doing like that because in the second command creates the master.m3u8 playlist for the HLS (I don't manage to do it with the control "-master_pl_name" of ffmpeg) – Santi Feb 06 '19 at 11:39
  • Anyway, I will try to investigate the tool FFmpeg.AutoGen in order to try to create the HLS in another way. Thank you! – Santi Feb 06 '19 at 11:40

2 Answers2

0

Are you sure this isn't a privileges issue when trying to execute the cmd.exe (e.g you need administrator privileges)

try adding

startInfo.Verb = "runas";

Paul

  • I don't think so. I have an app.manifest with level="requireAdministrator" and anyway I also tried to do it with startInfo.Verb = "runas" and it doesn't work yet. – Santi Feb 06 '19 at 09:08
0

Hmm its not a path issue with spaces in file/directory names is it? For ffmpegPath or one of your command parameters (if a file path). Surround all file paths with ' like below.

Try surrounding any file paths with '

 startInfo.Arguments = "/c '" + ffmpegPath + "' " + commandArguments;

Also you could try adding /K to the cmd command call to stop if from closing the command prompt when it finishes. It might tell you the error before it closes the window but you wont see it if it closes so quickly

Good luck :) Paul