Skip to content

Commit

Permalink
Released v1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mysteryx93 committed Jan 15, 2016
1 parent 0063f3b commit 3d21151
Show file tree
Hide file tree
Showing 72 changed files with 1,127 additions and 2,757 deletions.
46 changes: 24 additions & 22 deletions Business/AutoPitchBusiness.cs
Expand Up @@ -19,7 +19,7 @@ public class AutoPitchBusiness {
public static bool AppyAutoPitch(Media video) {
using (MediaInfoReader InfoReader = new MediaInfoReader()) {
InfoReader.LoadInfo(Settings.NaturalGroundingFolder + video.FileName);
if (Settings.SavedFile.ChangeAudioPitch && InfoReader.PixelAspectRatio == 1 && !video.DisablePitch) {
if (Settings.SavedFile.ChangeAudioPitch && InfoReader.PixelAspectRatio == 1 && !video.DisablePitch && (InfoReader.BitDepth ?? 8) == 8) {
CreateScript(Settings.NaturalGroundingFolder + video.FileName, InfoReader);
return true;
} else
Expand All @@ -33,33 +33,35 @@ public class AutoPitchBusiness {
/// <param name="inputFile">The video to play.</param>
/// <param name="infoReader">An object to read media information.</param>
public static void CreateScript(string inputFile, MediaInfoReader infoReader) {
bool AviSynthPlus = MpcConfigBusiness.GetAviSynthVersion() == AviSynthVersion.AviSynthPlus;
int CPU = Environment.ProcessorCount / 2;
AviSynthScriptBuilder Script = new AviSynthScriptBuilder();
Script.AddPluginPath();
//Script.LoadPluginDll("LSMASHSource.dll");
//Script.LoadPluginDll(infoReader.BitDepth == 10 ? "ffms2-10bit" : "ffms2.dll");
Script.LoadPluginDll("TimeStretch.dll");
Script.LoadPluginAvsi("UUSize4.avsi");
Script.LoadPluginDll("dither.dll");
Script.LoadPluginAvsi("dither.avsi");
Script.AppendLine("SetMTMode(3,{0})", CPU);
Script.OpenDirect(inputFile, Settings.AutoPitchCache, !string.IsNullOrEmpty(infoReader.AudioFormat), infoReader.BitDepth == 10, true);
//Script.AppendLine(@"file = ""{0}""", Script.GetAsciiPath(inputFile));
//if (new string[] { ".mp4", ".mov" }.Contains(Path.GetExtension(inputFile).ToLower())) {
//Script.AppendLine("LSMASHVideoSource(file, threads=1, stacked=true)");
//Script.AppendLine("AudioDub(LSMASHAudioSource(file))");
//} else {
//}
//Script.AppendLine("LWLibavVideoSource(file, cache=false, threads=1, stacked=true)");
//Script.AppendLine("AudioDub(LWLibavAudioSource(file, cache=false))");
//Script.AppendLine("FFVideoSource(file, cache=false, threads=1{0})", infoReader.BitDepth == 10 ? ", enable10bithack=true" : "");
//Script.AppendLine("AudioDub(FFAudioSource(file, cache=false))");
Script.AppendLine("SetMTMode(2)");
if (infoReader.BitDepth == 10)
Script.AppendLine("DitherPost()");
if (AviSynthPlus) {
Script.AppendLine(@"SetFilterMTMode(""DEFAULT_MT_MODE"",2)");
Script.AppendLine(@"SetFilterMTMode(""LWLibavVideoSource"",3)");
Script.AppendLine(@"SetFilterMTMode(""LWLibavAudioSource"",3)");
} else {
Script.AppendLine("SetMTMode(3,{0})", CPU);
}
Script.OpenDirect(inputFile, Settings.AutoPitchCache, !string.IsNullOrEmpty(infoReader.AudioFormat), 2);
if (!AviSynthPlus)
Script.AppendLine("SetMTMode(2)");
Script.AppendLine("UUSize4(mod=4)");
Script.AppendLine("ResampleAudio(48000)");
Script.AppendLine("TimeStretchPlugin(pitch = 100.0 * 0.98181819915771484)");
if (AviSynthPlus) {
// This causes a slight audio delay in AviSynth 2.6
Script.AppendLine("ResampleAudio(48000)");
Script.AppendLine("TimeStretchPlugin(pitch = 100.0 * 0.98181819915771484)");
Script.AppendLine("Prefetch({0})", CPU);
} else {
// This slightly slows down playback speed but audio stays in sync
Script.AppendLine("V = AssumeFPS(432.0 / 440.0 * FrameRate)");
Script.AppendLine("A = AssumeSampleRate(int(432.0 / 440.0 * AudioRate))");
Script.AppendLine("AudioDub(V, A)");
}

Script.WriteToFile(Settings.AutoPitchFile);
File.Delete(Settings.AutoPitchCache);
}
Expand Down
43 changes: 24 additions & 19 deletions Business/AviSynthScriptBuilder.cs
Expand Up @@ -106,18 +106,18 @@ public class AviSynthScriptBuilder {
/// If script ends with DitherPost(), replace it with Dither_out() when rawOutput is true. If rawOutput is false, it does the reverse.
/// </summary>
/// <param name="rawOutput">True to replace DitherPost with Dither_out, false to replace Dither_out with DitherPost.</param>
public void DitherOut(bool rawOutput) {
string StrPost = "DitherPost()";
string StrOut = "Dither_out()";
string Val = Script.TrimEnd('\r', '\n', ' ');
if (rawOutput && Val.EndsWith(StrPost)) {
int Pos = Val.LastIndexOf(StrPost);
script.Replace(StrPost, StrOut, Pos, script.Length - Pos);
} else if (!rawOutput && Val.EndsWith(StrOut)) {
int Pos = Val.LastIndexOf(StrOut);
script.Replace(StrOut, StrPost, Pos, script.Length - Pos);
}
}
//public void DitherOut(bool rawOutput) {
// string StrPost = "DitherPost()";
// string StrOut = "Dither_out()";
// string Val = Script.TrimEnd('\r', '\n', ' ');
// if (rawOutput && Val.EndsWith(StrPost)) {
// int Pos = Val.LastIndexOf(StrPost);
// script.Replace(StrPost, StrOut, Pos, script.Length - Pos);
// } else if (!rawOutput && Val.EndsWith(StrOut)) {
// int Pos = Val.LastIndexOf(StrOut);
// script.Replace(StrOut, StrPost, Pos, script.Length - Pos);
// }
//}

public void LoadPluginDll(string fileName) {
AppendLine(@"LoadPlugin(P+""{0}"")", fileName);
Expand All @@ -132,15 +132,20 @@ public class AviSynthScriptBuilder {
AppendLine(@"AviSource(file, audio={0}, pixel_type=""YV12"")", audio);
}

public void OpenDirect(string fileName, string cacheFile, bool audio, bool highBitDepth, bool multiThreaded) {
LoadPluginDll(highBitDepth ? "ffms2-10bit.dll" : "ffms2.dll");
public void OpenDirect(string fileName, string cacheFile, bool audio, int threads) {
//LoadPluginDll("ffms2.dll");
//AppendLine(@"file=""{0}""", GetAsciiPath(fileName));
//AppendLine("FFVideoSource(file{0}{1})",
// string.IsNullOrEmpty(cacheFile) ? ", cache=false" : string.Format(@", cachefile=""{0}""", cacheFile),
// multiThreaded ? ", threads=1" : "");
//if (audio)
// AppendLine("AudioDub(FFAudioSource(file, cache=false))");

LoadPluginDll("LSMASHSource.dll");
AppendLine(@"file=""{0}""", GetAsciiPath(fileName));
AppendLine("FFVideoSource(file{0}{1}{2})",
string.IsNullOrEmpty(cacheFile) ? ", cache=false" : string.Format(@", cachefile=""{0}""", cacheFile),
highBitDepth ? ", enable10bithack=true" : "",
multiThreaded ? ", threads=1" : "");
AppendLine("LWLibavVideoSource(file, cache=false{0})", threads > 0 ? ", threads=" + threads.ToString() : "");
if (audio)
AppendLine("AudioDub(FFAudioSource(file, cache=false))");
AppendLine("AudioDub(LWLibavAudioSource(file, cache=false))");
}

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
Expand Down
4 changes: 2 additions & 2 deletions Business/Business.csproj
Expand Up @@ -80,8 +80,8 @@
<Reference Include="Microsoft.Threading.Tasks.Extensions.Desktop">
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
Expand Down
6 changes: 6 additions & 0 deletions Business/Enumerations.cs
Expand Up @@ -18,4 +18,10 @@ public enum DownloadQuality {
p360 = 4,
p240 = 5
}

public enum AviSynthVersion {
None,
AviSynth26,
AviSynthPlus
}
}

0 comments on commit 3d21151

Please sign in to comment.