Skip to content

Commit

Permalink
1. Allow disabling numa node
Browse files Browse the repository at this point in the history
2. Allow episode specific settings.
  • Loading branch information
LittlePox committed Sep 10, 2019
1 parent e0fe17f commit f31cef6
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 64 deletions.
6 changes: 6 additions & 0 deletions OKEGui/OKEGui/00001.m2ts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"VspipeArgs" : [
"op_start=8000",
"op_end=16000"
]
}
27 changes: 25 additions & 2 deletions OKEGui/OKEGui/Gui/WizardWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using OKEGui.Utils;
using OKEGui.Model;
using OKEGui.Worker;
using OKEGui.Task;
using Newtonsoft.Json;

namespace OKEGui
{
Expand All @@ -19,6 +21,7 @@ namespace OKEGui
/// </summary>
public partial class WizardWindow : Window
{
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
// Wizard里需要显示的内容。
private class NewTask : INotifyPropertyChanged
{
Expand Down Expand Up @@ -196,6 +199,23 @@ private void WizardFinish(object sender, RoutedEventArgs e)
// 清理文件
cleaner.Clean(inputFile, new List<string> { json.InputScript });

EpisodeConfig config = null;
string cfgPath = inputFile + ".json";
FileInfo cfgFile = new FileInfo(cfgPath);
if (cfgFile.Exists)
{
try
{
string configStr = File.ReadAllText(cfgPath);
config = JsonConvert.DeserializeObject<EpisodeConfig>(configStr);
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.ToString(), cfgFile.Name + "文件写错了诶", MessageBoxButton.OK, MessageBoxImage.Error);
continue;
}
}

// 新建vpy文件(inputname.m2ts-mmddHHMM.vpy)
string vpy = inputTemplate[0] + inputTemplate[1] + "r'" +
inputFile + "'" + inputTemplate[3];
Expand All @@ -204,7 +224,7 @@ private void WizardFinish(object sender, RoutedEventArgs e)
string fileName = inputFile + "-" + time.ToString("MMddHHmm") + ".vpy";
File.WriteAllText(fileName, vpy);

var finfo = new FileInfo(inputFile);
FileInfo finfo = new FileInfo(inputFile);
TaskDetail td = new TaskDetail
{
TaskName = string.IsNullOrEmpty(json.ProjectName) ? finfo.Name : json.ProjectName + "-" + finfo.Name,
Expand All @@ -214,8 +234,11 @@ private void WizardFinish(object sender, RoutedEventArgs e)

// 更新输入脚本和输出文件拓展名
td.Taskfile.InputScript = fileName;
if (config != null)
{
td.Taskfile.Config = config.Clone() as EpisodeConfig;
}
td.UpdateOutputFileName();

workerManager.AddTask(td);
}
}
Expand Down
10 changes: 7 additions & 3 deletions OKEGui/OKEGui/Job/VideoJob/VideoInfoJob.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
namespace OKEGui
using System.Collections.Generic;

namespace OKEGui
{
public class VideoInfoJob : Job
{
public VideoInfoJob(string input) : base()
public List<string> Args = new List<string>();
public VideoInfoJob(string input, List<string> args) : base()
{
this.Input = input;
Input = input;
Args.AddRange(args);
}

public override JobType GetJobType()
Expand Down
5 changes: 4 additions & 1 deletion OKEGui/OKEGui/Job/VideoJob/VideoJob.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
namespace OKEGui
using System.Collections.Generic;

namespace OKEGui
{
public class VideoJob : Job
{
public string EncoderPath;
public string EncodeParam;
public List<string> VspipeArgs = new List<string>();
public double Fps;
public uint FpsNum;
public uint FpsDen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected void getInputProperties(VideoJob job)
{
//VapourSynthHelper vsHelper = new VapourSynthHelper();
//vsHelper.LoadScriptFile(job.Input);
VSPipeInfo vsHelper = new VSPipeInfo(job.Input);
VSPipeInfo vsHelper = new VSPipeInfo(job.Input, job.VspipeArgs);
fps_n = vsHelper.FpsNum;
fps_d = vsHelper.FpsDen;
numberOfFrames = (ulong)vsHelper.TotalFreams;
Expand Down
38 changes: 17 additions & 21 deletions OKEGui/OKEGui/JobProcessor/Video/VSPipeProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,24 @@ namespace OKEGui
{
public class VSPipeProcessor : CommandlineJobProcessor
{
public static IJobProcessor NewVSPipeProcessor(Job j)
{
if (j is VideoInfoJob) {
return new VSPipeProcessor(j as VideoInfoJob);
}
return null;
}

private VSVideoInfo videoInfo;
private ManualResetEvent retrieved = new ManualResetEvent(false);

public VSPipeProcessor(VideoInfoJob j) : base()
{
// 获取VSPipe路径
this.executable = Initializer.Config.vspipePath;
executable = Initializer.Config.vspipePath;
videoInfo = new VSVideoInfo();

StringBuilder sb = new StringBuilder();

sb.Append("--info ");
sb.Append("\"" + j.Input + "\" ");
sb.Append("-");
sb.Append("--info");
foreach (string arg in j.Args)
{
sb.Append($" --arg \"{arg}\"");
}
sb.Append(" \"" + j.Input + "\"");
sb.Append(" -");

commandLine = sb.ToString();
}
Expand All @@ -49,7 +45,14 @@ public override void ProcessLine(string line, StreamType stream)
Regex rColorFamily = new Regex("Color Family: ([a-zA-Z]+)");
Regex rBits = new Regex("Bits: ([0-9]+)");

if (line.Contains("Width"))
if (line.Contains("Python exception: "))
{
OKETaskException ex = new OKETaskException(Constants.vpyErrorSmr);
ex.progress = 0.0;
ex.Data["VPY_ERROR"] = line.Substring(18);
throw ex;
}
else if (line.Contains("Width"))
{
var s = rWidth.Split(line);
int w;
Expand Down Expand Up @@ -129,14 +132,7 @@ public override void ProcessLine(string line, StreamType stream)
else if (line.Contains("SubSampling"))
{
//目前还没有要处理subsampling的
}
else if (line.Contains("Python exception: "))
{
OKETaskException ex = new OKETaskException(Constants.vpyErrorSmr);
ex.progress = 0.0;
ex.Data["VPY_ERROR"] = line.Substring(18);
throw ex;
}
}
}

public override void waitForFinish()
Expand Down
25 changes: 15 additions & 10 deletions OKEGui/OKEGui/JobProcessor/Video/X264Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text.RegularExpressions;
using OKEGui.Utils;
using OKEGui.JobProcessor;
using System.Collections.Generic;

namespace OKEGui
{
Expand All @@ -14,9 +15,9 @@ public class X264Encoder : CommandlineVideoEncoder
private readonly string X264Path = "";
private readonly string VspipePath = "";

public X264Encoder(Job j) : base()
public X264Encoder(VideoJob job) : base()
{
job = j as VideoJob;
this.job = job;
getInputProperties(job);

executable = Path.Combine(Environment.SystemDirectory, "cmd.exe");
Expand All @@ -29,7 +30,7 @@ public X264Encoder(Job j) : base()
// 获取VSPipe路径
this.VspipePath = Initializer.Config.vspipePath;

commandLine = BuildCommandline(job.EncodeParam, job.NumaNode);
commandLine = BuildCommandline(job.EncodeParam, job.NumaNode, job.VspipeArgs);
}

public override void ProcessLine(string line, StreamType stream)
Expand Down Expand Up @@ -90,22 +91,26 @@ public override void ProcessLine(string line, StreamType stream)
}
}

private string BuildCommandline(string extractParam, int numaNode)
private string BuildCommandline(string extractParam, int numaNode, List<string> vspipeArgs)
{
StringBuilder sb = new StringBuilder();

sb.Append("/c \"start \"foo\" /b /wait /affinity 0xFFFFFFF /node ");
sb.Append(numaNode.ToString());
// 构建vspipe参数
sb.Append(" \"" + VspipePath + "\"");
sb.Append(" --y4m ");
sb.Append("\"" + job.Input + "\"");
sb.Append(" - | ");
sb.Append(" --y4m");
foreach (string arg in vspipeArgs)
{
sb.Append($" --arg \"{arg}\"");
}
sb.Append(" \"" + job.Input + "\"");
sb.Append(" - |");

// 构建X264参数
sb.Append("\"" + X264Path + "\"");
sb.Append(" --demuxer y4m " + extractParam + " -o ");
sb.Append("\"" + job.Output + "\" -");
sb.Append(" \"" + X264Path + "\"");
sb.Append(" --demuxer y4m " + extractParam + " -o");
sb.Append(" \"" + job.Output + "\" -");
sb.Append("\"");

return sb.ToString();
Expand Down
25 changes: 15 additions & 10 deletions OKEGui/OKEGui/JobProcessor/Video/x265Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.RegularExpressions;
using OKEGui.Utils;
using OKEGui.JobProcessor;
using System.Collections.Generic;

namespace OKEGui
{
Expand All @@ -13,9 +14,9 @@ public class X265Encoder : CommandlineVideoEncoder
private readonly string X265Path = "";
private readonly string vspipePath = "";

public X265Encoder(Job j) : base()
public X265Encoder(VideoJob job) : base()
{
job = j as VideoJob;
this.job = job;
getInputProperties(job);

executable = Path.Combine(Environment.SystemDirectory, "cmd.exe");
Expand All @@ -28,7 +29,7 @@ public X265Encoder(Job j) : base()
// 获取VSPipe路径
this.vspipePath = Initializer.Config.vspipePath;

commandLine = BuildCommandline(job.EncodeParam, job.NumaNode);
commandLine = BuildCommandline(job.EncodeParam, job.NumaNode, job.VspipeArgs);
}

public override void ProcessLine(string line, StreamType stream)
Expand Down Expand Up @@ -89,22 +90,26 @@ public override void ProcessLine(string line, StreamType stream)
}
}

private string BuildCommandline(string extractParam, int numaNode)
private string BuildCommandline(string extractParam, int numaNode, List<string> vspipeArgs)
{
StringBuilder sb = new StringBuilder();

sb.Append("/c \"start \"foo\" /b /wait /affinity 0xFFFFFFF /node ");
sb.Append(numaNode.ToString());
// 构建vspipe参数
sb.Append(" \"" + vspipePath + "\"");
sb.Append(" --y4m ");
sb.Append("\"" + job.Input + "\"");
sb.Append(" - | ");
sb.Append(" --y4m");
foreach (string arg in vspipeArgs)
{
sb.Append($" --arg \"{arg}\"");
}
sb.Append(" \"" + job.Input + "\"");
sb.Append(" - |");

// 构建x265参数
sb.Append("\"" + X265Path + "\"");
sb.Append(" --y4m " + extractParam + " -o ");
sb.Append("\"" + job.Output + "\" -");
sb.Append(" \"" + X265Path + "\"");
sb.Append(" --y4m " + extractParam + " -o");
sb.Append(" \"" + job.Output + "\" -");
sb.Append("\"");

return sb.ToString();
Expand Down
1 change: 1 addition & 0 deletions OKEGui/OKEGui/OKEGui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<Compile Include="Model\Info\Info.cs" />
<Compile Include="Model\Info\VideoInfo.cs" />
<Compile Include="Task\AddTaskService.cs" />
<Compile Include="Task\EpisodeProfile.cs" />
<Compile Include="Task\TaskProfile.cs" />
<Compile Include="Model\Track\AudioTrack.cs" />
<Compile Include="Model\Track\ChapterTrack.cs" />
Expand Down
2 changes: 1 addition & 1 deletion OKEGui/OKEGui/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.8.*")]
[assembly: AssemblyVersion("4.9.*")]
40 changes: 40 additions & 0 deletions OKEGui/OKEGui/Task/EpisodeProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;

namespace OKEGui.Task
{
public class EpisodeConfig : ICloneable
{
public List<string> VspipeArgs = new List<string>();

public object Clone()
{
EpisodeConfig clone = MemberwiseClone() as EpisodeConfig;
if (VspipeArgs != null)
{
clone.VspipeArgs = new List<string>();
foreach (string arg in VspipeArgs)
{
clone.VspipeArgs.Add(arg);
}
}
return clone;
}

public override string ToString()
{
string str = "EpisodeConfig{";
str += "VspipeArgs: ";
if (VspipeArgs == null)
{
str += "null";
}
else
{
str += "[" + string.Join(",", VspipeArgs) + "]";
}
str += "]";
return str;
}
}
}
4 changes: 3 additions & 1 deletion OKEGui/OKEGui/Task/TaskProfile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using OKEGui.Task;
using System;
using System.Collections.Generic;

/// <summary>
Expand Down Expand Up @@ -27,6 +28,7 @@ public class TaskProfile : ICloneable
public string SubtitleLanguage;
public List<Info> SubtitleTracks;
public List<string> InputFiles;
public EpisodeConfig Config;

public Object Clone()
{
Expand Down
1 change: 1 addition & 0 deletions OKEGui/OKEGui/Utils/Initializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class OKEGuiConfig
{
public string vspipePath;
public string logLevel = "DEBUG";
public bool noNuma = false;
}

static class Initializer
Expand Down
Loading

0 comments on commit f31cef6

Please sign in to comment.