如何格式化字符串ffmpeg参数将参数传递给文本框?

发布于 2025-02-11 06:47:37 字数 2039 浏览 0 评论 0原文

我创建了此表格:

“

我想使用变量ffmpegarguments将参数从文本框传递到ffmpeg类参数。问题在于,在FFMPEG类中,我正在使用这些变量:

文件名和Framerate,因此如何使用文件名和FRAMETER变量将从文本框的输入格式化为FFMPEG参数?

在FFMPEG类中:

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

I created this form :

arguments

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文