Skip to content

Commit

Permalink
better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatNerdUKnow committed May 1, 2022
1 parent 828fbc9 commit 07983ab
Showing 1 changed file with 56 additions and 29 deletions.
85 changes: 56 additions & 29 deletions vmaf-gui/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ string ChildProcess(string program_name, string args, bool show)
p.StartInfo.FileName = program_name;
p.StartInfo.Arguments = args;

p.StartInfo.RedirectStandardError = true;


p.Start();

Expand All @@ -39,6 +41,16 @@ string ChildProcess(string program_name, string args, bool show)
Console.WriteLine(args);

p.WaitForExit();

int exitCode = p.ExitCode;

if(exitCode != 0)
{
throw new Exception(p.StandardError.ReadToEnd());
}



return output;
}

Expand Down Expand Up @@ -135,35 +147,48 @@ private void button1_Click(object sender, EventArgs e)
ThreadStart tStart = new ThreadStart(
() =>
{
try
{
// Decompress source video file
lblProgress.Invoke(new Action(delegate () { lblProgress.Text = "Decompressing Source..."; }));
decompressVideo(sourcePath, "./temp/source.y4m");
prgProgress.Invoke(new Action(delegate () { prgProgress.PerformStep(); }));

// Decompress compressed video file
lblProgress.Invoke(new Action(delegate () { lblProgress.Text = "Decompressing Compressed..."; }));
decompressVideo(compressedPath, "./temp/compressed.y4m");
prgProgress.Invoke(new Action(delegate () { prgProgress.PerformStep(); }));


// Start vmaf
vmaf(resolution, model, psnr, ssim);
prgProgress.Invoke(new Action(delegate () { prgProgress.PerformStep(); }));


// Done
prgProgress.Invoke(new Action(delegate () { prgProgress.PerformStep(); }));
lblProgress.Invoke(new Action(delegate () { lblProgress.Text = "Done."; }));

// Clean up form controls and delete .yuv files to save disk space
lblProgress.Invoke(new Action(delegate () { lblProgress.Text = ""; }));
File.Delete("./temp/compressed.yuv");
File.Delete("./temp/source.yuv");
button1.Invoke(new Action(delegate () { button1.Enabled = true; }));

// Show Results
results resultsForm = new results();
resultsForm.showResults("./log.xml");
resultsForm.ShowDialog();
}catch
{
prgProgress.Invoke(new Action(delegate () {
prgProgress.Value = 0;
}));
lblProgress.Invoke(new Action(delegate () { lblProgress.Text = "There was a problem running VMAF"; }));
button1.Invoke(new Action(delegate () { button1.Enabled = true; }));


// Decompress source video file
lblProgress.Invoke(new Action(delegate () { lblProgress.Text = "Decompressing Source..."; }));
decompressVideo(sourcePath, "./temp/source.y4m");
prgProgress.Invoke(new Action(delegate () { prgProgress.PerformStep(); }));

// Decompress compressed video file
lblProgress.Invoke(new Action(delegate () { lblProgress.Text = "Decompressing Compressed..."; }));
decompressVideo(compressedPath, "./temp/compressed.y4m");
prgProgress.Invoke(new Action(delegate () { prgProgress.PerformStep(); }));

// Start vmaf
vmaf(resolution, model, psnr, ssim);
prgProgress.Invoke(new Action(delegate () { prgProgress.PerformStep(); }));

// Done
prgProgress.Invoke(new Action(delegate () { prgProgress.PerformStep(); }));
lblProgress.Invoke(new Action(delegate () { lblProgress.Text = "Done."; }));

// Clean up form controls and delete .yuv files to save disk space
lblProgress.Invoke(new Action(delegate () { lblProgress.Text = ""; }));
File.Delete("./temp/compressed.yuv");
File.Delete("./temp/source.yuv");
button1.Invoke(new Action(delegate () { button1.Enabled = true; }));

// Show Results
results resultsForm = new results();
resultsForm.showResults("./log.xml");
resultsForm.ShowDialog();
}

}

Expand All @@ -175,6 +200,7 @@ private void button1_Click(object sender, EventArgs e)
}
catch (Exception err)
{

MessageBox.Show(err.Message);
}
}
Expand Down Expand Up @@ -221,7 +247,8 @@ void vmaf(string resolution, string model, bool psnr, bool ssim)
ChildProcess("vmaf.exe", args, false);
}catch(Exception err)
{
MessageBox.Show(err.Message);
MessageBox.Show(err.Message,"There was a problem with VMAF");
throw new Exception();
}


Expand Down

0 comments on commit 07983ab

Please sign in to comment.