public ConvertWithHandbrake(ConversionJobOptions conversionOptions, string tool, VideoInfo videoFile, JobStatus jobStatus, Log jobLog, Scanner commercialScan)
            : base(conversionOptions, tool, videoFile, jobStatus, jobLog, commercialScan)
        {
            // Check if we have hardware encoding support available on the system
            Handbrake hb = new Handbrake(jobLog);

            hardwareEncodingAvailable = hb.QuickSyncEncodingAvailable;

            //Check if the profiles is setup for Hardware encoding, if so don't adjust hardware encoding options
            Ini  ini = new Ini(GlobalDefs.ProfileFile);
            bool profileHardwareEncoding = ini.ReadBoolean(conversionOptions.profile, tool + "-UsingHardwareEncoding", false);

            _jobLog.WriteEntry(this, "Handbrake profile optimized for hardware encoding, disable auto hardware optimization (" + tool + "-UsingHardwareEncoding) : " + profileHardwareEncoding.ToString(), Log.LogEntryType.Debug);
            if (_preferHardwareEncoding && profileHardwareEncoding)
            {
                _jobLog.WriteEntry(this, "Hardware enabled handbrake profile, disabling auto hardware encoder adjustments", Log.LogEntryType.Debug);
                _preferHardwareEncoding = false; // Don't change any settings, this profile is already setup for hardware encoding
            }

            // Check if we are using any of the h264 codecs, only then can we use hardware encoder for H264
            if (_preferHardwareEncoding && !h264Encoders.Any((new FFMpegMEncoderParams(_videoParams)).ParameterValue("-e").ToLower().Equals))
            {
                _jobLog.WriteEntry(this, "Cannot find h264 encoder, disabling auto hardware h264 encoder adjustments", Log.LogEntryType.Debug);
                _preferHardwareEncoding = false; // Don't use hardware encoder since this isn't a h264 profile
            }
        }
Ejemplo n.º 2
0
 private static async void PrintStatus(Handbrake hb)
 {
     while (true)
     {
         Console.Clear();
         Console.WriteLine(hb.Status + $" - {_current}/{_total}");
         await Task.Delay(1500);
     }
 }
