Skip to content

Commit

Permalink
Merge pull request #8 from ThatNerdUKnow/resultsForm
Browse files Browse the repository at this point in the history
Results form
  • Loading branch information
ThatNerdUKnow authored Apr 30, 2022
2 parents 56a7fa9 + d4d1328 commit 2748034
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 37 deletions.
71 changes: 34 additions & 37 deletions vmaf-gui/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Xml;
using System.Threading;
using System.Windows.Forms;

namespace vmaf_gui
{
Expand All @@ -20,11 +14,11 @@ public Form1()
InitializeComponent();
}


string ChildProcess(string program_name, string args, bool show)
{


// Spawn a child process. We don't need output from stdout so we don't capture it
var p = new Process();
p.StartInfo.UseShellExecute = false;
Expand All @@ -33,17 +27,17 @@ string ChildProcess(string program_name, string args, bool show)
p.StartInfo.FileName = program_name;
p.StartInfo.Arguments = args;


p.Start();


// p.standardoutput is an input stream

string output = "";

Console.WriteLine(program_name);
Console.WriteLine(args);

p.WaitForExit();
return output;
}
Expand Down Expand Up @@ -72,17 +66,17 @@ private void compressedFileDialog_FileOk(object sender, CancelEventArgs e)

private void Form1_Load(object sender, EventArgs e)
{

//cmbResolution.SelectedIndex = 1;

// Get list of model files and add them to the cmbModel form control
string[] models = Directory.GetFiles(".\\model");
foreach (string model in models)
{
string safeName = model.Substring(8, model.Length - 8);
if (!safeName.Contains(".model")&& safeName.Contains(".json"))
if (!safeName.Contains(".model") && safeName.Contains(".json"))
{
// cmbModel.Items.Add(safeName);
// cmbModel.Items.Add(safeName);
}
}
try
Expand All @@ -99,17 +93,17 @@ private void Form1_Load(object sender, EventArgs e)
private void button1_Click(object sender, EventArgs e)
{
prgProgress.Value = 0;

try
{

originalFileDialog.OpenFile();
compressedFileDialog.OpenFile();

originalFileDialog.Dispose();
compressedFileDialog.Dispose();

string sourcePath ="\""+ originalFileDialog.FileName + "\"";
string sourcePath = "\"" + originalFileDialog.FileName + "\"";
string compressedPath = "\"" + compressedFileDialog.FileName + "\"";

Console.WriteLine(sourcePath);
Expand All @@ -136,7 +130,8 @@ private void button1_Click(object sender, EventArgs e)

// Define what functions the thread does
ThreadStart tStart = new ThreadStart(
() => {
() =>
{

// Decompress source video file
lblProgress.Invoke(new Action(delegate () { lblProgress.Text = "Decompressing Source..."; }));
Expand All @@ -152,18 +147,21 @@ private void button1_Click(object sender, EventArgs e)
vmaf(resolution, model, psnr, ssim);
prgProgress.Invoke(new Action(delegate () { prgProgress.PerformStep(); }));

// Show results in notepad
// Done
prgProgress.Invoke(new Action(delegate () { prgProgress.PerformStep(); }));
lblProgress.Invoke(new Action(delegate () { lblProgress.Text = "Done."; }));
ChildProcess("notepad", "log.xml", true);



// 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 @@ -183,25 +181,25 @@ private void button1_Click(object sender, EventArgs e)
}
}

void decompressVideo(string path,string output)
void decompressVideo(string path, string output)
{
try
{
// Use ffmpeg to decompress the video into .yuv file
ChildProcess("ffmpeg.exe", "-y -i " + path + " -pix_fmt yuv420p -vsync 0 "+ output,false);
ChildProcess("ffmpeg.exe", "-y -i " + path + " -pix_fmt yuv420p -vsync 0 " + output, false);
}
catch (Exception err)
{
MessageBox.Show(path, err.Message);
}
}

void vmaf(string resolution,string model,bool psnr,bool ssim)
void vmaf(string resolution, string model, bool psnr, bool ssim)
{
// Build arguments list for vmaf
//string args = "yuv420p "+ resolution +" ./temp/source.yuv ./temp/compressed.yuv .\\model\\"+ model +" --log log.xml";
Array res = resolution.Split(' ');

string args = $"--threads 4 --reference ./temp/source.y4m --distorted ./temp/compressed.y4m -o log.xml";
/*
if (chkPSNR.Checked)
Expand All @@ -213,18 +211,17 @@ void vmaf(string resolution,string model,bool psnr,bool ssim)
args += " --ssim";
}*/

//lblProgress.Text = "Performing VMAF...";
lblProgress.Invoke(new Action(delegate () { lblProgress.Text = "Performing VMAF..."; }));

ChildProcess("vmaf.exe",args ,false);
ChildProcess("vmaf.exe", args, false);







}


}


}
87 changes: 87 additions & 0 deletions vmaf-gui/results.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions vmaf-gui/results.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using System.Xml.Linq;

namespace vmaf_gui
{
public partial class results : Form
{
public results()
{
InitializeComponent();
}

public void showResults(string path)
{
var doc = XDocument.Load(path);

var frames = from frame in doc.Root.Descendants("frame")
select frame;

double total = 0;
foreach (var frame in frames)
{
double frameNum = double.Parse(frame.Attribute("frameNum").Value);
double vmafScore = double.Parse(frame.Attribute("vmaf").Value);
total += vmafScore;
this.resultsChart.Series["VMAF"].Points.AddXY(frameNum, vmafScore);
}

double average = Math.Round(total / frames.ToArray().Length,2);

label1.Text = "VMAF: " + average;
}
}
}
Loading

0 comments on commit 2748034

Please sign in to comment.