Exemplo n.º 1
0
        private bool IsPresetDisabled(Preset preset)
        {
            bool isQsvEnabled   = this.userSettingService.GetUserSetting <bool>(UserSettingConstants.EnableQuickSyncEncoding);
            bool isNvencEnabled = this.userSettingService.GetUserSetting <bool>(UserSettingConstants.EnableNvencEncoder);
            bool isVcnEnabled   = this.userSettingService.GetUserSetting <bool>(UserSettingConstants.EnableVceEncoder);

            HBVideoEncoder foundEncoder = HandBrakeEncoderHelpers.GetVideoEncoder(EnumHelper <VideoEncoder> .GetShortName(preset.Task.VideoEncoder));

            if (foundEncoder == null)
            {
                return(true);
            }

            if (VideoEncoderHelpers.IsQuickSync(preset.Task.VideoEncoder) && !isQsvEnabled)
            {
                return(true);
            }

            if (VideoEncoderHelpers.IsNVEnc(preset.Task.VideoEncoder) && !isNvencEnabled)
            {
                return(true);
            }

            if (VideoEncoderHelpers.IsVCN(preset.Task.VideoEncoder) && !isVcnEnabled)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        public void ReleaseToken(VideoEncoder encoder, Guid?unlockKey)
        {
            if (unlockKey == null)
            {
                return;
            }

            lock (this.lockObj)
            {
                if (this.totalInstances.Contains(unlockKey.Value))
                {
                    this.totalInstances.Remove(unlockKey.Value);
                }

                if (VideoEncoderHelpers.IsQuickSync(encoder))
                {
                    if (this.qsvInstances.Contains(unlockKey.Value))
                    {
                        this.qsvInstances.Remove(unlockKey.Value);
                    }
                }
                else if (VideoEncoderHelpers.IsNVEnc(encoder))
                {
                    if (this.nvencInstances.Contains(unlockKey.Value))
                    {
                        this.nvencInstances.Remove(unlockKey.Value);
                    }
                }
                else if (VideoEncoderHelpers.IsVCN(encoder))
                {
                    if (this.vceInstances.Contains(unlockKey.Value))
                    {
                        this.vceInstances.Remove(unlockKey.Value);
                    }
                }
                else if (VideoEncoderHelpers.IsMediaFoundation(encoder))
                {
                    if (this.mfInstances.Contains(unlockKey.Value))
                    {
                        this.mfInstances.Remove(unlockKey.Value);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public Guid?GetToken(EncodeTask task)
        {
            lock (this.lockObj)
            {
                if (VideoEncoderHelpers.IsQuickSync(task.VideoEncoder))
                {
                    if (this.qsvInstances.Count < this.totalQsvInstances && this.TotalActiveInstances <= this.maxAllowedInstances)
                    {
                        this.AllocateIntelGPU(task);

                        Guid guid = Guid.NewGuid();
                        this.qsvInstances.Add(guid);
                        this.totalInstances.Add(guid);
                        return(guid);
                    }

                    return(Guid.Empty); // Busy
                }
                else if (VideoEncoderHelpers.IsNVEnc(task.VideoEncoder))
                {
                    if (this.nvencInstances.Count < this.totalNvidiaInstances && this.TotalActiveInstances <= this.maxAllowedInstances)
                    {
                        Guid guid = Guid.NewGuid();
                        this.nvencInstances.Add(guid);
                        this.totalInstances.Add(guid);
                        return(guid);
                    }

                    return(Guid.Empty); // Busy
                }
                else if (VideoEncoderHelpers.IsVCN(task.VideoEncoder))
                {
                    if (this.vceInstances.Count < this.totalVceInstances && this.TotalActiveInstances <= this.maxAllowedInstances)
                    {
                        Guid guid = Guid.NewGuid();
                        this.vceInstances.Add(guid);
                        this.totalInstances.Add(guid);
                        return(guid);
                    }

                    return(Guid.Empty); // Busy
                }
                else if (VideoEncoderHelpers.IsMediaFoundation(task.VideoEncoder))
                {
                    if (this.mfInstances.Count < this.totalMfInstances && this.TotalActiveInstances <= this.maxAllowedInstances)
                    {
                        Guid guid = Guid.NewGuid();
                        this.mfInstances.Add(guid);
                        this.totalInstances.Add(guid);
                        return(guid);
                    }

                    return(Guid.Empty); // Busy
                }
                else
                {
                    if (this.TotalActiveInstances <= this.maxAllowedInstances)
                    {
                        Guid guid = Guid.NewGuid();
                        this.totalInstances.Add(guid);
                        return(guid);
                    }
                    else
                    {
                        return(Guid.Empty); // Busy
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets a list of Video encoders OR returns the string name of an encoder depending on the input.
        /// </summary>
        /// <param name="values">
        /// The values.
        /// </param>
        /// <param name="targetType">
        /// The target type.
        /// </param>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        /// <param name="culture">
        /// The culture.
        /// </param>
        /// <returns>
        /// IEnumerable VideoEncoder or String encoder name.
        /// </returns>
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Count() >= 2)
            {
                IUserSettingService userSettingService = values[2] as IUserSettingService;
                bool isQsvEnabled = false, isVceEnabled = false, isNvencEnabled = false;
                if (userSettingService != null)
                {
                    isQsvEnabled   = userSettingService.GetUserSetting <bool>(UserSettingConstants.EnableQuickSyncEncoding);
                    isVceEnabled   = userSettingService.GetUserSetting <bool>(UserSettingConstants.EnableVceEncoder);
                    isNvencEnabled = userSettingService.GetUserSetting <bool>(UserSettingConstants.EnableNvencEncoder);
                }

                List <VideoEncoder> allEncoders = values[0] as List <VideoEncoder>;
                EncodeTask          task = values[1] as EncodeTask;

                if (task == null || allEncoders == null)
                {
                    return(null);
                }

                List <VideoEncoder> returnEncoders = new List <VideoEncoder>(allEncoders);

                foreach (var encoder in allEncoders)
                {
                    HBVideoEncoder foundEncoder = HandBrakeEncoderHelpers.GetVideoEncoder(EnumHelper <VideoEncoder> .GetShortName(encoder));
                    if (foundEncoder == null)
                    {
                        returnEncoders.Remove(encoder);
                        continue;
                    }

                    if (task.OutputFormat == OutputFormat.Mp4 && !foundEncoder.SupportsMP4)
                    {
                        returnEncoders.Remove(encoder);
                    }

                    if (task.OutputFormat == OutputFormat.Mkv && !foundEncoder.SupportsMKV)
                    {
                        returnEncoders.Remove(encoder);
                    }

                    if (task.OutputFormat == OutputFormat.WebM && !foundEncoder.SupportsWebM)
                    {
                        returnEncoders.Remove(encoder);
                    }

                    if (!isQsvEnabled && VideoEncoderHelpers.IsQuickSync(encoder))
                    {
                        returnEncoders.Remove(encoder);
                    }

                    if (!isVceEnabled && VideoEncoderHelpers.IsVCN(encoder))
                    {
                        returnEncoders.Remove(encoder);
                    }

                    if (!isNvencEnabled && VideoEncoderHelpers.IsNVEnc(encoder))
                    {
                        returnEncoders.Remove(encoder);
                    }
                }

                return(EnumHelper <VideoEncoder> .GetEnumDisplayValuesSubset(returnEncoders));
            }

            if (values[0].GetType() == typeof(VideoEncoder))
            {
                return(EnumHelper <VideoEncoder> .GetDisplay((VideoEncoder)values[0]));
            }

            return(null);
        }
Exemplo n.º 5
0
        private Video CreateVideo(EncodeTask job)
        {
            Video video = new Video();

            HBVideoEncoder videoEncoder = HandBrakeEncoderHelpers.VideoEncoders.FirstOrDefault(e => e.ShortName == EnumHelper <VideoEncoder> .GetShortName(job.VideoEncoder));

            Validate.NotNull(videoEncoder, "Video encoder " + job.VideoEncoder + " not recognized.");
            if (videoEncoder != null)
            {
                video.Encoder = videoEncoder.ShortName;
            }

            video.Level   = job.VideoLevel?.ShortName;
            video.Preset  = job.VideoPreset?.ShortName;
            video.Profile = job.VideoProfile?.ShortName;

            if (job.VideoTunes != null && job.VideoTunes.Count > 0)
            {
                foreach (var item in job.VideoTunes)
                {
                    video.Tune += string.IsNullOrEmpty(video.Tune) ? item.ShortName : "," + item.ShortName;
                }
            }

            if (job.VideoEncodeRateType == VideoEncodeRateType.ConstantQuality)
            {
                video.Quality = (decimal?)job.Quality;
            }

            if (job.VideoEncodeRateType == VideoEncodeRateType.AverageBitrate)
            {
                video.Bitrate = job.VideoBitrate;
                video.TwoPass = job.TwoPass;
                video.Turbo   = job.TurboFirstPass;
            }


            bool enableQuickSyncDecoding  = userSettingService.GetUserSetting <bool>(UserSettingConstants.EnableQuickSyncDecoding);
            bool useQSVDecodeForNonQSVEnc = userSettingService.GetUserSetting <bool>(UserSettingConstants.UseQSVDecodeForNonQSVEnc);
            bool enableQsvLowPower        = userSettingService.GetUserSetting <bool>(UserSettingConstants.EnableQuickSyncLowPower);

            video.QSV.Decode = HandBrakeHardwareEncoderHelper.IsQsvAvailable && enableQuickSyncDecoding;

            // The use of the QSV decoder is configurable for non QSV encoders.
            if (video.QSV.Decode && !VideoEncoderHelpers.IsQuickSync(job.VideoEncoder))
            {
                video.QSV.Decode = useQSVDecodeForNonQSVEnc;
            }

            video.Options = job.ExtraAdvancedArguments;

            if (HandBrakeHardwareEncoderHelper.IsQsvAvailable && (HandBrakeHardwareEncoderHelper.QsvHardwareGeneration > 6) && VideoEncoderHelpers.IsQuickSync(job.VideoEncoder))
            {
                if (enableQsvLowPower && !video.Options.Contains("lowpower"))
                {
                    video.Options = string.IsNullOrEmpty(video.Options) ? "lowpower=1" : string.Concat(video.Options, ":lowpower=1");
                }
                else if (!enableQsvLowPower && !video.Options.Contains("lowpower"))
                {
                    video.Options = string.IsNullOrEmpty(video.Options) ? "lowpower=0" : string.Concat(video.Options, ":lowpower=0");
                }
            }

            return(video);
        }