/// <summary> /// Creates an AviSynth script that will auto-pitch the audio to 432hz. You then open this script file in the video player instead of directly opening the file. /// </summary> /// <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; AviSynthScriptBuilder Script = new AviSynthScriptBuilder(); Script.AddPluginPath(); if (AviSynthPlus) { //Script.AppendLine(@"SetFilterMTMode(""DEFAULT_MT_MODE"",2)"); //Script.AppendLine(@"SetFilterMTMode(""LWLibavVideoSource"",3)"); //Script.AppendLine(@"SetFilterMTMode(""LWLibavAudioSource"",3)"); Script.OpenDirect(inputFile, Settings.AutoPitchCache, !string.IsNullOrEmpty(infoReader.AudioFormat), 0); Script.AppendLine("Preroll(int(FrameRate*3))"); // This causes a slight audio delay in AviSynth 2.6 Script.LoadPluginDll("TimeStretch.dll"); Script.AppendLine("ResampleAudio(48000)"); Script.AppendLine("TimeStretchPlugin(pitch = 100.0 * 0.98181819915771484)"); //Script.AppendLine("Prefetch({0})", CPU); } else { int CPU = Environment.ProcessorCount / 2; Script.AppendLine("SetMTMode(3,{0})", CPU); Script.OpenDirect(inputFile, Settings.AutoPitchCache, !string.IsNullOrEmpty(infoReader.AudioFormat), CPU); Script.AppendLine("SetMTMode(2)"); Script.AppendLine("Preroll(int(FrameRate*3))"); //Script.AppendLine("Loop(int(FrameRate/2), 0, 0)"); //Script.LoadPluginAvsi("UUSize4.avsi"); //Script.AppendLine("UUSize4(mod=4)"); // 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.Cleanup(); Script.WriteToFile(Settings.AutoPitchFile); File.Delete(Settings.AutoPitchCache); }
public void GenerateScript(MediaEncoderSettings settings, bool preview, bool multiThreaded) { AviSynthScriptBuilder Script = new AviSynthScriptBuilder(settings.CustomScript); if (Script.IsEmpty) Script = GenerateVideoScript(settings, GetPreviewSourceFile(settings), preview, multiThreaded); else if (preview) { Script.RemoveMT(); Script.AppendLine(@"ConvertToRGB32(matrix=""Rec709"")"); } else if (!multiThreaded) Script.RemoveMT(); Script.WriteToFile(PreviewScriptFile); SaveSettingsFile(settings, PreviewSettingsFile); }
/// <summary> /// Starts encoding with specified settings. If an encoding is already in process, it will be added /// to the queue and start once the previous encodings are finished. /// </summary> /// <param name="settings">The encoding settings.</param> public async Task EncodeFileAsync(MediaEncoderSettings settings) { settings.JobIndex = ++JobIndex; // Files must be prepared before adding to queue so that user can replace preview files. DeleteJobFiles(settings); File.Delete(PreviewScriptFile); File.Delete(PreviewSettingsFile); if (settings.ConvertToAvi) SafeMove(PreviewSourceFile, settings.InputFile); SaveSettingsFile(settings, settings.SettingsFile); AviSynthScriptBuilder Script = new AviSynthScriptBuilder(settings.CustomScript); if (Script.IsEmpty) Script = GenerateVideoScript(settings, settings.InputFile, false, true); else Script.Replace(Script.GetAsciiPath(PreviewSourceFile), Script.GetAsciiPath(settings.InputFile)); //Script.DitherOut(true); Script.WriteToFile(settings.ScriptFile); await StartEncodeFileAsync(settings); }