AydinAdn/MediaToolkit

Feature request: Raising OnErrorThrownEventArgs instead of an exception when an error occurs in FFmpeg

Opened this issue · 3 comments

This is more like an suggestion than an issue:

I would like to be able to handle public Engine.OnError event if an error occurs from FFMpeg.

Currently it is privatly handled in the Engine.FFmpegProcess.ErrorDataReceived but AFAIK it does not notify user about it. Instead, it should invoke the OnError event handler. The user then could log the error and decide if the process should be canceled or ignored.

The issue is that FFmpeg writes to STDERR, so we can only read the output from ErrorDataReceived. This is how we raise progress events and completion events by reading the output and attempting to serialise it,

If FFmpeg exits with errors, it will return an ExitCode of something other than 0 or 1, in such situations the an exception is composed and thrown. You can find the code below in Engine.cs at the end,

if ((this.FFmpegProcess.ExitCode != 0 && this.FFmpegProcess.ExitCode != 1) || caughtException != null)
{
    throw new Exception(
    this.FFmpegProcess.ExitCode + ": " + receivedMessagesLog[1] + receivedMessagesLog[0],
    caughtException);
}

That is all fine but instead of throwing a new exception would it not be great if the OnError event is invoked? Ofcourse, if no OnError event handler is attached an exception is thrown.

Ah my bad, I misunderstood you. I like that idea!

If I'm honest... I want to bulldoze the entire thing and rebuild from scratch, sometimes I wonder if I was drunk the entire time I was writing the damn thing.