From c7dc884bbee9c87fb4e7eb974d5ee029f4c234e4 Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 23 Aug 2013 13:20:38 +0000 Subject: WinGui: Manually merged the QuickSync UI changes from the qsv branch to trunk git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5741 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Factories/PlistPresetFactory.cs | 3 + .../Model/EncodeTask.cs | 7 + .../Utilities/Converters.cs | 4 + .../Utilities/PlistUtility.cs | 2 +- .../Utilities/QueryGeneratorUtility.cs | 82 +++++++-- .../Utilities/SystemInfo.cs | 31 ++++ .../HandBrakeInterop/HandBrakeInterop.csproj | 1 + .../HandBrakeInterop/Model/Encoding/QsvPreset.cs | 28 +++ .../Model/Encoding/VideoEncoder.cs | 3 + .../HandBrakeWPF/Converters/EnumComboConverter.cs | 8 + .../Converters/InverseBooleanConverter.cs | 8 - .../ViewModels/EncoderOptionsViewModel.cs | 1 + win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs | 201 ++++++++++++++++++++- win/CS/HandBrakeWPF/Views/VideoView.xaml | 75 +++++--- win/CS/HandBrakeWPF/Views/VideoView.xaml.cs | 86 +++++++++ 15 files changed, 482 insertions(+), 58 deletions(-) create mode 100644 win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/QsvPreset.cs diff --git a/win/CS/HandBrake.ApplicationServices/Factories/PlistPresetFactory.cs b/win/CS/HandBrake.ApplicationServices/Factories/PlistPresetFactory.cs index e3daf4154..488f1b9b6 100644 --- a/win/CS/HandBrake.ApplicationServices/Factories/PlistPresetFactory.cs +++ b/win/CS/HandBrake.ApplicationServices/Factories/PlistPresetFactory.cs @@ -238,6 +238,9 @@ namespace HandBrake.ApplicationServices.Factories case "h264Level": preset.Task.H264Level = kvp.Value; break; + case "QsvPreset": + preset.Task.QsvPreset = EnumHelper.GetValue(kvp.Value, true); + break; // Chapter Markers Tab case "ChapterMarkers": diff --git a/win/CS/HandBrake.ApplicationServices/Model/EncodeTask.cs b/win/CS/HandBrake.ApplicationServices/Model/EncodeTask.cs index 9e57ef03a..87ddadd43 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/EncodeTask.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/EncodeTask.cs @@ -46,6 +46,7 @@ namespace HandBrake.ApplicationServices.Model this.ChapterNames = new ObservableCollection(); this.AllowedPassthruOptions = new AllowedPassthru(); this.X264Preset = x264Preset.Medium; + this.QsvPreset = QsvPreset.Quality; this.H264Profile = x264Profile.None; this.X264Tune = x264Tune.None; this.Modulus = 16; @@ -126,6 +127,7 @@ namespace HandBrake.ApplicationServices.Model this.VideoEncodeRateType = task.VideoEncodeRateType; this.Width = task.Width; this.X264Preset = task.X264Preset; + this.QsvPreset = task.QsvPreset; this.H264Profile = task.H264Profile; this.X264Tune = task.X264Tune; this.H264Level = task.H264Level; @@ -417,6 +419,11 @@ namespace HandBrake.ApplicationServices.Model /// public x264Preset X264Preset { get; set; } + /// + /// Gets or sets the qsv preset. + /// + public QsvPreset QsvPreset { get; set; } + /// /// Gets or sets x264Profile. /// diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs b/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs index 66a936d1f..4e48c4f0f 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs @@ -292,6 +292,8 @@ namespace HandBrake.ApplicationServices.Utilities return VideoEncoder.FFMpeg2; case "x264": return VideoEncoder.X264; + case "qsv_h264": + return VideoEncoder.QuickSync; case "theora": return VideoEncoder.Theora; default: @@ -318,6 +320,8 @@ namespace HandBrake.ApplicationServices.Utilities return "mpeg2"; case VideoEncoder.X264: return "x264"; + case VideoEncoder.QuickSync: + return "qsv_h264"; case VideoEncoder.Theora: return "theora"; default: diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs b/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs index a6a91cce7..420717dfa 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs @@ -280,7 +280,7 @@ namespace HandBrake.ApplicationServices.Utilities } AddEncodeElement(xmlWriter, "x264Tune", "string", tune); AddEncodeElement(xmlWriter, "x264UseAdvancedOptions", "integer", parsed.ShowAdvancedTab ? "1" : "0"); - + AddEncodeElement(xmlWriter, "QsvPreset", "string", parsed.QsvPreset.ToString()); int videoQualityType = 0; if (parsed.VideoBitrate != null) videoQualityType = 1; diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs b/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs index 040600207..3c78664c7 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs @@ -427,6 +427,9 @@ namespace HandBrake.ApplicationServices.Utilities case VideoEncoder.X264: query += " -e x264"; break; + case VideoEncoder.QuickSync: + query += " -e qsv_h264"; + break; case VideoEncoder.Theora: query += " -e theora"; break; @@ -575,7 +578,7 @@ namespace HandBrake.ApplicationServices.Utilities firstLoop = false; } else - audioItems += "," + Converters.GetCliAudioEncoder(item); + audioItems += "," + Converters.GetCliAudioEncoder(item); } if (audioItems.Trim() != String.Empty) query += " -E " + audioItems; @@ -724,10 +727,10 @@ namespace HandBrake.ApplicationServices.Utilities { query += string.Format(" --audio-copy-mask {0}", fallbackEncoders); } - } + } else { - query += string.Format(" --audio-copy-mask none"); + query += string.Format(" --audio-copy-mask none"); } query += string.Format(" --audio-fallback {0}", Converters.GetCliAudioEncoder(task.AllowedPassthruOptions.AudioEncoderFallback)); @@ -897,10 +900,11 @@ namespace HandBrake.ApplicationServices.Utilities /// private static string AdvancedQuery(EncodeTask task) { + string query = string.Empty; + + // X264 Only if (task.VideoEncoder == VideoEncoder.X264) { - string query = string.Empty; - if (!task.ShowAdvancedTab) { if (task.X264Preset != x264Preset.Medium) @@ -909,12 +913,6 @@ namespace HandBrake.ApplicationServices.Utilities " --x264-preset={0} ", task.X264Preset.ToString().ToLower().Replace(" ", string.Empty)); } - if (task.H264Profile != x264Profile.None) - { - query += string.Format( - " --x264-profile={0} ", task.H264Profile.ToString().ToLower().Replace(" ", string.Empty)); - } - if (task.X264Tune != x264Tune.None) { string tune = string.Empty; @@ -933,23 +931,69 @@ namespace HandBrake.ApplicationServices.Utilities query += string.Format(" --x264-tune=\"{0}\" ", tune); } - if (task.H264Level != "Auto") - { - query += string.Format(" --h264-level=\"{0}\" ", task.H264Level); - } - if (!string.IsNullOrEmpty(task.ExtraAdvancedArguments)) { query += string.Format(" -x {0}", task.ExtraAdvancedArguments); } + } + } + // Options that apply to both x264 and QuickSync + if (task.VideoEncoder == VideoEncoder.QuickSync || task.VideoEncoder == VideoEncoder.X264) + { + if (task.H264Level != "Auto") + { + query += string.Format(" --h264-level=\"{0}\" ", task.H264Level); } - else + + if (task.H264Profile != x264Profile.None) + { + query += string.Format( + " --h264-profile={0} ", task.H264Profile.ToString().ToLower().Replace(" ", string.Empty)); + } + + if (task.VideoEncoder == VideoEncoder.QuickSync) { - if (!string.IsNullOrEmpty(task.AdvancedEncoderOptions)) + string qsvPreset; + + if (SystemInfo.IsHswOrNewer) { - query += string.Format(" -x {0}", task.AdvancedEncoderOptions); + switch (task.QsvPreset) + { + case QsvPreset.Speed: + qsvPreset = "6"; + break; + case QsvPreset.Balanced: + qsvPreset = "4"; + break; + default: + qsvPreset = "2"; + break; + } } + else + { + switch (task.QsvPreset) + { + case QsvPreset.Speed: + qsvPreset = "4"; + break; + case QsvPreset.Balanced: + qsvPreset = "2"; + break; + default: + qsvPreset = "2"; + break; + } + } + + query += string.IsNullOrEmpty(task.AdvancedEncoderOptions) + ? string.Format(" -x target-usage={0}", qsvPreset) + : string.Format(" -x target-usage={0}:{1}", qsvPreset, task.AdvancedEncoderOptions); + } + else if (!string.IsNullOrEmpty(task.AdvancedEncoderOptions)) // Not a H.264 encode + { + query += string.Format(" -x {0}", task.AdvancedEncoderOptions); } return query; diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/SystemInfo.cs b/win/CS/HandBrake.ApplicationServices/Utilities/SystemInfo.cs index 32328ab47..99ab990ca 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/SystemInfo.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/SystemInfo.cs @@ -9,6 +9,7 @@ namespace HandBrake.ApplicationServices.Utilities { + using System.Text.RegularExpressions; using System.Windows.Forms; using Microsoft.Win32; @@ -56,5 +57,35 @@ namespace HandBrake.ApplicationServices.Utilities { get { return Screen.PrimaryScreen; } } + + /// + /// Gets a value indicating whether is hsw or newer. + /// + public static bool IsHswOrNewer + { + get + { + // TODO replace with a call to libhb + string cpu = GetCpuCount.ToString(); + if (cpu.Contains("Intel")) + { + Match match = Regex.Match(cpu, "([0-9]{4})"); + if (match.Success) + { + string cpuId = match.Groups[0].ToString(); + int cpuNumber; + if (int.TryParse(cpuId, out cpuNumber)) + { + if (cpuNumber > 4000) + { + return true; + } + } + } + } + + return false; + } + } } } \ No newline at end of file diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj index d213ca39a..047a172e6 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj @@ -166,6 +166,7 @@ + diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/QsvPreset.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/QsvPreset.cs new file mode 100644 index 000000000..08147a5d3 --- /dev/null +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/QsvPreset.cs @@ -0,0 +1,28 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The qsv preset. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.Interop.Model.Encoding +{ + using System.ComponentModel.DataAnnotations; + + /// + /// The qsv preset. + /// + public enum QsvPreset + { + [Display(Name = "Best Speed")] + Speed, + + [Display(Name = "Balanced")] + Balanced, + + [Display(Name = "Best Quality")] + Quality, + } +} diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/VideoEncoder.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/VideoEncoder.cs index e05f74419..b355d5038 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/VideoEncoder.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/VideoEncoder.cs @@ -22,6 +22,9 @@ namespace HandBrake.Interop.Model.Encoding [ShortName("x264")] X264 = 0, + [Display(Name = "H.264 (Intel QSV)")] + QuickSync, + [Display(Name = "MPEG-4 (FFmpeg)")] [ShortName("mpeg4")] FFMpeg, diff --git a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs index 6f89bb52f..d65b7f9f1 100644 --- a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs @@ -65,6 +65,10 @@ namespace HandBrakeWPF.Converters { return EnumHelper.GetEnumDisplayValues(typeof(Mixdown)); } + if (targetType == typeof(QsvPreset) || value.GetType() == typeof(QsvPreset)) + { + return EnumHelper.GetDisplay((QsvPreset)value); + } if (value is IEnumerable) { @@ -182,6 +186,10 @@ namespace HandBrakeWPF.Converters { return EnumHelper.GetValue(value.ToString()); } + if (targetType == typeof(QsvPreset) || value.GetType() == typeof(QsvPreset)) + { + return EnumHelper.GetValue(value.ToString()); + } if (targetType == typeof(PresetPictureSettingsMode) || value.GetType() == typeof(PresetPictureSettingsMode)) { diff --git a/win/CS/HandBrakeWPF/Converters/InverseBooleanConverter.cs b/win/CS/HandBrakeWPF/Converters/InverseBooleanConverter.cs index f44e18a3e..8cd29431f 100644 --- a/win/CS/HandBrakeWPF/Converters/InverseBooleanConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/InverseBooleanConverter.cs @@ -19,10 +19,6 @@ namespace HandBrakeWPF.Converters [ValueConversion(typeof(bool), typeof(bool))] public class InverseBooleanConverter : IValueConverter { - #region Implemented Interfaces - - #region IValueConverter - /// /// The convert. /// @@ -73,9 +69,5 @@ namespace HandBrakeWPF.Converters { throw new NotSupportedException(); } - - #endregion - - #endregion } } \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/ViewModels/EncoderOptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/EncoderOptionsViewModel.cs index f1da43828..d7ae4e498 100644 --- a/win/CS/HandBrakeWPF/ViewModels/EncoderOptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/EncoderOptionsViewModel.cs @@ -33,6 +33,7 @@ namespace HandBrakeWPF.ViewModels public EncoderOptionsViewModel() { this.Task = new EncodeTask(); + cachedOptions.Add(VideoEncoder.QuickSync, "async-depth=4"); } /// diff --git a/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs index f37f9c7ea..bc07f57f5 100644 --- a/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs @@ -62,6 +62,16 @@ namespace HandBrakeWPF.ViewModels /// private bool displayX264Options; + /// + /// The display qsv options. + /// + private bool displayQSVOptions; + + /// + /// Backing field used to display / hide the h264 options + /// + private bool displayEncoderOptions; + /// /// The quality max. /// @@ -87,6 +97,11 @@ namespace HandBrakeWPF.ViewModels /// private int x264PresetValue; + /// + /// The qsv preset value. + /// + private int qsvPresetValue; + /// /// The extra arguments. /// @@ -102,6 +117,11 @@ namespace HandBrakeWPF.ViewModels /// private bool useAdvancedTab; + /// + /// The display framerate controls. + /// + private bool displayNonQSVControls; + #endregion #region Constructors and Destructors @@ -126,6 +146,7 @@ namespace HandBrakeWPF.ViewModels this.VideoEncoders = EnumHelper.GetEnumList(); X264Presets = new BindingList(EnumHelper.GetEnumList().ToList()); + QsvPresets = new BindingList(EnumHelper.GetEnumList().ToList()); H264Profiles = EnumHelper.GetEnumList(); X264Tunes = EnumHelper.GetEnumList().Where(t => t != x264Tune.Fastdecode); this.H264Levels = Levels; @@ -149,13 +170,17 @@ namespace HandBrakeWPF.ViewModels { get { - bool showAdvTabSetting = - this.userSettingService.GetUserSetting(UserSettingConstants.ShowAdvancedTab); + bool showAdvTabSetting = this.userSettingService.GetUserSetting(UserSettingConstants.ShowAdvancedTab); if (!showAdvTabSetting) { this.UseAdvancedTab = false; } + if (this.SelectedVideoEncoder == VideoEncoder.QuickSync) + { + return false; + } + return showAdvTabSetting; } } @@ -303,7 +328,7 @@ namespace HandBrakeWPF.ViewModels { get { - return 0.0.Equals(this.DisplayRF); + return 0.0.Equals(this.DisplayRF) && this.SelectedVideoEncoder == VideoEncoder.X264; } } @@ -366,6 +391,7 @@ namespace HandBrakeWPF.ViewModels case VideoEncoder.FFMpeg2: this.Task.Quality = (32 - value); break; + case VideoEncoder.QuickSync: case VideoEncoder.X264: double rfValue = 51.0 - value * cqStep; rfValue = Math.Round(rfValue, 2); @@ -393,6 +419,40 @@ namespace HandBrakeWPF.ViewModels } } + /// + /// Gets or sets a value indicating whether two pass. + /// + public bool TwoPass + { + get + { + return this.Task.TwoPass; + } + + set + { + this.Task.TwoPass = value; + this.NotifyOfPropertyChange(() => this.TwoPass); + } + } + + /// + /// Gets or sets a value indicating whether turbo first pass. + /// + public bool TurboFirstPass + { + get + { + return this.Task.TurboFirstPass; + } + + set + { + this.Task.TurboFirstPass = value; + this.NotifyOfPropertyChange(() => this.TurboFirstPass); + } + } + /// /// Gets the rfqp. /// @@ -480,9 +540,23 @@ namespace HandBrakeWPF.ViewModels // Hide the x264 controls when not needed. this.DisplayX264Options = value == VideoEncoder.X264; + this.DisplayQSVOptions = value == VideoEncoder.QuickSync; + this.DisplayH264Options = value == VideoEncoder.X264 || value == VideoEncoder.QuickSync; + this.UseAdvancedTab = value != VideoEncoder.QuickSync && this.UseAdvancedTab; + this.DisplayNonQSVControls = value != VideoEncoder.QuickSync; this.NotifyOfPropertyChange(() => this.Rfqp); + this.NotifyOfPropertyChange(() => this.ShowAdvancedTab); + this.NotifyOfPropertyChange(() => this.HighQualityLabel); + if (value == VideoEncoder.QuickSync) + { + this.IsConstantFramerate = true; + this.TwoPass = false; + this.TurboFirstPass = false; + this.Task.Framerate = null; + this.NotifyOfPropertyChange(() => SelectedFramerate); + } } } @@ -526,6 +600,23 @@ namespace HandBrakeWPF.ViewModels } } } + + /// + /// Gets or sets a value indicating whether to display H264 + /// + public bool DisplayH264Options + { + get + { + return this.displayEncoderOptions; + } + set + { + this.displayEncoderOptions = value; + this.NotifyOfPropertyChange(() => this.DisplayH264Options); + } + } + /// /// Gets or sets a value indicating whether display x 264 options. @@ -544,6 +635,40 @@ namespace HandBrakeWPF.ViewModels } } + + /// + /// Gets or sets a value indicating whether to display qsv options. + /// + public bool DisplayQSVOptions + { + get + { + return this.displayQSVOptions; + } + set + { + this.displayQSVOptions = value; + this.NotifyOfPropertyChange(() => this.DisplayQSVOptions); + } + } + + /// + /// Gets or sets a value indicating whether display framerate controls. + /// + public bool DisplayNonQSVControls + { + get + { + return this.displayNonQSVControls; + } + + set + { + this.displayNonQSVControls = value; + this.NotifyOfPropertyChange(() => this.DisplayNonQSVControls); + } + } + /// /// Gets or sets the x 264 preset value. /// @@ -585,6 +710,45 @@ namespace HandBrakeWPF.ViewModels } } } + + /// + /// Gets or sets X264Preset. + /// + public QsvPreset QsvPreset + { + get + { + return this.Task.QsvPreset; + } + set + { + if (!object.Equals(this.QsvPreset, value)) + { + this.Task.QsvPreset = value; + this.NotifyOfPropertyChange(() => this.QsvPreset); + } + } + } + + /// + /// Gets or sets the x 264 preset value. + /// + public int QsvPresetValue + { + get + { + return this.qsvPresetValue; + } + set + { + if (!object.Equals(this.QsvPresetValue, value)) + { + this.qsvPresetValue = value; + this.QsvPreset = this.QsvPresets[value]; + this.NotifyOfPropertyChange(() => this.QsvPresetValue); + } + } + } /// /// Gets or sets H264Profile. @@ -676,6 +840,12 @@ namespace HandBrakeWPF.ViewModels /// public BindingList X264Presets { get; set; } + /// + /// Gets or sets QsvPreset. + /// + public BindingList QsvPresets { get; set; } + + /// /// Gets or sets X264Profiles. /// @@ -702,6 +872,17 @@ namespace HandBrakeWPF.ViewModels } } + /// + /// Gets the qsv slider max. + /// + public int QsvSliderMax + { + get + { + return SystemInfo.IsHswOrNewer ? 2 : 1; + } + } + #endregion #region Public Methods @@ -774,6 +955,7 @@ namespace HandBrakeWPF.ViewModels this.RF = 32 - cq; } break; + case VideoEncoder.QuickSync: case VideoEncoder.X264: double multiplier = 1.0 / cqStep; @@ -812,6 +994,10 @@ namespace HandBrakeWPF.ViewModels this.FastDecode = preset.Task.VideoEncoder == VideoEncoder.X264 && preset.Task.FastDecode; this.ExtraArguments = preset.Task.ExtraAdvancedArguments; + this.QsvPresetValue = preset.Task.VideoEncoder == VideoEncoder.QuickSync + ? (int)preset.Task.QsvPreset + : SystemInfo.IsHswOrNewer ? (int)QsvPreset.Quality : (int)QsvPreset.Balanced; + this.UseAdvancedTab = !string.IsNullOrEmpty(preset.Task.AdvancedEncoderOptions) && this.ShowAdvancedTab; } } @@ -843,6 +1029,7 @@ namespace HandBrakeWPF.ViewModels this.NotifyOfPropertyChange(() => this.H264Profile); this.NotifyOfPropertyChange(() => this.FastDecode); this.NotifyOfPropertyChange(() => this.ExtraArguments); + this.NotifyOfPropertyChange(() => this.QsvPreset); } /// @@ -853,7 +1040,14 @@ namespace HandBrakeWPF.ViewModels /// public void SetEncoder(VideoEncoder encoder) { + this.DisplayH264Options = encoder == VideoEncoder.X264 || encoder == VideoEncoder.QuickSync; this.DisplayX264Options = encoder == VideoEncoder.X264; + this.DisplayQSVOptions = encoder == VideoEncoder.QuickSync; + + if (encoder == VideoEncoder.QuickSync) + { + this.UseAdvancedTab = false; + } } /// @@ -909,6 +1103,7 @@ namespace HandBrakeWPF.ViewModels this.QualityMax = 31; break; case VideoEncoder.X264: + case VideoEncoder.QuickSync: this.QualityMin = 0; this.QualityMax = (int)(51 / userSettingService.GetUserSetting(UserSettingConstants.X264Step)); break; diff --git a/win/CS/HandBrakeWPF/Views/VideoView.xaml b/win/CS/HandBrakeWPF/Views/VideoView.xaml index c4bd565c7..fffbfd0b2 100644 --- a/win/CS/HandBrakeWPF/Views/VideoView.xaml +++ b/win/CS/HandBrakeWPF/Views/VideoView.xaml @@ -6,7 +6,8 @@ xmlns:Converters="clr-namespace:HandBrakeWPF.Converters" xmlns:Video="clr-namespace:HandBrakeWPF.Converters.Video" xmlns:Properties="clr-namespace:HandBrakeWPF.Properties" - xmlns:Micro="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro" mc:Ignorable="d" > + xmlns:cal="http://www.caliburnproject.org" + mc:Ignorable="d" > @@ -74,12 +75,18 @@ - - - + + + + + - + @@ -89,7 +96,7 @@ - + @@ -112,22 +119,21 @@ - - + + - + + IsChecked="{Binding TwoPass}" Margin="0,0,10,0" /> + IsChecked="{Binding TurboFirstPass}" /> - + @@ -139,8 +145,7 @@ - + @@ -160,22 +165,36 @@ - - + + - + + ItemsSource="{Binding X264Tunes, Converter={StaticResource enumComboConverter}}" + SelectedItem="{Binding X264Tune, Converter={StaticResource enumComboConverter}}" + Visibility="{Binding DisplayX264Options, Converter={StaticResource boolToVisConverter}}" + ToolTip="{x:Static Properties:Resources.Video_x264Tune}" + Style="{StaticResource LongToolTipHolder}" /> + Visibility="{Binding DisplayX264Options, Converter={StaticResource boolToVisConverter}}" + ToolTip="{x:Static Properties:Resources.Video_x264FastDecode}"/> + + + + + + @@ -194,13 +213,15 @@ ToolTip="{x:Static Properties:Resources.Video_x264Level}"/> - + + Height="30" MaxLines="2" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="3" Margin="5,10,0,0" VerticalAlignment="Center" + ToolTip="{Binding FullOptionsTooltip}" Style="{StaticResource LongToolTipHolder}" + Visibility="{Binding DisplayX264Options, Converter={StaticResource boolToVisConverter}}" > - + diff --git a/win/CS/HandBrakeWPF/Views/VideoView.xaml.cs b/win/CS/HandBrakeWPF/Views/VideoView.xaml.cs index 8a0842a96..a285e490b 100644 --- a/win/CS/HandBrakeWPF/Views/VideoView.xaml.cs +++ b/win/CS/HandBrakeWPF/Views/VideoView.xaml.cs @@ -9,8 +9,19 @@ namespace HandBrakeWPF.Views { + using System.Collections.Generic; + using System.Windows; using System.Windows.Controls; + using Caliburn.Micro; + + using HandBrake.ApplicationServices.Model; + using HandBrake.ApplicationServices.Utilities; + using HandBrake.Interop.Model.Encoding; + + using HandBrakeWPF.ViewModels; + using HandBrakeWPF.ViewModels.Interfaces; + /// /// Interaction logic for VideoView.xaml /// @@ -23,5 +34,80 @@ namespace HandBrakeWPF.Views { InitializeComponent(); } + + + private void qsv_preset_radiobutton(object sender, System.Windows.RoutedEventArgs e) + { + qsv_preset_ValueChanged(sender, null); + } + + private void qsv_preset_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) + { + VideoViewModel mvm = ((VideoViewModel)this.DataContext); + EncodeTask task = mvm.Task; + + string addon = ""; + + if (SystemInfo.IsHswOrNewer) + { + if (task.VideoEncodeRateType == VideoEncodeRateType.ConstantQuality) + { + if (task.QsvPreset == QsvPreset.Balanced || + task.QsvPreset == QsvPreset.Speed) + addon = "num-ref-frame=1"; + } + if (task.VideoEncodeRateType == VideoEncodeRateType.AverageBitrate) + { + if (task.QsvPreset == QsvPreset.Quality) + addon = "lookahead=1:gop-ref-dist=3"; + else + if (task.QsvPreset == QsvPreset.Balanced) + { + addon = "num-ref-frame=1:gop-ref-dist=1"; + } + else + if (task.QsvPreset == QsvPreset.Speed) + addon = "gop-ref-dist=1"; + } + } + + + string full_string = addon + ":"; + + IDictionary newOptions = new Dictionary(); + string[] existingSegments = full_string.Split(':'); + foreach (string existingSegment in existingSegments) + { + string optionName = existingSegment; + string optionValue = string.Empty; + int equalsIndex = existingSegment.IndexOf('='); + if (equalsIndex >= 0) + { + optionName = existingSegment.Substring( + 0, existingSegment.IndexOf("=", System.StringComparison.Ordinal)); + optionValue = existingSegment.Substring(equalsIndex); + } + + if (optionName != string.Empty) + { + if (newOptions.ContainsKey(optionName)) + newOptions.Remove(optionName); + newOptions.Add(optionName, optionValue); + } + } + + full_string = ""; + foreach (KeyValuePair entry in newOptions) + { + full_string += entry.Key; + if (entry.Value != string.Empty) + full_string += entry.Value; + full_string += ":"; + } + full_string = full_string.TrimEnd(':'); + + task.AdvancedEncoderOptions = full_string; + task.NotifyOfPropertyChange(() => task.AdvancedEncoderOptions); + } } } -- cgit v1.2.3