Skip to content

Commit

Permalink
Child processes no longer block main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatNerdUKnow committed Oct 1, 2020
1 parent 150e3f9 commit 9bf5a10
Showing 1 changed file with 50 additions and 19 deletions.
69 changes: 50 additions & 19 deletions vmaf-gui/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -33,6 +33,7 @@ string ChildProcess(string program_name, string args, bool show)
p.StartInfo.FileName = program_name;
p.StartInfo.Arguments = args;


p.Start();


Expand All @@ -54,7 +55,7 @@ string ChildProcess(string program_name, string args, bool show)
Console.WriteLine(args);

p.WaitForExit();
prgProgress.PerformStep();
//prgProgress.PerformStep();
return output;
}

Expand Down Expand Up @@ -106,8 +107,10 @@ private void Form1_Load(object sender, EventArgs e)
private void button1_Click(object sender, EventArgs e)
{
prgProgress.Value = 0;

try
{

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

Expand All @@ -121,25 +124,51 @@ private void button1_Click(object sender, EventArgs e)
Console.WriteLine(compressedPath);
try
{
button1.Enabled = false;
if (!Directory.Exists("temp"))
{
Directory.CreateDirectory("temp");
}

lblProgress.Text = "Decompressing Source...";
System.Windows.Forms.Application.DoEvents();
decompressVideo(sourcePath,"./temp/source.yuv");
string resolution = cmbResolution.Text;
string model = cmbModel.Text;
bool psnr = chkPSNR.Checked;
bool ssim = chkSSIM.Checked;

ThreadStart tStart = new ThreadStart(
() => {

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

//lblProgress.Text = "Decompressing Compressed...";
lblProgress.Invoke(new Action(delegate () { lblProgress.Text = "Decompressing Compressed..."; }));

decompressVideo(compressedPath, "./temp/compressed.yuv");
prgProgress.Invoke(new Action(delegate () { prgProgress.PerformStep(); }));


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

lblProgress.Text = "Decompressing Compressed...";
System.Windows.Forms.Application.DoEvents();
decompressVideo(compressedPath,"./temp/compressed.yuv");
ChildProcess("notepad", "log.xml", true);
prgProgress.Invoke(new Action(delegate () { prgProgress.PerformStep(); }));


vmaf();
lblProgress.Invoke(new Action(delegate () { lblProgress.Text = ""; }));
File.Delete("./temp/compressed.yuv");
File.Delete("./temp/source.yuv");

lblProgress.Text = "";
File.Delete("./temp/compressed.yuv");
File.Delete("./temp/source.yuv");
button1.Invoke(new Action(delegate () { button1.Enabled = true; }));

}

);


Thread t = new Thread(tStart);
t.Start();
}
catch (Exception err)
{
Expand All @@ -156,6 +185,7 @@ void decompressVideo(string path,string output)
{
try
{

ChildProcess("ffmpeg.exe", "-y -i " + path + " -pix_fmt yuv420p -vsync 0 "+ output,false);
}
catch (Exception err)
Expand All @@ -164,9 +194,9 @@ void decompressVideo(string path,string output)
}
}

void vmaf()
void vmaf(string resolution,string model,bool psnr,bool ssim)
{
string args = "yuv420p "+ cmbResolution.Text +" ./temp/source.yuv ./temp/compressed.yuv .\\model\\"+ cmbModel.Text +" --log log.xml";
string args = "yuv420p "+ resolution +" ./temp/source.yuv ./temp/compressed.yuv .\\model\\"+ model +" --log log.xml";
if (chkPSNR.Checked)
{
args += " --psnr";
Expand All @@ -176,12 +206,13 @@ void vmaf()
args += " --ssim";
}

lblProgress.Text = "Performing VMAF...";
System.Windows.Forms.Application.DoEvents();
//lblProgress.Text = "Performing VMAF...";
lblProgress.Invoke(new Action(delegate () { lblProgress.Text = "Performing VMAF..."; }));

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

System.Windows.Forms.Application.DoEvents();
ChildProcess("notepad", "log.xml",true);



}

Expand Down

0 comments on commit 9bf5a10

Please sign in to comment.