所以我使用下面的代码通过运行ffmpeg来转换一个指定的文件,我需要进度在一个进度条中是可见的,所以I#d需要让它实时地将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发布于 2018-03-19 12:43:59
您没有显示进度查看器的代码,但这是如何获得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现在有一个进度选项,它使输出更容易被解析。
有关更多详细信息,请参阅this answer。
https://stackoverflow.com/questions/49362864
复制相似问题