This question already has an answer here:
I am coding a video converter using NRECO and ffmpeg everything works but when it comes at to get the Progress time i've tried
pgbConversion.Value = FFMpegConverter.ConvertProgress();
but it is impossible so i got ! ** **ConvertProgress is an even; please check C# documentation about how to add an even handler.****
from NReco please how can i get the video progress knowing that ConvertProgrss is an event
You write this:
FFMpegConverter.ConvertProgress +=
Your Visual Studio starts helping you out by offering to attach event handler code to the ConvertProgress event for you. It will show you a pop up, like MY visual studio is doing here, in this screenshot of me attaching an event handler to a Timer.Elapsed event, which is a totally different event, on a different object, that I'm using as an example to demonstrate how visual studio helps you attach events to things:
Then you press TAB in YOUR visual studio to accept the suggestion in the pop up
Visual Studio will scaffold a basic event handler for you, and you can add your code into it that you want to be run every time the event is raised. Here is what my visual studio did when I pressed tab during adding an event handler to my example using Timer:
(Naturally my pics show VS making a handler for Timer.Elapsed, not FFMpegConverter.ConvertProgress, because I have Timer, but I don't have that FFMpegConverter class.. "Pics are for illustration purposes only - you are NOT supposed to type the code you see in my pictures")
Are you sure it's not a typo and they mean "Event"? In which case I would assign lambda expression to the event, or you could just reference another method as seen below, so the documentation would be here: Lambda Expressions, Events.
Example w/o Lambda:
static void Main(string[] args)
{
var ffMpeg = new FFMpegConverter();
ffMpeg.ConvertProgress += FfMpeg_ConvertProgress;
ffMpeg.ConvertMedia("input.mov", "output.mp4", Format.mp4);
}
private static void FfMpeg_ConvertProgress(object sender, ConvertProgressEventArgs e)
{
// Percent complete as a double
pgbConversion.Value = e.Processed.TotalSeconds / e.TotalDuration.TotalSeconds;
}
Example w/ Lambda expression:
static void Main(string[] args)
{
var ffMpeg = new FFMpegConverter();
ffMpeg.ConvertProgress += (s, e) => {
pgbConversion.Value = e.Processed.TotalSeconds / e.TotalDuration.TotalSeconds;
};
ffMpeg.ConvertMedia("input.mov", "output.mp4", Format.mp4);
}
The event only has the total number of seconds in the video and the number of seconds that's been processed. They are also represented as TimeSpan objects. I'd advise getting the total number of seconds of each of these (returning a double), and then dividing to get a percentage complete. Of course you could use either of them as TimeSpan instances individually.