How to format string the ffmpeg arguments to pass the arguments to a textBox?

Chocolade 516 Reputation points
2022-06-28T21:51:47.857+00:00

I created this form :

nGpiD.jpg

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();  
        }  
    }  
}  
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,833 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,274 questions
0 comments No comments
{count} vote

Accepted answer
  1. Karen Payne MVP 35,036 Reputation points
    2022-06-28T22:36:34.917+00:00

    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();  
        }  
    }  
    
    0 comments No comments

0 additional answers

Sort by: Most helpful