gpt4 book ai didi

c# - 如何在 C# WPF 应用程序中获取 FFMPEG 转换进度到进度条?

转载 作者:行者123 更新时间:2023-12-04 23:02:49 28 4
gpt4 key购买 nike

所以我使用下面的代码通过运行 ffmpeg 转换指定的文件,并且我需要在进度条中显示进度,所以我需要让它实时显示 cmd 输出到我的文本框让它被进度条显示,有什么帮助吗?

 private void convertbutton_Click(object sender, RoutedEventArgs e)
{
string resdir = AppDomain.CurrentDomain.BaseDirectory + "\\res";
Extract("ADC", AppDomain.CurrentDomain.BaseDirectory + "\\res", "res", "ffmpeg.exe");

string ffdir = AppDomain.CurrentDomain.BaseDirectory + "\\res\\ffmpeg.exe";
string arg = @"-y -activation_bytes ";
string arg1 = @" -i ";
string arg2 = @" -ab 80k -vn ";
string abytes = bytebox.Text;
string arguments = arg + abytes + arg1 + openFileDialog1.FileName + arg2 + saveFileDialog1.FileName;

Process ffm = new Process();
ffm.StartInfo.FileName = ffdir;
ffm.StartInfo.Arguments = arguments;
ffm.StartInfo.CreateNoWindow = true;
ffm.StartInfo.RedirectStandardOutput = true;
ffm.StartInfo.RedirectStandardError = true;
ffm.StartInfo.UseShellExecute = false;
ffm.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory();
ffm.Start();

ffm.WaitForExit();
ffm.Close();

Directory.Delete(resdir, true);
}

FFMPEG 输出通常如下所示:
size=    4824kB time=00:08:13.63 bitrate=  80.1kbits/s speed=  33x

最佳答案

您没有显示进度查看器的代码,但这是您获得 ffmpeg.exe 输出的方式和(仅相关部分):

Process ffm = new Process()
{
RedirectStandardError = true,
RedirectStandardOutput = true
};

ffm.OutputDataReceived += this.HandleOutputData;
ffm.ErrorDataReceived += this.HandleErrorData;

在这些方法中,您可以处理对 TextBox 的写入和观众:
private void HandleOutputData(object sender, DataReceivedEventArgs e)
{
// The new data is contained in e.Data
MyProgressViewer.Update(e.Data);
this.myTextBox.Text += e.Data;
}

private void HandleErrorData(object sender, DataReceivedEventArgs e)
{
// The new data is contained in e.Data
MyProgressViewer.Update(e.Data);
this.myTextBox.Text += e.Data;

// Additional error handling here.
}

至于解析:显然,

ffmpeg now has a progress option, which gives output more easily parsed.



this answer更多细节。

关于c# - 如何在 C# WPF 应用程序中获取 FFMPEG 转换进度到进度条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49362864/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com