From 7cfbe9a7d316631049acf5b267d9b9a2e4084c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brandon=20Pi=C3=B1a?= Date: Sat, 30 Apr 2022 13:50:18 -0500 Subject: [PATCH 1/3] Read xml from log file and parse --- vmaf-gui/Form1.cs | 65 +++++++++---------- vmaf-gui/ReadXML.cs | 14 ++++ vmaf-gui/results.Designer.cs | 72 +++++++++++++++++++++ vmaf-gui/results.cs | 44 +++++++++++++ vmaf-gui/results.resx | 120 +++++++++++++++++++++++++++++++++++ vmaf-gui/vmaf-gui.csproj | 11 ++++ 6 files changed, 294 insertions(+), 32 deletions(-) create mode 100644 vmaf-gui/ReadXML.cs create mode 100644 vmaf-gui/results.Designer.cs create mode 100644 vmaf-gui/results.cs create mode 100644 vmaf-gui/results.resx diff --git a/vmaf-gui/Form1.cs b/vmaf-gui/Form1.cs index c9bcf11..45babb6 100644 --- a/vmaf-gui/Form1.cs +++ b/vmaf-gui/Form1.cs @@ -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 { @@ -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; @@ -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; } @@ -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 @@ -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); @@ -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..."; })); @@ -157,6 +152,10 @@ private void button1_Click(object sender, EventArgs e) lblProgress.Invoke(new Action(delegate () { lblProgress.Text = "Done."; })); ChildProcess("notepad", "log.xml", true); + results resultsForm = new results(); + resultsForm.showResults("./log.xml"); + resultsForm.ShowDialog(); + // Clean up form controls and delete .yuv files to save disk space lblProgress.Invoke(new Action(delegate () { lblProgress.Text = ""; })); @@ -164,6 +163,8 @@ private void button1_Click(object sender, EventArgs e) File.Delete("./temp/source.yuv"); button1.Invoke(new Action(delegate () { button1.Enabled = true; })); + + } ); @@ -183,12 +184,12 @@ 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) { @@ -196,12 +197,12 @@ void decompressVideo(string path,string output) } } - 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) @@ -216,15 +217,15 @@ void vmaf(string resolution,string model,bool psnr,bool ssim) //lblProgress.Text = "Performing VMAF..."; lblProgress.Invoke(new Action(delegate () { lblProgress.Text = "Performing VMAF..."; })); - ChildProcess("vmaf.exe",args ,false); + ChildProcess("vmaf.exe", args, false); + + + - - - } - + } - + } diff --git a/vmaf-gui/ReadXML.cs b/vmaf-gui/ReadXML.cs new file mode 100644 index 0000000..4cfe75f --- /dev/null +++ b/vmaf-gui/ReadXML.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; + +namespace vmaf_gui +{ + class ReadXML + { + + } +} diff --git a/vmaf-gui/results.Designer.cs b/vmaf-gui/results.Designer.cs new file mode 100644 index 0000000..1c1cf3a --- /dev/null +++ b/vmaf-gui/results.Designer.cs @@ -0,0 +1,72 @@ + +namespace vmaf_gui +{ + partial class results + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + this.resultsChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); + ((System.ComponentModel.ISupportInitialize)(this.resultsChart)).BeginInit(); + this.SuspendLayout(); + // + // resultsChart + // + chartArea1.Name = "ChartArea1"; + this.resultsChart.ChartAreas.Add(chartArea1); + legend1.Name = "Legend1"; + this.resultsChart.Legends.Add(legend1); + this.resultsChart.Location = new System.Drawing.Point(12, 12); + this.resultsChart.Name = "resultsChart"; + series1.ChartArea = "ChartArea1"; + series1.Legend = "Legend1"; + series1.Name = "Series1"; + this.resultsChart.Series.Add(series1); + this.resultsChart.Size = new System.Drawing.Size(776, 426); + this.resultsChart.TabIndex = 0; + this.resultsChart.Text = "chart1"; + // + // results + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.resultsChart); + this.Name = "results"; + this.Text = "results"; + ((System.ComponentModel.ISupportInitialize)(this.resultsChart)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataVisualization.Charting.Chart resultsChart; + } +} \ No newline at end of file diff --git a/vmaf-gui/results.cs b/vmaf-gui/results.cs new file mode 100644 index 0000000..d2d7658 --- /dev/null +++ b/vmaf-gui/results.cs @@ -0,0 +1,44 @@ +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; + + var pooled_metrics = from metric in doc.Root.Descendants("pooled_metrics") + where metric.Attribute("name").Value == "vmaf" + select metric; + + + + DataPointCollection data = null; + foreach(var frame in frames) + { + double frameNum = double.Parse(frame.Attribute("frameNum").Value); + double vmafScore = double.Parse(frame.Attribute("vmaf").Value); + data.AddXY(frameNum, vmafScore); + Console.WriteLine(frame); + } + + //TODO Bind vmaf data to results form control + + } + } +} diff --git a/vmaf-gui/results.resx b/vmaf-gui/results.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/vmaf-gui/results.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/vmaf-gui/vmaf-gui.csproj b/vmaf-gui/vmaf-gui.csproj index 531ef9b..e8ca84c 100644 --- a/vmaf-gui/vmaf-gui.csproj +++ b/vmaf-gui/vmaf-gui.csproj @@ -66,6 +66,7 @@ + @@ -85,6 +86,13 @@ + + + Form + + + results.cs + Form1.cs @@ -98,6 +106,9 @@ Resources.resx True + + results.cs + SettingsSingleFileGenerator Settings.Designer.cs From 95dc5e0cb9975f169dc577471dd7d86481c9624d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brandon=20Pi=C3=B1a?= Date: Sat, 30 Apr 2022 15:54:48 -0500 Subject: [PATCH 2/3] Added results charting --- vmaf-gui/Form1.cs | 14 +++++--------- vmaf-gui/results.Designer.cs | 26 ++++++++++++++------------ vmaf-gui/results.cs | 26 ++++++++++++++++---------- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/vmaf-gui/Form1.cs b/vmaf-gui/Form1.cs index 45babb6..67469db 100644 --- a/vmaf-gui/Form1.cs +++ b/vmaf-gui/Form1.cs @@ -147,23 +147,20 @@ 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); - - results resultsForm = new results(); - resultsForm.showResults("./log.xml"); - resultsForm.ShowDialog(); - // 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(); } @@ -214,7 +211,6 @@ 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); diff --git a/vmaf-gui/results.Designer.cs b/vmaf-gui/results.Designer.cs index 1c1cf3a..3690672 100644 --- a/vmaf-gui/results.Designer.cs +++ b/vmaf-gui/results.Designer.cs @@ -29,25 +29,26 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.resultsChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); ((System.ComponentModel.ISupportInitialize)(this.resultsChart)).BeginInit(); this.SuspendLayout(); // // resultsChart // - chartArea1.Name = "ChartArea1"; - this.resultsChart.ChartAreas.Add(chartArea1); - legend1.Name = "Legend1"; - this.resultsChart.Legends.Add(legend1); + chartArea2.Name = "ChartArea1"; + this.resultsChart.ChartAreas.Add(chartArea2); + legend2.Name = "Legend1"; + this.resultsChart.Legends.Add(legend2); this.resultsChart.Location = new System.Drawing.Point(12, 12); this.resultsChart.Name = "resultsChart"; - series1.ChartArea = "ChartArea1"; - series1.Legend = "Legend1"; - series1.Name = "Series1"; - this.resultsChart.Series.Add(series1); + series2.ChartArea = "ChartArea1"; + series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series2.Legend = "Legend1"; + series2.Name = "VMAF"; + this.resultsChart.Series.Add(series2); this.resultsChart.Size = new System.Drawing.Size(776, 426); this.resultsChart.TabIndex = 0; this.resultsChart.Text = "chart1"; @@ -56,10 +57,11 @@ private void InitializeComponent() // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(804, 450); this.Controls.Add(this.resultsChart); this.Name = "results"; this.Text = "results"; + this.Load += new System.EventHandler(this.results_Load); ((System.ComponentModel.ISupportInitialize)(this.resultsChart)).EndInit(); this.ResumeLayout(false); diff --git a/vmaf-gui/results.cs b/vmaf-gui/results.cs index d2d7658..107af28 100644 --- a/vmaf-gui/results.cs +++ b/vmaf-gui/results.cs @@ -22,23 +22,29 @@ public void showResults(string path) var frames = from frame in doc.Root.Descendants("frame") select frame; - var pooled_metrics = from metric in doc.Root.Descendants("pooled_metrics") - where metric.Attribute("name").Value == "vmaf" - select metric; - - + - DataPointCollection data = null; - foreach(var frame in frames) + foreach (var frame in frames) { double frameNum = double.Parse(frame.Attribute("frameNum").Value); double vmafScore = double.Parse(frame.Attribute("vmaf").Value); - data.AddXY(frameNum, vmafScore); - Console.WriteLine(frame); + this.resultsChart.Series["VMAF"].Points.AddXY(frameNum, vmafScore); } - + //TODO Bind vmaf data to results form control + + + } + + private void label1_Click(object sender, EventArgs e) + { + + } + + private void results_Load(object sender, EventArgs e) + { + } } } From d4d1328f67bf6b0e78b20393644e773c9b491b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brandon=20Pi=C3=B1a?= Date: Sat, 30 Apr 2022 16:44:45 -0500 Subject: [PATCH 3/3] average vmaf scores manually since the xml reader doesn't like the vmaf log file --- vmaf-gui/ReadXML.cs | 14 ------------ vmaf-gui/results.Designer.cs | 41 ++++++++++++++++++++++++------------ vmaf-gui/results.cs | 20 ++++-------------- vmaf-gui/vmaf-gui.csproj | 1 - 4 files changed, 31 insertions(+), 45 deletions(-) delete mode 100644 vmaf-gui/ReadXML.cs diff --git a/vmaf-gui/ReadXML.cs b/vmaf-gui/ReadXML.cs deleted file mode 100644 index 4cfe75f..0000000 --- a/vmaf-gui/ReadXML.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml; - -namespace vmaf_gui -{ - class ReadXML - { - - } -} diff --git a/vmaf-gui/results.Designer.cs b/vmaf-gui/results.Designer.cs index 3690672..8945937 100644 --- a/vmaf-gui/results.Designer.cs +++ b/vmaf-gui/results.Designer.cs @@ -29,46 +29,59 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.resultsChart = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.label1 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.resultsChart)).BeginInit(); this.SuspendLayout(); // // resultsChart // - chartArea2.Name = "ChartArea1"; - this.resultsChart.ChartAreas.Add(chartArea2); - legend2.Name = "Legend1"; - this.resultsChart.Legends.Add(legend2); + chartArea1.Name = "ChartArea1"; + this.resultsChart.ChartAreas.Add(chartArea1); + legend1.Name = "Legend1"; + this.resultsChart.Legends.Add(legend1); this.resultsChart.Location = new System.Drawing.Point(12, 12); this.resultsChart.Name = "resultsChart"; - series2.ChartArea = "ChartArea1"; - series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; - series2.Legend = "Legend1"; - series2.Name = "VMAF"; - this.resultsChart.Series.Add(series2); + series1.ChartArea = "ChartArea1"; + series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; + series1.Legend = "Legend1"; + series1.Name = "VMAF"; + this.resultsChart.Series.Add(series1); this.resultsChart.Size = new System.Drawing.Size(776, 426); this.resultsChart.TabIndex = 0; this.resultsChart.Text = "chart1"; // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(795, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(161, 25); + this.label1.TabIndex = 1; + this.label1.Text = "VMAF: 100.00"; + // // results // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(804, 450); + this.ClientSize = new System.Drawing.Size(962, 450); + this.Controls.Add(this.label1); this.Controls.Add(this.resultsChart); this.Name = "results"; this.Text = "results"; - this.Load += new System.EventHandler(this.results_Load); ((System.ComponentModel.ISupportInitialize)(this.resultsChart)).EndInit(); this.ResumeLayout(false); + this.PerformLayout(); } #endregion private System.Windows.Forms.DataVisualization.Charting.Chart resultsChart; + private System.Windows.Forms.Label label1; } } \ No newline at end of file diff --git a/vmaf-gui/results.cs b/vmaf-gui/results.cs index 107af28..e26d08e 100644 --- a/vmaf-gui/results.cs +++ b/vmaf-gui/results.cs @@ -18,33 +18,21 @@ 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); } - //TODO Bind vmaf data to results form control - - - - } - - private void label1_Click(object sender, EventArgs e) - { - - } - - private void results_Load(object sender, EventArgs e) - { + double average = Math.Round(total / frames.ToArray().Length,2); + label1.Text = "VMAF: " + average; } } } diff --git a/vmaf-gui/vmaf-gui.csproj b/vmaf-gui/vmaf-gui.csproj index e8ca84c..8256fd3 100644 --- a/vmaf-gui/vmaf-gui.csproj +++ b/vmaf-gui/vmaf-gui.csproj @@ -86,7 +86,6 @@ - Form