I'm working on a C# application where I'm using FFmpeg to encode multiple video files. I want to display a progress bar to show the encoding progress for each video. I have tried using the Process.OutputDataReceived event to capture FFmpeg's progress updates, but it doesn't seem to work reliably.
Here's the relevant part of my code:
// Code snippet
int i = 1;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
progressBar1.Maximum = openFileDialog1.FileNames.Length;
foreach (string file in openFileDialog1.FileNames)
{
// Output file naming code here
Process process = new Process();
process.StartInfo.FileName = "ffmpeg.exe";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.UseShellExecute = false;
process.OutputDataReceived += (sender, e) =>
{
// Progress parsing code here
// This part doesn't seem to receive any data
};
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
i++;
}
}
However, the OutputDataReceived event doesn't seem to receive any data from FFmpeg's stderr, and the progress bar doesn't update as expected.
Is there a better way to capture FFmpeg's progress updates for encoding videos and use them to update the progress bar in C#? How can I achieve this?
Any help or suggestions would be greatly appreciated. Thank you!