-1

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

pm100
  • 48,078
  • 23
  • 82
  • 145
franznkemaka
  • 153
  • 1
  • 1
  • 9
  • Are you sure it doesn't mean "event" and not even? In which case I would see what property I need to assign an expression to, probably using a lambda. I'm unfamiliar with this framework, but if you wanted to add a function to a button click event is would be something like button.onClick += (s,e) => DoSomething(); – Kirkland Dec 14 '17 at 18:17
  • What is pgbConversion? Is that a progress bar? – Gareth Jun 12 '19 at 17:48

2 Answers2

2

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:

enter image description here

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:

enter image description here

(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")

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
1

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.

Kirkland
  • 798
  • 1
  • 8
  • 20
  • thanks, please i have an eror here : pgbConversion.Value = it shows that it is non-static – franznkemaka Dec 14 '17 at 20:22
  • Could you add the code? Is the class that pgbConversion instantiates a standard part of the .NET library? – Kirkland Dec 14 '17 at 20:49
  • 1
    How come you switched away from using the lambda version? I thought that was quite neat.. – Caius Jard Dec 14 '17 at 20:56
  • Wasn't directly relevant to the question. I wanted to prioritize what was specifically being asked over the technical level of the answer. Since you've asked, however, I can add it :) – Kirkland Dec 14 '17 at 21:18