1,931 questions
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();
}
}