コード例 #1
0
        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);
            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
            }
        }
コード例 #2
0
        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;
        }