Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,921 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I created this form :
I want to use the variable ffmpegArguments to pass the arguments from the textBox to the ffmpeg class arguments. the problem is that in the ffmpeg class i'm using the variables :
FileName and Framerate so how can i format the input from the textBox to the ffmpeg arguments with the FileName and Framerate variables ?
In the ffmpeg class :
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Capture_Screen
{
internal class FFmpeg_Capture
{
public string workingDirectory;
public string outputDirectory;
public string ffmpegArguments;
private Process process;
public FFmpeg_Capture()
{
}
public void Start(string FileName, int Framerate)
{
process = new Process();
process.StartInfo.FileName = outputDirectory; // Change the directory where ffmpeg.exe is.
process.EnableRaisingEvents = false;
process.StartInfo.WorkingDirectory = workingDirectory; // The output directory
process.StartInfo.Arguments = @"-y -f gdigrab -framerate " + Framerate +
" -i desktop -preset ultrafast -pix_fmt yuv420p " + FileName;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true; //Redirect stdin
process.StartInfo.CreateNoWindow = true;
process.Start();
}
public void Stop()
{
byte[] qKey = Encoding.GetEncoding("gbk").GetBytes("q"); //Get encoding of 'q' key
process.StandardInput.BaseStream.Write(qKey, 0, 1); //Write 'q' key to stdin of FFmpeg sub-processs
process.StandardInput.BaseStream.Flush(); //Flush stdin (just in case).
process.Close();
process.Dispose();
}
}
}
Why not pass information in the constructor as shown below?
internal class FFmpeg_Capture
{
public string OutputDirectory { get; protected set; }
public string WorkingDirectory { get; protected set; }
public string FfmpegArguments { get; protected set; }
private Process process;
public FFmpeg_Capture(string outputDirectory, string workingDirectory, string ffmpegArguments)
{
OutputDirectory = outputDirectory;
WorkingDirectory = workingDirectory;
FfmpegArguments = ffmpegArguments;
}
public void Start(string FileName, int Framerate)
{
process = new Process();
process.StartInfo.FileName = OutputDirectory; // Change the directory where ffmpeg.exe is.
process.EnableRaisingEvents = false;
process.StartInfo.WorkingDirectory = WorkingDirectory; // The output directory
process.StartInfo.Arguments = $@"-y -f gdigrab -framerate {Framerate}" +
$" -i desktop -preset ultrafast -pix_fmt yuv420p {FileName}";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true; //Redirect stdin
process.StartInfo.CreateNoWindow = true;
process.Start();
}
public void Stop()
{
byte[] qKey = Encoding.GetEncoding("gbk").GetBytes("q"); //Get encoding of 'q' key
process.StandardInput.BaseStream.Write(qKey, 0, 1); //Write 'q' key to stdin of FFmpeg sub-processs
process.StandardInput.BaseStream.Flush(); //Flush stdin (just in case).
process.Close();
process.Dispose();
}
}