public async Task AddSar(ulong roleId, ulong guildId) => await _soraTransactor.DoInTransactionAsync(async context => { var sar = new Sar(roleId, guildId); context.Sars.Add(sar); await context.SaveChangesAsync().ConfigureAwait(false); }).ConfigureAwait(false);
public static List <decimal?> Sar(this IEnumerable <ICandle> candles, double?accelerationFactor = null, double?maximumAccelerationFactor = null) { accelerationFactor = accelerationFactor ?? 0.02; maximumAccelerationFactor = maximumAccelerationFactor ?? 0.2; IIndicatorOptions options = new SarOptions(accelerationFactor.Value, maximumAccelerationFactor.Value); Sar sar = new Sar(); return(sar.Get(candles, options)); }
/// <summary> /// Checks input video file for device compatibility /// </summary> /// <param name="hRes">the horizontal resolution</param> /// <param name="vRes">the vertical resolution</param> /// <param name="fps_n">fps numerator</param> /// <param name="fps_d">fps denominator</param> /// <returns>whether the source could be opened or not</returns> public void CheckInputFile(Dar?d, int hres, int vres, int fps_n, int fps_d) { if (_log == null) { return; } if (_device.BluRay == true) { if ((hres == 1920 || hres == 1440) && vres == 1080) { string fps = fps_n + "/" + fps_d; Double dfps = Double.Parse(fps_n.ToString()) / fps_d; if (fps.Equals("24000/1001") || dfps == 24) { if (_xs.InterlacedMode != x264Settings.x264InterlacedModes.progressive) { _xs.InterlacedMode = x264Settings.x264InterlacedModes.progressive; _log.LogEvent("the selected device does not support interlaced encoding of " + fps_n + "/" + fps_d + " fps. changing interlaced mode to progressive.", ImageType.Warning); } _xs.FakeInterlaced = _xs.PicStruct = false; } else if (dfps == 25 || fps.Equals("30000/1001")) { if (_xs.InterlacedMode == x264Settings.x264InterlacedModes.progressive) { _xs.FakeInterlaced = _xs.PicStruct = true; } else { _xs.FakeInterlaced = _xs.PicStruct = false; } } else if (dfps == 30) { _xs.FakeInterlaced = _xs.PicStruct = false; if (_xs.InterlacedMode == x264Settings.x264InterlacedModes.progressive) { _xs.InterlacedMode = x264Settings.x264InterlacedModes.tff; _log.LogEvent("the selected device does not support progressive encoding of " + fps_n + "/" + fps_d + " fps. changing interlaced mode to tff.", ImageType.Warning); } } else { _log.LogEvent("the selected device does not support " + fps_n + "/" + fps_d + " fps with a resolution of " + hres + "x" + vres + ". Supported are 24000/1001, 24/1, 25/1, 30000/1001 and 30/1.", ImageType.Warning); } _xs.ColorPrim = _xs.Transfer = _xs.ColorMatrix = 1; if (hres == 1440) { _xs.SampleAR = 2; } else { _xs.SampleAR = 1; } _xs.X264PullDown = 0; } else if (hres == 1280 && vres == 720) { if (_xs.InterlacedMode != x264Settings.x264InterlacedModes.progressive) { _xs.InterlacedMode = x264Settings.x264InterlacedModes.progressive; _log.LogEvent("the selected device does not support interlaced encoding of " + hres + "x" + vres + ". changing interlaced mode to progressive.", ImageType.Warning); } _xs.FakeInterlaced = _xs.PicStruct = false; _xs.X264PullDown = 0; string fps = fps_n + "/" + fps_d; Double dfps = Double.Parse(fps_n.ToString()) / fps_d; if (dfps == 25 || fps.Equals("30000/1001")) { if (_xs.X264PullDown != 4) { _xs.X264PullDown = 4; _log.LogEvent("changing --pulldown to double as it is required for encoding of " + hres + "x" + vres + " with " + fps_n + "/" + fps_d + " fps for the selected device.", ImageType.Information); } } else if (!fps.Equals("24000/1001") && dfps != 24 && dfps != 50 && !fps.Equals("60000/1001")) { _log.LogEvent("the selected device does not support " + fps_n + "/" + fps_d + " fps with a resolution of " + hres + "x" + vres + ". Supported are 24000/1001, 24/1, 25/1, 30000/1001, 50/1 and 60000/1001.", ImageType.Warning); } _xs.ColorPrim = _xs.Transfer = _xs.ColorMatrix = 1; _xs.SampleAR = 1; } else if (hres == 720 && vres == 576) { if (_xs.SampleAR != 5 && _xs.SampleAR != 6) { if (!d.HasValue) { _xs.SampleAR = 6; _log.LogEvent("assume --sar 16:11 as only 16:11 or 12:11 are supported with a resolution of " + hres + "x" + vres + ". for the selected device", ImageType.Warning); } else { Sar s = d.Value.ToSar(hres, vres); _log.LogEvent("detected --sar " + s.X + ":" + s.Y, ImageType.Information); Double dDiff16 = 16.0 / 11 - Double.Parse(s.X.ToString()) / s.Y; Double dDiff4 = 12.0 / 11 - Double.Parse(s.X.ToString()) / s.Y; if (dDiff16 <= 0) { _xs.SampleAR = 6; _log.LogEvent("assume --sar 16:11 as only 16:11 or 12:11 are supported with a resolution of " + hres + "x" + vres + " for the selected device.", ImageType.Warning); } else if (dDiff4 >= 0) { _xs.SampleAR = 5; _log.LogEvent("assume --sar 12:11 as only 16:11 or 12:11 are supported with a resolution of " + hres + "x" + vres + " for the selected device.", ImageType.Warning); } else if (Math.Min(dDiff16, -dDiff4) == dDiff16) { _xs.SampleAR = 6; _log.LogEvent("assume --sar 16:11 as only 16:11 or 12:11 are supported with a resolution of " + hres + "x" + vres + " for the selected device.", ImageType.Warning); } else { _xs.SampleAR = 5; _log.LogEvent("assume --sar 12:11 as only 16:11 or 12:11 are supported with a resolution of " + hres + "x" + vres + " for the selected device.", ImageType.Warning); } } } Double dfps = Double.Parse(fps_n.ToString()) / fps_d; if (dfps == 25) { if (_xs.InterlacedMode == x264Settings.x264InterlacedModes.progressive) { _xs.FakeInterlaced = _xs.PicStruct = true; } else { _xs.FakeInterlaced = _xs.PicStruct = false; } } else { _log.LogEvent("the selected device does not support " + fps_n + "/" + fps_d + " fps with a resolution of " + hres + "x" + vres + ". Supported is 25/1.", ImageType.Warning); } _xs.ColorPrim = _xs.Transfer = _xs.ColorMatrix = 3; _xs.X264PullDown = 0; } else if (hres == 720 && vres == 480) { if (_xs.SampleAR != 8 && _xs.SampleAR != 4) { if (!d.HasValue) { _xs.SampleAR = 8; _log.LogEvent("assume --sar 40:33 as only 40:33 or 10:11 are supported with a resolution of " + hres + "x" + vres + " for the selected device.", ImageType.Warning); } else { Sar s = d.Value.ToSar(hres, vres); _log.LogEvent("detected --sar " + s.X + ":" + s.Y, ImageType.Information); Double dDiff16 = 40.0 / 33 - Double.Parse(s.X.ToString()) / s.Y; Double dDiff4 = 10.0 / 11 - Double.Parse(s.X.ToString()) / s.Y; if (dDiff16 <= 0) { _xs.SampleAR = 8; _log.LogEvent("assume --sar 40:33 as only 40:33 or 10:11 are supported with a resolution of " + hres + "x" + vres + " for the selected device.", ImageType.Warning); } else if (dDiff4 >= 0) { _xs.SampleAR = 4; _log.LogEvent("assume --sar 10:11 as only 40:33 or 10:11 are supported with a resolution of " + hres + "x" + vres + " for the selected device.", ImageType.Warning); } else if (Math.Min(dDiff16, -dDiff4) == dDiff16) { _xs.SampleAR = 8; _log.LogEvent("assume --sar 40:33 as only 40:33 or 10:11 are supported with a resolution of " + hres + "x" + vres + " for the selected device.", ImageType.Warning); } else { _xs.SampleAR = 4; _log.LogEvent("assume --sar 10:11 as only 40:33 or 10:11 are supported with a resolution of " + hres + "x" + vres + " for the selected device.", ImageType.Warning); } } } string fps = fps_n + "/" + fps_d; if (fps.Equals("30000/1001")) { _xs.X264PullDown = 0; _xs.FakeInterlaced = _xs.PicStruct = false; if (_xs.InterlacedMode == x264Settings.x264InterlacedModes.progressive) { _xs.InterlacedMode = x264Settings.x264InterlacedModes.tff; _log.LogEvent("the selected device does not support progressive encoding of " + fps_n + "/" + fps_d + " fps. changing interlaced mode to tff.", ImageType.Warning); } } else if (fps.Equals("24000/1001")) { if (_xs.X264PullDown != 2) { _xs.X264PullDown = 2; _log.LogEvent("changing --pulldown to 32 as it is required for encoding of " + hres + "x" + vres + " with " + fps_n + "/" + fps_d + " fps for the selected device.", ImageType.Warning); } if (_xs.InterlacedMode != x264Settings.x264InterlacedModes.progressive) { _xs.InterlacedMode = x264Settings.x264InterlacedModes.progressive; _log.LogEvent("the selected device does not support interlaced encoding of " + hres + "x" + vres + ". changing interlaced mode to progressive.", ImageType.Warning); } } else { _log.LogEvent("the selected device does not support " + fps_n + "/" + fps_d + " fps with a resolution of " + hres + "x" + vres + ". Supported are 30000/1001 and 24000/1001.", ImageType.Warning); } _xs.ColorPrim = _xs.ColorMatrix = 4; _xs.Transfer = 7; } else { _log.LogEvent("the selected device does not support a resolution of " + hres + "x" + vres + ". Supported are 1920x1080, 1440x1080, 1280x720, 720x576 and 720x480.", ImageType.Warning); } } else { if (_device.Width > 0 && hres > _device.Width) { _log.LogEvent("the selected device does not support a resolution width of " + hres + ". The maximum value is " + _device.Width, ImageType.Warning); } if (_device.Height > 0 && vres > _device.Height) { _log.LogEvent("the selected device does not support a resolution height of " + vres + ". The maximum value is " + _device.Height, ImageType.Warning); } } }
/// <summary> /// Calculates --sar value /// </summary> /// <returns>the --sar value</returns> public int getSar(Dar?d, int hRes, int vRes, out string CustomSarValue, string CustomSarValueInput) { string strCustomValue; CustomSarValue = String.Empty; if (String.IsNullOrEmpty(CustomSarValueInput) && extractCustomCommand("sar", out strCustomValue)) { switch (strCustomValue.ToLowerInvariant()) { case "1:1": _xs.SampleAR = 1; break; case "4:3": _xs.SampleAR = 2; break; case "8:9": _xs.SampleAR = 3; break; case "10:11": _xs.SampleAR = 4; break; case "12:11": _xs.SampleAR = 5; break; case "16:11": _xs.SampleAR = 6; break; case "16:15": _xs.SampleAR = 7; break; case "32:27": _xs.SampleAR = 8; break; case "40:33": _xs.SampleAR = 9; break; case "64:45": _xs.SampleAR = 10; break; default: CustomSarValue = strCustomValue; _xs.SampleAR = 0; break; } } if (d.HasValue && _xs.SampleAR == 0 && String.IsNullOrEmpty(CustomSarValue) && String.IsNullOrEmpty(CustomSarValueInput)) { Sar s = d.Value.ToSar(hRes, vRes); switch (s.X + ":" + s.Y) { case "1:1": _xs.SampleAR = 1; break; case "4:3": _xs.SampleAR = 2; break; case "8:9": _xs.SampleAR = 3; break; case "10:11": _xs.SampleAR = 4; break; case "12:11": _xs.SampleAR = 5; break; case "16:11": _xs.SampleAR = 6; break; case "16:15": _xs.SampleAR = 7; break; case "32:27": _xs.SampleAR = 8; break; case "40:33": _xs.SampleAR = 9; break; case "64:45": _xs.SampleAR = 10; break; default: CustomSarValue = s.X + ":" + s.Y; break; } } return(_xs.SampleAR); }
public static string genCommandline(string input, string output, Dar?d, xvidSettings xs, int hres, int vres) { StringBuilder sb = new StringBuilder(); CultureInfo ci = new CultureInfo("en-us"); sb.Append("-i \"" + input + "\" "); switch (xs.EncodingMode) { case 0: // CBR sb.Append("-single -bitrate " + xs.BitrateQuantizer + " "); // add bitrate break; case 1: // CQ sb.Append("-single -cq " + xs.Quantizer + " "); // add quantizer break; case 2: // 2 pass first pass sb.Append("-pass1 " + "\"" + xs.Logfile + "\" -bitrate " + xs.BitrateQuantizer + " "); // add logfile break; case 3: // 2 pass second pass case 4: // automated twopass sb.Append("-pass2 " + "\"" + xs.Logfile + "\" -bitrate " + xs.BitrateQuantizer + " "); // add logfile break; } if (xs.EncodingMode <= 1) // 1 pass modes { if (xs.ReactionDelayFactor != 16) { sb.Append("-reaction " + xs.ReactionDelayFactor + " "); } if (xs.AveragingPeriod != 100) { sb.Append("-averaging " + xs.AveragingPeriod + " "); } if (xs.RateControlBuffer != 100) { sb.Append("-smoother " + xs.RateControlBuffer + " "); } } else // two pass modes { if (xs.KeyFrameBoost != 10) { sb.Append("-kboost " + xs.KeyFrameBoost + " "); } if (xs.KeyframeThreshold != 1) { sb.Append("-kthresh " + xs.KeyframeThreshold + " "); } if (xs.KeyframeReduction != 20) { sb.Append("-kreduction " + xs.KeyframeReduction + " "); } if (xs.OverflowControlStrength != 5) { sb.Append("-ostrength " + xs.OverflowControlStrength + " "); } if (xs.MaxOverflowImprovement != 5) { sb.Append("-oimprove " + xs.MaxOverflowImprovement + " "); } if (xs.MaxOverflowDegradation != 5) { sb.Append("-odegrade " + xs.MaxOverflowDegradation + " "); } if (xs.HighBitrateDegradation != 0) { sb.Append("-chigh " + xs.HighBitrateDegradation + " "); } if (xs.LowBitrateImprovement != 0) { sb.Append("-clow " + xs.LowBitrateImprovement + " "); } sb.Append("-overhead 0 "); if (xs.VbvBuffer != 0) { sb.Append("-vbvsize " + xs.VbvBuffer + " "); } if (xs.VbvMaxRate != 0) { sb.Append("-vbvmax " + xs.VbvMaxRate + " "); } if (xs.VbvPeakRate != 0) { sb.Append("-vbvpeak " + xs.VbvPeakRate + " "); } } if (xs.Turbo) { sb.Append("-turbo "); } if (xs.KeyframeInterval != 300) { sb.Append("-max_key_interval " + xs.KeyframeInterval + " "); } if (!xs.PackedBitstream) // default is on in encraw { sb.Append("-nopacked "); } if (xs.MotionSearchPrecision != 6) { sb.Append("-quality " + xs.MotionSearchPrecision + " "); } if (xs.VHQMode != 1) { sb.Append("-vhqmode " + xs.VHQMode + " "); } if (xs.QPel) { sb.Append("-qpel "); } if (xs.GMC) { sb.Append("-gmc "); } if (xs.QuantizerMatrix == xvidSettings.MPEGMatrix) { sb.Append("-qtype 1 "); } else if (xs.QuantizerMatrix != xvidSettings.H263Matrix && !string.IsNullOrEmpty(xs.QuantizerMatrix)) { sb.Append("-qmatrix \"" + xs.QuantizerMatrix + "\" "); } if (xs.ClosedGOP) { sb.Append("-closed_gop "); } if (xs.AdaptiveQuant) { sb.Append("-lumimasking "); } if (xs.Interlaced) { sb.Append("-interlaced "); if (xs.BottomFieldFirst) { sb.Append("1 "); } else { sb.Append("2 "); } } if (xs.Greyscale) { sb.Append("-grey "); } if (xs.LumiMasking) { sb.Append("-lumimasking "); } if (!xs.Trellis) { sb.Append("-notrellis "); } if (!xs.ChromaMotion) { sb.Append("-nochromame "); } if (xs.MinQuantizer != 2) { sb.Append("-imin " + xs.MinQuantizer + " "); } if (xs.MaxQuantizer != 31) { sb.Append("-imax " + xs.MaxQuantizer + " "); } if (xs.MinPQuant != 2) { sb.Append("-pmin " + xs.MinPQuant + " "); } if (xs.MaxPQuant != 31) { sb.Append("-pmax " + xs.MaxPQuant + " "); } if (!xs.ClosedGOP) { sb.Append("-noclosed_gop "); } if (xs.FrameDropRatio != 0) { sb.Append("-drop " + xs.FrameDropRatio + " "); } if (xs.NbBframes != 2) { sb.Append("-max_bframes " + xs.NbBframes + " "); } if (xs.NbBframes > 0) { if (xs.VHQForBframes) { sb.Append("-bvhq "); } if (xs.BQuantRatio != 150) { sb.Append("-bquant_ratio " + xs.BQuantRatio + " "); } if (xs.BQuantOffset != 100) { sb.Append("-bquant_offset " + xs.BQuantOffset + " "); } if (xs.MinBQuant != 2) { sb.Append("-bmin " + xs.MinBQuant + " "); } if (xs.MaxBQuant != 31) { sb.Append("-bmax " + xs.MaxBQuant + " "); } } if (d.HasValue) // custom PAR mode { Sar s = d.Value.ToSar(hres, vres); sb.Append("-par " + s.X + ":" + s.Y + " "); } sb.Append("-threads " + xs.NbThreads + " "); if (xs.Zones != null && xs.Zones.Length > 0 && xs.CreditsQuantizer >= new decimal(1) && xs.EncodingMode != 1) // only for non CQ mode at the moment { foreach (Zone zone in xs.Zones) { if (zone.mode == ZONEMODE.QUANTIZER) { sb.Append("-zq " + zone.startFrame + " " + zone.modifier + " "); } if (zone.mode == ZONEMODE.WEIGHT) { sb.Append("-zw " + zone.startFrame + " "); double mod = (double)zone.modifier / 100.0; sb.Append(mod.ToString(ci) + " "); } } } if (xs.EncodingMode != 2) // not 2 pass vbr first pass, add output filename and output type { string extension = Path.GetExtension(output).ToLower(); if (extension.Equals(".mkv")) { sb.Append(" -mkv \"" + output + "\""); } else if (extension.Equals(".avi")) { sb.Append(" -avi \"" + output + "\""); } else { sb.Append(" -o \"" + output + "\""); } } if (!xs.CustomEncoderOptions.Equals("")) // add custom encoder options { sb.Append(" " + xs.CustomEncoderOptions); } return(sb.ToString()); }
public static string genCommandline(string input, string output, Dar?d, int hres, int vres, x264Settings xs) { StringBuilder sb = new StringBuilder(); CultureInfo ci = new CultureInfo("en-us"); if (xs.EncodingMode == 4 || xs.EncodingMode == 7) { xs.Turbo = false; // turn off turbo to prevent inconsistent commandline preview } switch (xs.EncodingMode) { case 0: // ABR sb.Append("--bitrate " + xs.BitrateQuantizer + " "); break; case 1: // CQ if (xs.Lossless) { sb.Append("--qp 0 "); } else { sb.Append("--qp " + xs.QuantizerCRF.ToString(new CultureInfo("en-us")) + " "); } 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 9: // constant quality sb.Append("--crf " + xs.QuantizerCRF.ToString(new CultureInfo("en-us")) + " "); break; } // now add the rest of the x264 encoder options // AVC Level if (xs.Level != 15) // unrestricted (x264.exe default) { sb.Append("--level " + AVCLevels.getCLILevelNames()[xs.Level] + " "); } if (xs.KeyframeInterval != 250) // gop size of 250 is default { sb.Append("--keyint " + xs.KeyframeInterval + " "); } if (xs.MinGOPSize != 25) { sb.Append("--min-keyint " + xs.MinGOPSize + " "); } if (xs.Turbo) { xs.NbRefFrames = 1; xs.SubPelRefinement = 0; // Q-Pel 1 iteration xs.METype = 0; // diamond search xs.I4x4mv = false; xs.P4x4mv = false; xs.I8x8mv = false; xs.P8x8mv = false; xs.B8x8mv = false; xs.AdaptiveDCT = false; xs.MixedRefs = false; xs.BRDO = false; xs.X264Trellis = 0; // disable trellis xs.noFastPSkip = false; xs.WeightedBPrediction = false; xs.biME = false; } if (xs.DeadZoneInter != 21) { sb.Append("--deadzone-inter " + xs.DeadZoneInter + " "); } if (xs.DeadZoneIntra != 11) { sb.Append("--deadzone-intra " + xs.DeadZoneIntra + " "); } if (xs.NbRefFrames != 1) // 1 ref frame is default { sb.Append("--ref " + xs.NbRefFrames + " "); } if (xs.MixedRefs) { sb.Append("--mixed-refs "); } if (xs.noFastPSkip) { sb.Append("--no-fast-pskip "); } if (xs.NbBframes != 0) // 0 is default value, adaptive and pyramid are conditional on b frames being enabled { sb.Append("--bframes " + xs.NbBframes + " "); if (!xs.AdaptiveBFrames) { sb.Append("--no-b-adapt "); } if (xs.NbBframes > 1 && xs.BFramePyramid) // pyramid needs a minimum of 2 b frames { sb.Append("--b-pyramid "); } if (xs.BRDO) { sb.Append("--b-rdo "); } if (xs.biME) { sb.Append("--bime "); } if (xs.WeightedBPrediction) { sb.Append("--weightb "); } if (xs.BframePredictionMode != 1) { sb.Append("--direct "); if (xs.BframePredictionMode == 0) { sb.Append("none "); } else if (xs.BframePredictionMode == 2) { sb.Append("temporal "); } else if (xs.BframePredictionMode == 3) { sb.Append("auto "); } } } if (xs.Deblock) // deblocker active, add options { if (xs.AlphaDeblock != 0 || xs.BetaDeblock != 0) // 0 is default value { sb.Append("--filter " + xs.AlphaDeblock + "," + xs.BetaDeblock + " "); } } else // no deblocking { sb.Append("--nf "); } if (!xs.Cabac) // no cabac { sb.Append("--no-cabac "); } if (xs.SubPelRefinement + 1 != 5) // non default subpel refinement { int subq = xs.SubPelRefinement + 1; sb.Append("--subme " + subq + " "); } if (!xs.ChromaME) { sb.Append("--no-chroma-me "); } if (xs.X264Trellis > 0) { sb.Append("--trellis " + xs.X264Trellis + " "); } // now it's time for the macroblock types if (xs.P8x8mv || xs.B8x8mv || xs.I4x4mv || xs.I8x8mv || xs.P4x4mv || xs.AdaptiveDCT) { sb.Append("--partitions "); if (xs.I4x4mv && xs.P4x4mv && xs.I8x8mv && xs.P8x8mv && xs.B8x8mv) { sb.Append("all "); } else { if (xs.P8x8mv) // default is checked { sb.Append("p8x8,"); } if (xs.B8x8mv) // default is checked { sb.Append("b8x8,"); } if (xs.I4x4mv) // default is checked { sb.Append("i4x4,"); } if (xs.P4x4mv) // default is unchecked { sb.Append("p4x4,"); } if (xs.I8x8mv) // default is checked { sb.Append("i8x8"); } if (sb.ToString().EndsWith(",")) { sb.Remove(sb.Length - 1, 1); } } if (xs.AdaptiveDCT) // default is unchecked { sb.Append(" --8x8dct "); } if (!sb.ToString().EndsWith(" ")) { sb.Append(" "); } } else { sb.Append("--partitions none "); } if (xs.EncodingMode != 1) // doesn't apply to CQ mode { if (xs.MinQuantizer != 10) // default min quantizer is 10 { sb.Append("--qpmin " + xs.MinQuantizer + " "); } if (xs.MaxQuantizer != 51) // 51 is the default max quanitzer { sb.Append("--qpmax " + xs.MaxQuantizer + " "); } if (xs.MaxQuantDelta != 4) // 4 is the default value { sb.Append("--qpstep " + xs.MaxQuantDelta + " "); } if (xs.IPFactor != new decimal(1.4)) // 1.4 is the default value { sb.Append("--ipratio " + xs.IPFactor.ToString(ci) + " "); } if (xs.PBFactor != new decimal(1.3)) // 1.3 is the default value here { sb.Append("--pbratio " + xs.PBFactor.ToString(ci) + " "); } if (xs.ChromaQPOffset != new decimal(0.0)) { sb.Append("--chroma-qp-offset " + xs.ChromaQPOffset.ToString(ci) + " "); } if (xs.VBVBufferSize > 0) { sb.Append("--vbv-bufsize " + xs.VBVBufferSize + " "); } if (xs.VBVMaxBitrate > 0) { sb.Append("--vbv-maxrate " + xs.VBVMaxBitrate + " "); } if (xs.VBVInitialBuffer != new decimal(0.9)) { sb.Append("--vbv-init " + xs.VBVInitialBuffer.ToString(ci) + " "); } if (xs.BitrateVariance != 1) { sb.Append("--ratetol " + xs.BitrateVariance.ToString(ci) + " "); } if (xs.QuantCompression != new decimal(0.6)) { sb.Append("--qcomp " + xs.QuantCompression.ToString(ci) + " "); } if (xs.EncodingMode > 1) // applies only to twopass { if (xs.TempComplexityBlur != 20) { sb.Append("--cplxblur " + xs.TempComplexityBlur.ToString(ci) + " "); } if (xs.TempQuanBlurCC != new decimal(0.5)) { sb.Append("--qblur " + xs.TempQuanBlurCC.ToString(ci) + " "); } } } if (xs.SCDSensitivity != new decimal(40)) { sb.Append("--scenecut " + xs.SCDSensitivity.ToString(ci) + " "); } if (xs.BframeBias != new decimal(0)) { sb.Append("--b-bias " + xs.BframeBias.ToString(ci) + " "); } if (xs.METype + 1 != 2) { sb.Append("--me "); if (xs.METype + 1 == 1) { sb.Append("dia "); } if (xs.METype + 1 == 3) { sb.Append("umh "); } if (xs.METype + 1 == 4) { sb.Append("esa "); } if (xs.METype + 1 == 5) { sb.Append("tesa "); } } if (xs.MERange != 16) { sb.Append("--merange " + xs.MERange + " "); } if (xs.NbThreads > 1) { sb.Append("--threads " + xs.NbThreads + " "); } if (xs.NbThreads == 0) { sb.Append("--threads auto "); } sb.Append("--thread-input "); if (xs.Zones != null && xs.Zones.Length > 0 && xs.CreditsQuantizer >= new decimal(1)) { sb.Append("--zones "); foreach (Zone zone in xs.Zones) { sb.Append(zone.startFrame + "," + zone.endFrame + ","); if (zone.mode == ZONEMODE.QUANTIZER) { sb.Append("q="); sb.Append(zone.modifier + "/"); } if (zone.mode == ZONEMODE.WEIGHT) { sb.Append("b="); double mod = (double)zone.modifier / 100.0; sb.Append(mod.ToString(ci) + "/"); } } sb.Remove(sb.Length - 1, 1); sb.Append(" "); } if (d.HasValue) { Sar s = d.Value.ToSar(hres, vres); sb.Append("--sar " + s.X + ":" + s.Y + " "); } if (xs.QuantizerMatrixType > 0) // custom matrices enabled { if (xs.QuantizerMatrixType == 1) { sb.Append("--cqm \"jvt\" "); } if (xs.QuantizerMatrixType == 2) { sb.Append("--cqmfile \"" + xs.QuantizerMatrix + "\" "); } } sb.Append("--progress "); // ensure that the progress is shown if (xs.NoDCTDecimate) { sb.Append("--no-dct-decimate "); } if (!xs.PSNRCalculation) { sb.Append("--no-psnr "); } if (!xs.SSIMCalculation) { sb.Append("--no-ssim "); } if (xs.EncodeInterlaced) { sb.Append("--interlaced "); } if (xs.NoiseReduction > 0) { sb.Append("--nr " + xs.NoiseReduction + " "); } //add the rest of the mencoder commandline regarding the output if (xs.EncodingMode == 2 || xs.EncodingMode == 5) { sb.Append("--output NUL "); } else { sb.Append("--output " + "\"" + output + "\" "); } sb.Append("\"" + input + "\" "); if (!xs.CustomEncoderOptions.Equals("")) // add custom encoder options { sb.Append(xs.CustomEncoderOptions); } return(sb.ToString()); }
public static string genCommandline(string input, string output, Dar?d, xvidSettings xs, int hres, int vres, int fps_n, int fps_d, Zone[] zones, LogItem log) { StringBuilder sb = new StringBuilder(); CultureInfo ci = new CultureInfo("en-us"); // log if (log != null) { if (!String.IsNullOrEmpty(xs.CustomEncoderOptions)) { log.LogEvent("custom command line: " + xs.CustomEncoderOptions); } } #region input options if (log != null) { sb.Append("-i \"" + input + "\" "); } #endregion #region output options if (log != null) { if (xs.VideoEncodingType != VideoCodecSettings.VideoEncodingMode.twopass1) // not 2 pass vbr first pass, add output filename and output type { sb.Append("-o \"" + output + "\" "); } } #endregion #region rate control options switch (xs.VideoEncodingType) { case VideoCodecSettings.VideoEncodingMode.twopass1: // 2 pass first pass sb.Append("-pass1 " + "\"" + xs.Logfile + "\" "); // add logfile break; case VideoCodecSettings.VideoEncodingMode.twopass2: // 2 pass second pass case VideoCodecSettings.VideoEncodingMode.twopassAutomated: // automated twopass sb.Append("-pass2 " + "\"" + xs.Logfile + "\" "); // add logfile break; } if (!xs.CustomEncoderOptions.Contains("-bitrate ") && !xs.CustomEncoderOptions.Contains("-cq ")) { if (xs.VideoEncodingType == VideoCodecSettings.VideoEncodingMode.CQ) { sb.Append("-cq " + xs.Quantizer.ToString(ci) + " "); // add quantizer } else if (xs.BitrateQuantizer != 700) { sb.Append("-bitrate " + xs.BitrateQuantizer + " "); // add bitrate } } if (!xs.CustomEncoderOptions.Contains("-max_key_interval ") && xs.KeyframeInterval != 300) { sb.Append("-max_key_interval " + xs.KeyframeInterval + " "); } if (zones != null && zones.Length > 0 && xs.CreditsQuantizer >= new decimal(1)) { foreach (Zone zone in zones) { if (zone.mode == ZONEMODE.Quantizer) { sb.Append("-zq " + zone.startFrame + " " + zone.modifier + " "); } if (zone.mode == ZONEMODE.Weight) { sb.Append("-zw " + zone.startFrame + " "); double mod = (double)zone.modifier / 100.0; sb.Append(mod.ToString(ci) + " "); } } } #endregion #region single pass options if (xs.VideoEncodingType == VideoCodecSettings.VideoEncodingMode.CQ || xs.VideoEncodingType == VideoCodecSettings.VideoEncodingMode.CBR) { if (!xs.CustomEncoderOptions.Contains("-reaction ") && xs.ReactionDelayFactor != 16) { sb.Append("-reaction " + xs.ReactionDelayFactor + " "); } if (!xs.CustomEncoderOptions.Contains("-averaging ") && xs.AveragingPeriod != 100) { sb.Append("-averaging " + xs.AveragingPeriod + " "); } if (!xs.CustomEncoderOptions.Contains("-smoother ") && xs.RateControlBuffer != 100) { sb.Append("-smoother " + xs.RateControlBuffer + " "); } } #endregion #region second pass options if (xs.VideoEncodingType != VideoCodecSettings.VideoEncodingMode.CQ && xs.VideoEncodingType != VideoCodecSettings.VideoEncodingMode.CBR) { if (!xs.CustomEncoderOptions.Contains("-kboost ") && xs.KeyFrameBoost != 10) { sb.Append("-kboost " + xs.KeyFrameBoost + " "); } if (!xs.CustomEncoderOptions.Contains("-kthresh ") && xs.KeyframeThreshold != 1) { sb.Append("-kthresh " + xs.KeyframeThreshold + " "); } if (!xs.CustomEncoderOptions.Contains("-kreduction ") && xs.KeyframeReduction != 20) { sb.Append("-kreduction " + xs.KeyframeReduction + " "); } if (!xs.CustomEncoderOptions.Contains("-ostrength ") && xs.OverflowControlStrength != 5) { sb.Append("-ostrength " + xs.OverflowControlStrength + " "); } if (!xs.CustomEncoderOptions.Contains("-oimprove ") && xs.MaxOverflowImprovement != 5) { sb.Append("-oimprove " + xs.MaxOverflowImprovement + " "); } if (!xs.CustomEncoderOptions.Contains("-odegrade ") && xs.MaxOverflowDegradation != 5) { sb.Append("-odegrade " + xs.MaxOverflowDegradation + " "); } if (!xs.CustomEncoderOptions.Contains("-chigh ") && xs.HighBitrateDegradation != 0) { sb.Append("-chigh " + xs.HighBitrateDegradation + " "); } if (!xs.CustomEncoderOptions.Contains("-clow ") && xs.LowBitrateImprovement != 0) { sb.Append("-clow " + xs.LowBitrateImprovement + " "); } // -overhead missing if (xs.XvidProfile != 0) { int ivbvmax = 0, ivbvsize = 0, ivbvpeak = 0; switch (xs.XvidProfile) { case 1: ivbvmax = 4854000; ivbvsize = 3145728; ivbvpeak = 2359296; break; case 2: ivbvmax = 9708400; ivbvsize = 6291456; ivbvpeak = 4718592; break; case 3: ivbvmax = 20000000; ivbvsize = 16000000; ivbvpeak = 12000000; break; case 4: ivbvmax = 200000; ivbvsize = 262144; ivbvpeak = 196608; break; case 5: ivbvmax = 600000; ivbvsize = 655360; ivbvpeak = 491520; break; case 6: ivbvmax = xs.VbvMaxRate; ivbvsize = xs.VbvBuffer; ivbvpeak = xs.VbvPeakRate; break; } if (!xs.CustomEncoderOptions.Contains("-vbvsize ") && ivbvsize != 0) { sb.Append("-vbvsize " + ivbvsize + " "); } if (!xs.CustomEncoderOptions.Contains("-vbvmax ") && ivbvmax != 0) { sb.Append("-vbvmax " + ivbvmax + " "); } if (!xs.CustomEncoderOptions.Contains("-vbvpeak ") && ivbvpeak != 0) { sb.Append("-vbvpeak " + ivbvpeak + " "); } } } #endregion #region bframes options if (!xs.CustomEncoderOptions.Contains("-max_bframes ") && xs.NbBframes != 2) { sb.Append("-max_bframes " + xs.NbBframes + " "); } if (xs.NbBframes > 0) { if (!xs.CustomEncoderOptions.Contains("-bquant_ratio ") && xs.BQuantRatio != 150) { sb.Append("-bquant_ratio " + xs.BQuantRatio + " "); } if (!xs.CustomEncoderOptions.Contains("-bquant_offset ") && xs.BQuantOffset != 100) { sb.Append("-bquant_offset " + xs.BQuantOffset + " "); } } #endregion #region other options // -noasm missing if (!xs.CustomEncoderOptions.Contains("-turbo") && xs.Turbo) { sb.Append("-turbo "); } if (!xs.CustomEncoderOptions.Contains("-quality ") && xs.MotionSearchPrecision != 6) { sb.Append("-quality " + xs.MotionSearchPrecision + " "); } if (!xs.CustomEncoderOptions.Contains("-vhqmode ") && xs.VHQMode != 1) { sb.Append("-vhqmode " + xs.VHQMode + " "); } if (xs.NbBframes > 0 && !xs.CustomEncoderOptions.Contains("-bvhq ") && xs.VHQForBframes) { sb.Append("-bvhq "); } // -metric missing if (!xs.CustomEncoderOptions.Contains("-qpel ") && xs.QPel) { sb.Append("-qpel "); } if (!xs.CustomEncoderOptions.Contains("-gmc ") && xs.GMC) { sb.Append("-gmc "); } if (!xs.CustomEncoderOptions.Contains("-qtype ") && xs.QuantizerMatrix == xvidSettings.MPEGMatrix) { sb.Append("-qtype 1 "); } else if (!xs.CustomEncoderOptions.Contains("-qmatrix ") && xs.QuantizerMatrix != xvidSettings.H263Matrix && !string.IsNullOrEmpty(xs.QuantizerMatrix)) { sb.Append("-qmatrix \"" + xs.QuantizerMatrix + "\" "); } if (!xs.CustomEncoderOptions.Contains("-interlaced ") && xs.Interlaced) { sb.Append("-interlaced "); if (xs.BottomFieldFirst) { sb.Append("1 "); } else { sb.Append("2 "); } } if (!xs.CustomEncoderOptions.Contains("-nopacked") && !xs.PackedBitstream) { sb.Append("-nopacked "); } if (!xs.CustomEncoderOptions.Contains("-noclosed_gop") && !xs.ClosedGOP) { sb.Append("-noclosed_gop "); } if (!xs.CustomEncoderOptions.Contains("-masking ") && xs.HVSMasking != 0) { sb.Append("-masking " + xs.HVSMasking + " "); } // -stats missing // -ssim missing // -ssim_file missing // -debug missing // -vop_debug missing if (!xs.CustomEncoderOptions.Contains("-nochromame") && !xs.ChromaMotion) { sb.Append("-nochromame "); } if (!xs.CustomEncoderOptions.Contains("-notrellis") && !xs.Trellis) { sb.Append("-notrellis "); } if (!xs.CustomEncoderOptions.Contains("-imin ") && xs.MinQuantizer != 2) { sb.Append("-imin " + xs.MinQuantizer + " "); } if (!xs.CustomEncoderOptions.Contains("-imax ") && xs.MaxQuantizer != 31) { sb.Append("-imax " + xs.MaxQuantizer + " "); } if (xs.NbBframes > 0) { if (!xs.CustomEncoderOptions.Contains("-bmin ") && xs.MinBQuant != 2) { sb.Append("-bmin " + xs.MinBQuant + " "); } if (!xs.CustomEncoderOptions.Contains("-bmax ") && xs.MaxBQuant != 31) { sb.Append("-bmax " + xs.MaxBQuant + " "); } } if (!xs.CustomEncoderOptions.Contains("-pmin ") && xs.MinPQuant != 2) { sb.Append("-pmin " + xs.MinPQuant + " "); } if (!xs.CustomEncoderOptions.Contains("-pmax ") && xs.MaxPQuant != 31) { sb.Append("-pmax " + xs.MaxPQuant + " "); } if (!xs.CustomEncoderOptions.Contains("-drop ") && xs.FrameDropRatio != 0) { sb.Append("-drop " + xs.FrameDropRatio + " "); } // -start missing if (!xs.CustomEncoderOptions.Contains("-threads ") && xs.NbThreads > 0) { sb.Append("-threads " + xs.NbThreads + " "); } // -slices missing // -progress missing if (!xs.CustomEncoderOptions.Contains("-par ") && d.HasValue) // custom PAR mode { Sar s = d.Value.ToSar(hres, vres); if (s.X == 1 && s.Y == 1) { sb.Append("-par 1 "); } else if (s.X == 12 && s.Y == 11) { sb.Append("-par 2 "); } else if (s.X == 10 && s.Y == 11) { sb.Append("-par 3 "); } else if (s.X == 16 && s.Y == 11) { sb.Append("-par 4 "); } else if (s.X == 40 && s.Y == 33) { sb.Append("-par 5 "); } else { sb.Append("-par " + s.X + ":" + s.Y + " "); } } #endregion if (!String.IsNullOrEmpty(xs.CustomEncoderOptions.Trim())) // add custom encoder options { sb.Append(xs.CustomEncoderOptions.Trim()); } return(sb.ToString()); }