Skip to content

Commit

Permalink
Merge branch 'release/1.0.6.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
tautcony committed Oct 27, 2019
2 parents 1e868f6 + 20017ce commit e2b47a9
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 41 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# RP Cheker [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Build status](https://ci.appveyor.com/api/projects/status/pq6a7ju9q9hue3np?svg=true&passingText=%E7%BC%96%E8%AF%91%20-%20%E7%A8%B3%20&pendingText=%E5%B0%8F%E5%9C%9F%E8%B1%86%E7%82%B8%E4%BA%86%20&failingText=%E6%88%91%E6%84%9F%E8%A7%89%E5%8D%9C%E8%A1%8C%20)](https://ci.appveyor.com/project/tautcony/auto-torrent-inspection)
# RP Cheker [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Build status](https://ci.appveyor.com/api/projects/status/1uifyy3wsi8fblts?svg=true&passingText=%E7%BC%96%E8%AF%91%20-%20%E7%A8%B3%20&pendingText=%E5%B0%8F%E5%9C%9F%E8%B1%86%E7%82%B8%E4%BA%86%20&failingText=%E6%88%91%E6%84%9F%E8%A7%89%E5%8D%9C%E8%A1%8C%20)](https://ci.appveyor.com/project/tautcony/rp-checker)

- A simple tool to check if a video file corrupted by calculate PSNR/SSIM with another reference video file.
- A simple tool to check if a video file corrupted by calculate [PSNR](https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio)/[SSIM](https://en.wikipedia.org/wiki/Structural_similarity)/[GMSD](https://www4.comp.polyu.edu.hk/~cslzhang/IQA/GMSD/GMSD.htm) with another reference video file.


## Directions

- You must have .NET Framework 4.8 available from Windows Update.

- FFmpeg is now the default processor with both PSNR/SSIM, you can get ffmpeg from [here](https://ffmpeg.org/).
- FFmpeg is now the default processor provide both PSNR/SSIM metrics with faster speed, you can get ffmpeg from [here](https://ffmpeg.org/).

- VapourSynth script version has ability to handle defferent resolution video file and yeild more correct result, you can even write you own template script for even more complex condition.
- VapourSynth script version provide PSNR/GMSD metrics, it has ability to handle defferent resolution video file and yeild more correct result, custom script template is also available in this version.

- You can swith these options by click form icon at top-left corner, GMSD option is available in a combobox at right panel.

- You shall install [VapourSynth R29](https://github.com/vapoursynth/vapoursynth/releases) or higher and [python 3.6.0](https://www.python.org/downloads/) or higher to enable this processor.

- PSNR(VS) requires [mvsfunc](https://github.com/HomeOfVapourSynthEvolution/mvsfunc/releases) installed.

- GMSD(VS) requires [muvsfunc](https://github.com/WolframRhodium/muvsfunc), [mvsfunc](https://github.com/HomeOfVapourSynthEvolution/mvsfunc/releases), [havsfunc](https://github.com/HomeOfVapourSynthEvolution/havsfunc), [fmtconv](https://github.com/EleonoreMizo/fmtconv) installed.

- You shall install [VapourSynth R29](https://github.com/vapoursynth/vapoursynth/releases) or higher with [mvsfunc](https://github.com/HomeOfVapourSynthEvolution/mvsfunc/releases) and [python 3.6.0](https://www.python.org/downloads/) or higher to enable this processor.


## Thanks to
Expand Down
2 changes: 1 addition & 1 deletion RPChecker/Forms/Form1.Designer.cs

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

28 changes: 19 additions & 9 deletions RPChecker/Forms/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
var threshold = Convert.ToInt32(numericUpDown1.Value);
if (threshold == _threshold) return;
_threshold = threshold;
if (_fullData == null || _fullData.Count == 0) return;
UpdateGridView(CurrentData, FrameRate);
}
Expand Down Expand Up @@ -326,7 +327,8 @@ private void AnalyzeClip((string src, string opt) item)
{
toolStripProgressBar1.Style = ProgressBarStyle.Continuous;
var vsFile = $"{item.opt}.vpy";
ToolKits.GenerateVpyFile(item, vsFile, (cbVpyFile.SelectedItem as FileInfo)?.FullName);
ToolKits.GenerateVpyFile(item, vsFile,
cbVpyFile.SelectedItem is FileInfo info ? info.FullName : cbVpyFile.SelectedItem as string);
coreThread = new Thread(() => _coreProcess.GenerateLog(vsFile));
}
else
Expand Down Expand Up @@ -387,12 +389,12 @@ private void ProgressUpdated(string progress)
_coreProcess
.Match<VsPipePSNRProcess>(_ =>
{
if (IsHandleCreated && IsDisposed)
if (IsHandleCreated && !IsDisposed)
Invoke(new Action(() => VsUpdateProgress(progress)));
})
.Match<FFmpegProcess>(_ =>
{
if (IsHandleCreated && IsDisposed)
if (IsHandleCreated && !IsDisposed)
Invoke(new Action(() => FFmpegUpdateProgress(progress)));
})
;
Expand All @@ -406,12 +408,12 @@ private void ValueUpdated(string data)
_coreProcess
.Match<VsPipePSNRProcess>(self =>
{
if (IsHandleCreated && IsDisposed)
if (IsHandleCreated && !IsDisposed)
Invoke(new Action(() => self.UpdateValue(data, ref _data)));
})
.Match<FFmpegProcess>(self =>
{
if (IsHandleCreated && IsDisposed)
if (IsHandleCreated && !IsDisposed)
Invoke(new Action(() => self.UpdateValue(data, ref _data)));
})
;
Expand All @@ -420,10 +422,11 @@ private void ValueUpdated(string data)

#region vapoursynth
private static readonly Regex VsProgressRegex = new Regex(@"Frame: (?<processed>\d+)/(?<total>\d+)", RegexOptions.Compiled);
private static readonly Regex VsErrorRegex = new Regex("Failed|Error", RegexOptions.Compiled | RegexOptions.IgnoreCase);

private void VsUpdateProgress(string progress)
{
if (Regex.IsMatch(progress, "Failed|Error", RegexOptions.IgnoreCase))
if (VsErrorRegex.IsMatch(progress))
{
_currentBuffer.Inf = true;
}
Expand All @@ -441,14 +444,21 @@ private void VsUpdateProgress(string progress)
_errorDialogShowed = true;
new Task(() => MessageBox.Show(caption: @"RPChecker ERROR", icon: MessageBoxIcon.Error,
buttons: MessageBoxButtons.OK,
text: $"尚未正确放置mawen菊苣的滤镜库 'mvsfunc'{Environment.NewLine}大概的位置是在Python36\\Lib\\site-packages")).Start();
text: $"尚未正确放置mawen菊苣的滤镜库 'mvsfunc'{Environment.NewLine}大概的位置是在Python3X\\Lib\\site-packages")).Start();
}
else if (!_errorDialogShowed && progress.EndsWith("There is no function named PlaneAverage"))
{
_errorDialogShowed = true;
new Task(() => MessageBox.Show(caption: @"RPChecker ERROR", icon: MessageBoxIcon.Error,
buttons: MessageBoxButtons.OK,
text: $"请升级 'mvsfunc' 至少至 r6{Environment.NewLine}大概的位置是在Python36\\Lib\\site-packages")).Start();
text: $"请升级 'mvsfunc' 至少至 r6{Environment.NewLine}大概的位置是在Python3X\\Lib\\site-packages")).Start();
}
else if (!_errorDialogShowed && progress.EndsWith("ModuleNotFoundError: No module named 'muvsfunc'"))
{
_errorDialogShowed = true;
new Task(() => MessageBox.Show(caption: @"RPChecker ERROR", icon: MessageBoxIcon.Error,
buttons: MessageBoxButtons.OK,
text: $"尚未正确放置滤镜库 'muvsfunc'{Environment.NewLine}大概的位置是在Python3X\\Lib\\site-packages")).Start();
}
return;
}
Expand Down Expand Up @@ -507,7 +517,7 @@ private void FFmpegUpdateProgress(string progress)
private void btnChart_Click(object sender, EventArgs e)
{
if (cbFileList.SelectedIndex < 0 || _chartFormOpened) return;
var type = _coreProcess is VsPipePSNRProcess || _coreProcess is FFmpegPSNRProcess ? "PSNR" : "SSIM";
var type = _coreProcess.ValueText;
var chart = new FrmChart(CurrentData, _threshold, FrameRate, type);
chart.Load += (o, args) => _chartFormOpened = true;
chart.Closed += (o, args) => _chartFormOpened = false;
Expand Down
4 changes: 2 additions & 2 deletions RPChecker/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.6.0")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyVersion("1.0.6.2")]
[assembly: AssemblyFileVersion("1.0.6.2")]
44 changes: 36 additions & 8 deletions RPChecker/Properties/Resources.Designer.cs

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

48 changes: 39 additions & 9 deletions RPChecker/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,10 @@
<data name="Checked" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_check_box_black_24dp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Unchecked" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_check_box_outline_blank_black_24dp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="vpyTemplate" xml:space="preserve">
<data name="Default" xml:space="preserve">
<value>import vapoursynth as vs
import mvsfunc as mvf
import muvsfunc as muf
import functools

core=vs.get_core()
Expand All @@ -144,14 +142,46 @@ opt=mvf.GetPlane(source(opt))
if src.width!=opt.width:src=src.resize.Bicubic(width=opt.width,height=opt.height,format=vs.GRAY16)

def callback(n,f,clip):
print(n,f.props.PlanePSNR,flush=True)
#clip=core.text.Text(clip,str(n)+" "+str(f.props.PlanePSNR))
print(n,(1-min(1,float(f.props.PlaneGMSD)))*100,flush=True)
#clip=core.text.Text(clip,str(n)+" "+str(f.props.PlaneGMSD))
return clip

cmp=mvf.PlaneCompare(opt,src,mae=False,rmse=False,cov=False,corr=False)
cmp=muf.GMSD(opt,src)
cmp=core.std.FrameEval(cmp,functools.partial(callback,clip=cmp),prop_src=[cmp])
cmp.set_output()
</value>
cmp.set_output()</value>
<comment>默认的vpy模板</comment>
</data>
<data name="GMSD" xml:space="preserve">
<value>import vapoursynth as vs
import mvsfunc as mvf
import muvsfunc as muf
import functools

core=vs.get_core()
core.max_cache_size=5000

src=r"%File1%"
opt=r"%File2%"
fmt="yuv420p16"

source=lambda path:core.lsmas.LibavSMASHSource(path,format=fmt)if path.lower().endswith("mp4")else core.lsmas.LWLibavSource(path,format=fmt)

src=mvf.GetPlane(source(src))
opt=mvf.GetPlane(source(opt))

if src.width!=opt.width:src=src.resize.Bicubic(width=opt.width,height=opt.height,format=vs.GRAY16)

def callback(n,f,clip):
print(n,(1-min(1,float(f.props.PlaneGMSD)))*100,flush=True)
#clip=core.text.Text(clip,str(n)+" "+str(f.props.PlaneGMSD))
return clip

cmp=muf.GMSD(opt,src)
cmp=core.std.FrameEval(cmp,functools.partial(callback,clip=cmp),prop_src=[cmp])
cmp.set_output()</value>
<comment>计算GMSD的vpy模板</comment>
</data>
<data name="Unchecked" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_check_box_outline_blank_black_24dp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
9 changes: 8 additions & 1 deletion RPChecker/Util/FilterProcess/VsPipePSNRProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,14 @@ public void UpdateValue(string data, ref List<(int index, double value)> tempDat
}
public void Kill()
{
_consoleProcess.Kill();
try
{
_consoleProcess?.Kill();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}
22 changes: 16 additions & 6 deletions RPChecker/Util/ToolKits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,25 @@ public static TimeSpan ToTimeSpan(this string input)

public static void GenerateVpyFile((string src, string opt) item, string outputFile, string selectedFile)
{
var template = Properties.Resources.vpyTemplate;
if (selectedFile != null)
string template;
switch (selectedFile)
{
var temp = GetUTF8String(File.ReadAllBytes(selectedFile));
if (!temp.Contains(@"%File1%") || !temp.Contains(@"%File2%"))
case "Default":
template = Properties.Resources.Default;
break;
case "GMSD":
template = Properties.Resources.GMSD;
break;
default:
{
throw new FormatException("无效的模板文件");
var temp = GetUTF8String(File.ReadAllBytes(selectedFile));
if (!temp.Contains(@"%File1%") || !temp.Contains(@"%File2%"))
{
throw new FormatException("无效的模板文件");
}
template = temp;
break;
}
template = temp;
}
if (Path.GetDirectoryName(item.src) == Path.GetDirectoryName(item.opt))
{
Expand Down

0 comments on commit e2b47a9

Please sign in to comment.