Beispiel #1
0
 private static IJobProcessor init(MainForm mf, Job j)
 {
     if (j is VideoJob && (j as VideoJob).Settings is x265Settings)
     {
         x265Settings xs = (x265Settings)((j as VideoJob).Settings);
         return(new x265Encoder(mf.Settings.X265.Path));
     }
     return(null);
 }
Beispiel #2
0
        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());
        }
Beispiel #3
0
        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());
        }
Beispiel #4
0
 /// <summary>
 ///  Handles assessment of whether the encoding options vary between two x265Settings instances
 /// The following are excluded from the comparison:
 /// BitrateQuantizer
 /// CreditsQuantizer
 /// Logfile
 /// NbThreads
 /// SARX
 /// SARY
 /// Zones
 /// </summary>
 /// <param name="otherSettings"></param>
 /// <returns>true if the settings differ</returns>
 public bool IsAltered(x265Settings otherSettings)
 {
     if (
         this.NewAdaptiveBFrames != otherSettings.NewAdaptiveBFrames ||
         this.AdaptiveDCT != otherSettings.AdaptiveDCT ||
         this.AlphaDeblock != otherSettings.AlphaDeblock ||
         this.NoFastPSkip != otherSettings.NoFastPSkip ||
         this.B8x8mv != otherSettings.B8x8mv ||
         this.BetaDeblock != otherSettings.BetaDeblock ||
         this.BframeBias != otherSettings.BframeBias ||
         this.BframePredictionMode != otherSettings.BframePredictionMode ||
         this.x265BFramePyramid != otherSettings.x265BFramePyramid ||
         this.x265GOPCalculation != otherSettings.x265GOPCalculation ||
         this.BitrateVariance != otherSettings.BitrateVariance ||
         this.PsyRDO != otherSettings.PsyRDO ||
         this.PsyTrellis != otherSettings.PsyTrellis ||
         this.Cabac != otherSettings.Cabac ||
         this.ChromaME != otherSettings.ChromaME ||
         this.ChromaQPOffset != otherSettings.ChromaQPOffset ||
         this.CustomEncoderOptions != otherSettings.CustomEncoderOptions ||
         this.Deblock != otherSettings.Deblock ||
         this.EncodingMode != otherSettings.EncodingMode ||
         this.I4x4mv != otherSettings.I4x4mv ||
         this.I8x8mv != otherSettings.I8x8mv ||
         this.IPFactor != otherSettings.IPFactor ||
         this.KeyframeInterval != otherSettings.KeyframeInterval ||
         this.AVCLevel != otherSettings.AVCLevel ||
         this.MaxQuantDelta != otherSettings.MaxQuantDelta ||
         this.MaxQuantizer != otherSettings.MaxQuantizer ||
         this.MERange != otherSettings.MERange ||
         this.METype != otherSettings.METype ||
         this.MinGOPSize != otherSettings.MinGOPSize ||
         this.MinQuantizer != otherSettings.MinQuantizer ||
         this.NoMixedRefs != otherSettings.NoMixedRefs ||
         this.NbBframes != otherSettings.NbBframes ||
         this.NbRefFrames != otherSettings.NbRefFrames ||
         this.noiseReduction != otherSettings.noiseReduction ||
         this.P4x4mv != otherSettings.P4x4mv ||
         this.P8x8mv != otherSettings.P8x8mv ||
         this.PBFactor != otherSettings.PBFactor ||
         this.Profile != otherSettings.Profile ||
         this.QPel != otherSettings.QPel ||
         this.QuantCompression != otherSettings.QuantCompression ||
         this.QuantizerMatrix != otherSettings.QuantizerMatrix ||
         this.QuantizerMatrixType != otherSettings.QuantizerMatrixType ||
         this.SCDSensitivity != otherSettings.SCDSensitivity ||
         this.SubPelRefinement != otherSettings.SubPelRefinement ||
         this.TempComplexityBlur != otherSettings.TempComplexityBlur ||
         this.TempQuanBlurCC != otherSettings.TempQuanBlurCC ||
         this.TempQuantBlur != otherSettings.TempQuantBlur ||
         this.Trellis != otherSettings.Trellis ||
         this.x265SlowFirstpass != otherSettings.x265SlowFirstpass ||
         this.V4MV != otherSettings.V4MV ||
         this.VBVBufferSize != otherSettings.VBVBufferSize ||
         this.VBVInitialBuffer != otherSettings.VBVInitialBuffer ||
         this.VBVMaxBitrate != otherSettings.VBVMaxBitrate ||
         this.WeightedBPrediction != otherSettings.WeightedBPrediction ||
         this.WeightedPPrediction != otherSettings.WeightedPPrediction ||
         this.x265Trellis != otherSettings.x265Trellis ||
         this.AQmode != otherSettings.AQmode ||
         this.AQstrength != otherSettings.AQstrength ||
         this.UseQPFile != otherSettings.UseQPFile ||
         this.QPFile != otherSettings.QPFile ||
         this.FullRange != otherSettings.FullRange ||
         this.Range != otherSettings.Range ||
         this.MacroBlockOptions != otherSettings.MacroBlockOptions ||
         this.x265PresetLevel != otherSettings.x265PresetLevel ||
         this.x265PsyTuning != otherSettings.x265PsyTuning ||
         this.x265AdvancedSettings != otherSettings.x265AdvancedSettings ||
         this.Lookahead != otherSettings.Lookahead ||
         this.NoMBTree != otherSettings.NoMBTree ||
         this.ThreadInput != otherSettings.ThreadInput ||
         this.NoPsy != otherSettings.NoPsy ||
         this.Scenecut != otherSettings.Scenecut ||
         this.SlicesNb != otherSettings.SlicesNb ||
         this.Nalhrd != otherSettings.Nalhrd ||
         this.OpenGop != otherSettings.OpenGop ||
         this.SampleAR != otherSettings.SampleAR ||
         this.ColorMatrix != otherSettings.ColorMatrix ||
         this.Transfer != otherSettings.Transfer ||
         this.ColorPrim != otherSettings.ColorPrim ||
         this.PicStruct != otherSettings.PicStruct ||
         this.FakeInterlaced != otherSettings.FakeInterlaced ||
         this.NonDeterministic != otherSettings.NonDeterministic ||
         this.MaxSliceSyzeBytes != otherSettings.MaxSliceSyzeBytes ||
         this.MaxSliceSyzeMBs != otherSettings.MaxSliceSyzeMBs ||
         this.tuneFastDecode != otherSettings.tuneFastDecode ||
         this.tuneZeroLatency != otherSettings.tuneZeroLatency
         )
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }