Reputation: 446
I have this code:
string d = "-f image2 -framerate 9 -i E:\\REC\\Temp\\%06d.jpeg -r 30 E:\\REC\\Video\\" + label1.Text + ".avi";
//string d = "-f dshow -i video=\"screen-capture-recorder\" E:\\REC\\" + label1.Text + ".flv";
Process proc = new Process();
proc.StartInfo.FileName = "E:\\ffmpeg\\bin\\ffmpeg.exe";
proc.StartInfo.Arguments = d;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
if (!proc.Start())
{
Console.WriteLine("Error starting");
return;
}
proc.WaitForExit();
When it runs the ffmpeg.exe
is there like this:
My question is how to hide this window?
Upvotes: 3
Views: 3165
Reputation: 1819
This on keeps the all processes in same console window. no allow to open an new one`
Process process = new Process();
// Stop the process from opening a new window
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
// Setup executable and parameters
process.StartInfo.FileName = @"E:\\ffmpeg\\bin\\ffmpeg.exe"
//Optional
string d = "-f image2 -framerate 9 -i E:\\REC\\Temp\\%06d.jpeg -r 30 E:\\REC\\Video\\" + label1.Text + ".avi";
process.StartInfo.Arguments = d;
// Go
process.Start();
Upvotes: 1
Reputation: 613461
You need the following combination of settings:
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
And that's it.
The reason being that the key setting is CreateNoWindow
which has to be true
. But CreateNoWindow
only has any effect when UseShellExecute
is false
. That's because CreateNoWindow
maps to the CREATE_NO_WINDOW
process creation flag passed to CreateProcess
. And CreateProcess
is only called when UseShellExecute
is false
.
More information can be found from the documentation:
Property Value
true if the process should be started without creating a new window to contain it; otherwise, false. The default is false.
Remarks
If the UseShellExecute property is true or the UserName and Password properties are not null, the CreateNoWindow property value is ignored and a new window is created.
Upvotes: 3