public static string genCommandline(string input, string output, Dar?d, int hres, int vres, int fps_n, int fps_d, ref ulong numberOfFrames, x265Settings _xs, Zone[] zones, LogItem log) { int qp; StringBuilder sb = new StringBuilder(); CultureInfo ci = new CultureInfo("en-us"); x265Settings xs = (x265Settings)_xs.Clone(); MeGUI.packages.video.x265.x265SettingsHandler oSettingsHandler = new packages.video.x265.x265SettingsHandler(xs, log); // log if (log != null) { if (!String.IsNullOrEmpty(xs.CustomEncoderOptions)) { log.LogEvent("custom command line: " + xs.CustomEncoderOptions); } sb.Append("/c \"\"" + MainForm.Instance.Settings.FFmpeg.Path + "\" -loglevel level+error -i \"" + input + "\" -strict -1 -f yuv4mpegpipe - | "); if (!MainForm.Instance.Settings.Usex64Tools) { sb.Append("\"" + Path.Combine(Path.GetDirectoryName(MainForm.Instance.Settings.X265.Path), @"x86\x265.exe") + "\" "); } else { sb.Append("\"" + Path.Combine(Path.GetDirectoryName(MainForm.Instance.Settings.X265.Path), @"x64\x265.exe") + "\" "); } } #region main tab ///<summary> /// x265 Main Tab Settings ///</summary> // x265 Presets if (!xs.CustomEncoderOptions.Contains("--preset ")) { switch (xs.x265PresetLevel) { case x265Settings.x265PresetLevelModes.ultrafast: sb.Append("--preset ultrafast "); break; case x265Settings.x265PresetLevelModes.superfast: sb.Append("--preset superfast "); break; case x265Settings.x265PresetLevelModes.veryfast: sb.Append("--preset veryfast "); break; case x265Settings.x265PresetLevelModes.faster: sb.Append("--preset faster "); break; case x265Settings.x265PresetLevelModes.fast: sb.Append("--preset fast "); break; //case x265Settings.x265PresetLevelModes.medium: sb.Append("--preset medium "); break; // default value case x265Settings.x265PresetLevelModes.slow: sb.Append("--preset slow "); break; case x265Settings.x265PresetLevelModes.slower: sb.Append("--preset slower "); break; case x265Settings.x265PresetLevelModes.veryslow: sb.Append("--preset veryslow "); break; case x265Settings.x265PresetLevelModes.placebo: sb.Append("--preset placebo "); break; } } // x265 Tunings if (!xs.CustomEncoderOptions.Contains("--tune ")) { switch (xs.x265PsyTuning) { case x265Settings.x265PsyTuningModes.PSNR: sb.Append("--tune psnr "); break; case x265Settings.x265PsyTuningModes.SSIM: sb.Append("--tune ssim "); break; case x265Settings.x265PsyTuningModes.FastDecode: sb.Append("--tune fastdecode "); break; case x265Settings.x265PsyTuningModes.ZeroLatency: sb.Append("--tune zerolatency "); break; case x265Settings.x265PsyTuningModes.Grain: sb.Append("--tune grain "); break; default: break; } } // Encoding Modes switch (xs.VideoEncodingType) { case VideoCodecSettings.VideoEncodingMode.CBR: if (!xs.CustomEncoderOptions.Contains("--bitrate ")) { sb.Append("--bitrate " + xs.BitrateQuantizer + " "); } break; case VideoCodecSettings.VideoEncodingMode.CQ: if (!xs.CustomEncoderOptions.Contains("--qp ")) { qp = (int)xs.QuantizerCRF; sb.Append("--qp " + qp.ToString(ci) + " "); } break; case VideoCodecSettings.VideoEncodingMode.twopass1: // 2 pass first pass sb.Append("--pass 1 --bitrate " + xs.BitrateQuantizer + " --stats " + "\"" + xs.Logfile + "\" "); break; case VideoCodecSettings.VideoEncodingMode.twopass2: // 2 pass second pass case VideoCodecSettings.VideoEncodingMode.twopassAutomated: // automated twopass sb.Append("--pass 2 --bitrate " + xs.BitrateQuantizer + " --stats " + "\"" + xs.Logfile + "\" "); break; case VideoCodecSettings.VideoEncodingMode.threepass1: // 3 pass first pass sb.Append("--pass 1 --bitrate " + xs.BitrateQuantizer + " --stats " + "\"" + xs.Logfile + "\" "); break; case VideoCodecSettings.VideoEncodingMode.threepass2: // 3 pass 2nd pass sb.Append("--pass 3 --bitrate " + xs.BitrateQuantizer + " --stats " + "\"" + xs.Logfile + "\" "); break; case VideoCodecSettings.VideoEncodingMode.threepass3: // 3 pass 3rd pass case VideoCodecSettings.VideoEncodingMode.threepassAutomated: // automated threepass, show third pass options sb.Append("--pass 3 --bitrate " + xs.BitrateQuantizer + " --stats " + "\"" + xs.Logfile + "\" "); break; case VideoCodecSettings.VideoEncodingMode.quality: // constant quality if (!xs.CustomEncoderOptions.Contains("--crf ")) { if (xs.QuantizerCRF != 28) { sb.Append("--crf " + xs.QuantizerCRF.ToString(ci) + " "); } } break; } // Threads if (!xs.CustomEncoderOptions.Contains("--frame-threads ")) { if (xs.NbThreads > 0) { sb.Append("--frame-threads " + xs.NbThreads + " "); } } #endregion string CustomSarValue; xs.SampleAR = oSettingsHandler.getSar(d, hres, vres, out CustomSarValue, String.Empty); // get number of frames to encode oSettingsHandler.getFrames(ref numberOfFrames); xs.CustomEncoderOptions = oSettingsHandler.getCustomCommandLine(); if (!String.IsNullOrEmpty(xs.CustomEncoderOptions)) // add custom encoder options { sb.Append(xs.CustomEncoderOptions + " "); } switch (xs.SampleAR) { case 0: { if (!String.IsNullOrEmpty(CustomSarValue)) { sb.Append("--sar " + CustomSarValue + " "); } break; } case 1: sb.Append("--sar 1:1 "); break; case 2: sb.Append("--sar 4:3 "); break; case 3: sb.Append("--sar 8:9 "); break; case 4: sb.Append("--sar 10:11 "); break; case 5: sb.Append("--sar 12:11 "); break; case 6: sb.Append("--sar 16:11 "); break; case 7: sb.Append("--sar 16:15 "); break; case 8: sb.Append("--sar 32:27 "); break; case 9: sb.Append("--sar 40:33 "); break; case 10: sb.Append("--sar 64:45 "); break; } if (log != null) { // input/output if (xs.VideoEncodingType == VideoCodecSettings.VideoEncodingMode.twopass1 || xs.VideoEncodingType == VideoCodecSettings.VideoEncodingMode.threepass1) { sb.Append("--output NUL "); } else if (!String.IsNullOrEmpty(output)) { sb.Append("--output " + "\"" + output + "\" "); } sb.Append("--frames " + numberOfFrames + " --y4m -\""); } return(sb.ToString()); }
public static string genCommandline(string input, string output, Dar?d, int hres, int vres, int fps_n, int fps_d, x265Settings _xs, Zone[] zones, LogItem log) { int qp; StringBuilder sb = new StringBuilder(); CultureInfo ci = new CultureInfo("en-us"); x265Settings xs = (x265Settings)_xs.Clone(); // log if (log != null) { log.LogEvent("resolution: " + hres + "x" + vres); log.LogEvent("frame rate: " + fps_n + "/" + fps_d); if (d.HasValue) { log.LogValue("aspect ratio", d.Value); } if (!String.IsNullOrEmpty(xs.CustomEncoderOptions)) { log.LogEvent("custom command line: " + xs.CustomEncoderOptions); } string path = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "tools\\x265"); #if x86 if (OSInfo.isWow64()) { sb.Append("--x265-binary \"" + Path.Combine(path, "x64\\x265.exe") + "\" "); } else { sb.Append("--x265-binary \"" + Path.Combine(path, "x86\\x265.exe") + "\" "); } #else sb.Append("--x265-binary \"" + Path.Combine(path, "x64\\x265.exe") + "\" "); #endif } #region main tab ///<summary> /// x265 Main Tab Settings ///</summary> // x265 Presets if (!xs.CustomEncoderOptions.Contains("--preset ")) { switch (xs.x265PresetLevel) { case x265Settings.x265PresetLevelModes.ultrafast: sb.Append("--preset ultrafast "); break; case x265Settings.x265PresetLevelModes.superfast: sb.Append("--preset superfast "); break; case x265Settings.x265PresetLevelModes.veryfast: sb.Append("--preset veryfast "); break; case x265Settings.x265PresetLevelModes.faster: sb.Append("--preset faster "); break; case x265Settings.x265PresetLevelModes.fast: sb.Append("--preset fast "); break; //case x265Settings.x265PresetLevelModes.medium: sb.Append("--preset medium "); break; // default value case x265Settings.x265PresetLevelModes.slow: sb.Append("--preset slow "); break; case x265Settings.x265PresetLevelModes.slower: sb.Append("--preset slower "); break; case x265Settings.x265PresetLevelModes.veryslow: sb.Append("--preset veryslow "); break; case x265Settings.x265PresetLevelModes.placebo: sb.Append("--preset placebo "); break; } } // x265 Tunings if (!xs.CustomEncoderOptions.Contains("--tune ")) { switch (xs.x265PsyTuning) { case x265Settings.x265PsyTuningModes.PSNR: sb.Append("--tune psnr "); break; case x265Settings.x265PsyTuningModes.SSIM: sb.Append("--tune ssim "); break; case x265Settings.x265PsyTuningModes.FastDecode: sb.Append("--tune fastdecode "); break; case x265Settings.x265PsyTuningModes.ZeroLatency: sb.Append("--tune zerolatency "); break; default: break; } } // Encoding Modes switch (xs.EncodingMode) { case 0: // ABR if (!xs.CustomEncoderOptions.Contains("--bitrate ")) { sb.Append("--bitrate " + xs.BitrateQuantizer + " "); } break; case 1: // CQ if (!xs.CustomEncoderOptions.Contains("--qp ")) { qp = (int)xs.QuantizerCRF; sb.Append("--qp " + qp.ToString(ci) + " "); } break; /* case 2: // 2 pass first pass * sb.Append("--pass 1 --bitrate " + xs.BitrateQuantizer + " --stats " + "\"" + xs.Logfile + "\" "); * break; * case 3: // 2 pass second pass * case 4: // automated twopass * sb.Append("--pass 2 --bitrate " + xs.BitrateQuantizer + " --stats " + "\"" + xs.Logfile + "\" "); * break; * case 5: // 3 pass first pass * sb.Append("--pass 1 --bitrate " + xs.BitrateQuantizer + " --stats " + "\"" + xs.Logfile + "\" "); * break; * case 6: // 3 pass 2nd pass * sb.Append("--pass 3 --bitrate " + xs.BitrateQuantizer + " --stats " + "\"" + xs.Logfile + "\" "); * break; * case 7: // 3 pass 3rd pass * case 8: // automated threepass, show third pass options * sb.Append("--pass 3 --bitrate " + xs.BitrateQuantizer + " --stats " + "\"" + xs.Logfile + "\" "); * break;*/ case 2: // constant quality if (!xs.CustomEncoderOptions.Contains("--crf ")) { if (xs.QuantizerCRF != 28) { sb.Append("--crf " + xs.QuantizerCRF.ToString(ci) + " "); } } break; } // Threads if (!xs.CustomEncoderOptions.Contains("--frame-threads ")) { if (xs.NbThreads > 0) { sb.Append("--frame-threads " + xs.NbThreads + " "); } } if (!String.IsNullOrEmpty(xs.CustomEncoderOptions)) // add custom encoder options { sb.Append(xs.CustomEncoderOptions + " "); } if (!String.IsNullOrEmpty(output)) { sb.Append(" --output " + "\"" + output + "\" "); } if (!String.IsNullOrEmpty(input)) { sb.Append("\"" + input + "\""); } #endregion return(sb.ToString()); }