Ejemplo n.º 3
0
        private static async Task Run(IReadOnlyCollection <string> files, string output)
        {
            var hb = new Handbrake("./HandbrakeCLI.exe");

            _total   = files.Count;
            _current = 0;
            PrintStatus(hb);
            var config = new HandbrakeConfiguration();

            foreach (var file in files)
            {
                await hb.Transcode(config, file, output, overwriteExisting : true);

                _current++;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 ///     Handles a change in PlayerKeyState.
 /// </summary>
 /// <param name="sender">Sender of the event.</param>
 /// <param name="e">Object containing information about the event.</param>
 public void Handle(object sender, KeyStateChangedEventArgs e)
 {
     if (Action != null && _check(e, Keys.Action))
     {
         Action.Handle(sender, e);
     }
     if (Crouch != null && _check(e, Keys.Crouch))
     {
         Crouch.Handle(sender, e);
     }
     if (Fire != null && _check(e, Keys.Fire))
     {
         Fire.Handle(sender, e);
     }
     if (Sprint != null && _check(e, Keys.Sprint))
     {
         Sprint.Handle(sender, e);
     }
     if (SecondaryAttack != null && _check(e, Keys.SecondaryAttack))
     {
         SecondaryAttack.Handle(sender, e);
     }
     if (Jump != null && _check(e, Keys.Jump))
     {
         Jump.Handle(sender, e);
     }
     if (LookRight != null && _check(e, Keys.LookRight))
     {
         LookRight.Handle(sender, e);
     }
     if (Handbrake != null && _check(e, Keys.Handbrake))
     {
         Handbrake.Handle(sender, e);
     }
     if (Aim != null && _check(e, Keys.Aim))
     {
         Aim.Handle(sender, e);
     }
     if (LookLeft != null && _check(e, Keys.LookLeft))
     {
         LookLeft.Handle(sender, e);
     }
     if (Submission != null && _check(e, Keys.Submission))
     {
         Submission.Handle(sender, e);
     }
     if (Walk != null && _check(e, Keys.Walk))
     {
         Walk.Handle(sender, e);
     }
     if (AnalogUp != null && _check(e, Keys.AnalogUp))
     {
         AnalogUp.Handle(sender, e);
     }
     if (AnalogDown != null && _check(e, Keys.AnalogDown))
     {
         AnalogDown.Handle(sender, e);
     }
     if (AnalogLeft != null && _check(e, Keys.AnalogLeft))
     {
         AnalogLeft.Handle(sender, e);
     }
     if (AnalogRight != null && _check(e, Keys.AnalogRight))
     {
         AnalogRight.Handle(sender, e);
     }
     if (Yes != null && _check(e, Keys.Yes))
     {
         Yes.Handle(sender, e);
     }
     if (No != null && _check(e, Keys.No))
     {
         No.Handle(sender, e);
     }
     if (CtrlBack != null && _check(e, Keys.CtrlBack))
     {
         CtrlBack.Handle(sender, e);
     }
 }
Ejemplo n.º 5
0
 public void Awake()
 {
     instance = this;
 }
        protected override bool ConvertWithTool()
        {
            if (_2Pass && !(hardwareEncodingAvailable && (ParameterValue("-e") == "qsv_h264"))) // QuickSync does not support 2 pass encoding yet
            {
                _cmdParams += " -2";
            }
            else if (hardwareEncodingAvailable && (ParameterValue("-e") == "qsv_h264") && _2Pass)
            {
                _jobLog.WriteEntry(this, "QuickSync does not support 2 Pass, using 1 pass.", Log.LogEntryType.Warning);
            }

            // TODO: Update this section based on QuickSync encoder opts updates
            // Handbrake QuickSync has specific encoding opts, enable them if required - https://trac.handbrake.fr/wiki/QuickSyncOptions
            if (hardwareEncodingAvailable && _preferHardwareEncoding && (ParameterValue("-e") == "qsv_h264"))
            {
                // Replace only those that differ from the standard x264 options
                string xValue;

                xValue = ParameterSubValue("-x", "no-cabac");
                if (!String.IsNullOrWhiteSpace(xValue))
                {
                    ParameterSubValueDelete("-x", "no-cabac");
                    ParameterSubValueReplaceOrInsert("-x", "cabac", "=" + (xValue == "0" ? "1" : "0"));
                }

                xValue = ParameterSubValue("-x", "no_cabac");
                if (!String.IsNullOrWhiteSpace(xValue))
                {
                    ParameterSubValueDelete("-x", "no_cabac");
                    ParameterSubValueReplaceOrInsert("-x", "cabac", "=" + (xValue == "0" ? "1" : "0"));
                }

                xValue = ParameterSubValue("-x", "b-pyramid");
                if (!String.IsNullOrWhiteSpace(xValue))
                {
                    ParameterSubValueReplace("-x", "b-pyramid", "=" + (xValue == "none" ? "0" : "1"));
                }

                xValue = ParameterSubValue("-x", "b_pyramid");
                if (!String.IsNullOrWhiteSpace(xValue))
                {
                    ParameterSubValueDelete("-x", "b_pyramid");
                    ParameterSubValueReplaceOrInsert("-x", "b-pyramid", "=" + (xValue == "none" ? "0" : "1"));
                }

                xValue = ParameterSubValue("-x", "rc-lookahead");
                if (!String.IsNullOrWhiteSpace(xValue))
                {
                    ParameterSubValueDelete("-x", "rc-lookahead");
                    ParameterSubValueReplaceOrInsert("-x", "la-depth", "=" + xValue);
                }

                xValue = ParameterSubValue("-x", "rc_lookahead");
                if (!String.IsNullOrWhiteSpace(xValue))
                {
                    ParameterSubValueDelete("-x", "rc_lookahead");
                    ParameterSubValueReplaceOrInsert("-x", "la-depth", "=" + xValue);
                }

                _jobLog.WriteEntry(this, "After adujsting QuickSync encoder opts -> " + _cmdParams, Log.LogEntryType.Debug);
            }

            Handbrake hb = new Handbrake(_cmdParams, _jobStatus, _jobLog);

            _jobStatus.CurrentAction = Localise.GetPhrase("Converting video file");
            hb.Run();
            if (!hb.Success) // something didn't complete or went wrong, don't check for % since sometimes handbrake shows less than 90%
            {
                // TODO: When handbrake hardware encoder is stable we need to remove this fallback check
                // Check if we enabled hardware encoding, possibly could have failed due to hardware encoder (unstable). Don't fallback if the user hardcoded hardware encoding
                if (hardwareEncodingAvailable && _preferHardwareEncoding && (ParameterValue("-e") == "qsv_h264"))
                {
                    _jobLog.WriteEntry(this, "Handbrake conversion failed with hardware encoder, retrying with default x264 encoder", Log.LogEntryType.Warning);

                    if (ParameterValue("--deinterlace") == "qsv") // If we are using hardware deinterlacer change it back
                    {
                        _jobLog.WriteEntry(this, "Using standard deinterlacer instead of qsv", Log.LogEntryType.Debug);
                        ParameterValueReplaceOrInsert("--deinterlace", ""); // don't use hardware deinterlacing, default back
                    }

                    _jobLog.WriteEntry(this, "Using default x264 encoder instead of qsv", Log.LogEntryType.Debug);
                    ParameterValueReplaceOrInsert("-e", "x264"); // default back to x264 encoder

                    if (_2Pass && !_cmdParams.Contains(" -2"))   // Check if we have 2Pass enabled, x264 supports it (hardware encoder does not)
                    {
                        _jobLog.WriteEntry(this, "Enabling 2 pass conversion for x264", Log.LogEntryType.Debug);
                        _cmdParams += " -2";
                    }

                    hb = new Handbrake(_cmdParams, _jobStatus, _jobLog);
                    _jobStatus.CurrentAction = Localise.GetPhrase("Converting video file");
                    hb.Run();
                    if (!hb.Success) // something didn't complete or went wrong, don't check for % since sometimes handbrake shows less than 90%
                    {
                        _jobLog.WriteEntry(this, "Handbrake fallback conversion failed", Log.LogEntryType.Error);
                        _jobStatus.ErrorMsg = "Handbrake fallback conversion failed";
                        return(false);
                    }
                }
                else
                {
                    _jobLog.WriteEntry(this, "Handbrake conversion failed", Log.LogEntryType.Error);
                    _jobStatus.ErrorMsg = "Handbrake conversion failed";
                    return(false);
                }
            }

            return(true);
        }