Skip to content

Commit

Permalink
WinGui: Add the Nvidia 10bit HEVC encoder. Fix an issue with the qual…
Browse files Browse the repository at this point in the history
…ity scale when changing encoders in certain instances.
  • Loading branch information
sr55 committed Feb 9, 2022
1 parent 0741a82 commit 405ae91
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace HandBrakeWPF.Converters.Video
using System.Globalization;
using System.Windows.Data;

using HandBrake.Interop.Interop;

using HandBrakeWPF.Utilities;

using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask;
Expand Down Expand Up @@ -47,18 +49,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
EncodeTask task = value as EncodeTask;
if (task != null)
{
string rfqp = task.VideoEncoder == VideoEncoder.X264 || task.VideoEncoder == VideoEncoder.X264_10 || task.VideoEncoder == VideoEncoder.X265
|| task.VideoEncoder == VideoEncoder.X265_10 || task.VideoEncoder == VideoEncoder.X265_12 ? "RF" : "QP";

if (task.VideoEncoder == VideoEncoder.NvencH264 || task.VideoEncoder == VideoEncoder.NvencH265)
{
rfqp = "CQ";
}

if (task.VideoEncoder == VideoEncoder.MFH264 || task.VideoEncoder == VideoEncoder.MFH265)
{
rfqp = "CQ";
}
string rfqp = HandBrakeEncoderHelpers.GetVideoQualityRateControlName(EnumHelper<VideoEncoder>.GetShortName(task.VideoEncoder));

string quality = task.VideoEncodeRateType == VideoEncodeRateType.ConstantQuality ? string.Format("{0} {1}", task.Quality, rfqp) : string.Format("{0} {1}", task.VideoBitrate, " kbps");
string twoPass = null;
Expand Down
4 changes: 4 additions & 0 deletions win/CS/HandBrakeWPF/Model/Video/VideoEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public enum VideoEncoder
[ShortName("nvenc_h265")]
NvencH265,

[DisplayName("H.265 10-bit (Nvidia NVEnc)")]
[ShortName("nvenc_h265_10bit")]
NvencH26510b,

[DisplayName("H.265 (MediaFoundation)")]
[ShortName("mf_h265")]
MFH265,
Expand Down
5 changes: 5 additions & 0 deletions win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,11 @@ private bool IsPresetDisabled(Preset preset)
return true;
}

if (preset.Task.VideoEncoder == VideoEncoder.NvencH26510b && (!HandBrakeHardwareEncoderHelper.IsNVEncH265Available || !isNvencEnabled))
{
return true;
}

if (preset.Task.VideoEncoder == VideoEncoder.MFH264 || preset.Task.VideoEncoder == VideoEncoder.MFH265)
{
if (RuntimeInformation.ProcessArchitecture != Architecture.Arm64)
Expand Down
2 changes: 2 additions & 0 deletions win/CS/HandBrakeWPF/Services/Queue/QueueResourceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public void Init()

case VideoEncoder.NvencH264:
case VideoEncoder.NvencH265:
case VideoEncoder.NvencH26510b:
if (this.nvencInstances.Count < this.totalNvidiaInstances && this.TotalActiveInstances <= this.maxAllowedInstances)
{
Guid guid = Guid.NewGuid();
Expand Down Expand Up @@ -212,6 +213,7 @@ public void ReleaseToken(VideoEncoder encoder, Guid? unlockKey)
break;
case VideoEncoder.NvencH264:
case VideoEncoder.NvencH265:
case VideoEncoder.NvencH26510b:
if (this.nvencInstances.Contains(unlockKey.Value))
{
this.nvencInstances.Remove(unlockKey.Value);
Expand Down
44 changes: 18 additions & 26 deletions win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,27 +240,20 @@ public int RF
case VideoEncoder.X265:
case VideoEncoder.X265_10:
case VideoEncoder.X265_12:
double cqStep = userSettingService.GetUserSetting<double>(UserSettingConstants.X264Step);
double rfValue = 51.0 - (value * cqStep);
rfValue = Math.Round(rfValue, 2);
this.Task.Quality = rfValue;
break;
case VideoEncoder.QuickSync:
case VideoEncoder.QuickSyncH265:
case VideoEncoder.VceH264:
case VideoEncoder.VceH265:
case VideoEncoder.NvencH264:
case VideoEncoder.NvencH265:
case VideoEncoder.NvencH26510b:
case VideoEncoder.MFH264:
case VideoEncoder.MFH265:
rfValue = 51.0 - value;
rfValue = Math.Round(rfValue, 0);
this.Task.Quality = rfValue;
break;
double cqStep = userSettingService.GetUserSetting<double>(UserSettingConstants.X264Step);
this.Task.Quality = Math.Round(51.0 - (value * cqStep), 2);
break;
case VideoEncoder.QuickSyncH26510b:
rfValue = 63.0 - (value - 0);
rfValue = Math.Round(rfValue, 0);
this.Task.Quality = rfValue;
this.Task.Quality = Math.Round(63.0 - (value - 0), 0);
break;
case VideoEncoder.Theora:
Task.Quality = value;
Expand Down Expand Up @@ -790,7 +783,7 @@ public bool MatchesPreset(Preset preset)
|| this.Task.VideoEncoder == VideoEncoder.X265_12 || this.Task.VideoEncoder == VideoEncoder.QuickSync
|| this.Task.VideoEncoder == VideoEncoder.QuickSyncH265 || this.Task.VideoEncoder == VideoEncoder.QuickSyncH26510b
|| this.Task.VideoEncoder == VideoEncoder.VceH264 || this.Task.VideoEncoder == VideoEncoder.VceH265
|| this.Task.VideoEncoder == VideoEncoder.NvencH264 || this.Task.VideoEncoder == VideoEncoder.NvencH265
|| this.Task.VideoEncoder == VideoEncoder.NvencH264 || this.Task.VideoEncoder == VideoEncoder.NvencH265 || this.Task.VideoEncoder == VideoEncoder.NvencH26510b
|| this.Task.VideoEncoder == VideoEncoder.MFH264 || this.Task.VideoEncoder == VideoEncoder.MFH265)
{
if (!Equals(preset.Task.VideoPreset, this.Task.VideoPreset))
Expand Down Expand Up @@ -876,17 +869,6 @@ private void SetQualitySliderBounds()
this.QualityMin = 1;
this.QualityMax = 31;
break;
case VideoEncoder.QuickSync:
case VideoEncoder.QuickSyncH265:
case VideoEncoder.VceH264:
case VideoEncoder.VceH265:
case VideoEncoder.NvencH264:
case VideoEncoder.NvencH265:
case VideoEncoder.MFH264:
case VideoEncoder.MFH265:
this.QualityMin = 0;
this.QualityMax = 51;
break;
case VideoEncoder.QuickSyncH26510b:
this.QualityMin = 0;
this.QualityMax = 63;
Expand All @@ -896,6 +878,15 @@ private void SetQualitySliderBounds()
case VideoEncoder.X265:
case VideoEncoder.X265_10:
case VideoEncoder.X265_12:
case VideoEncoder.QuickSync:
case VideoEncoder.QuickSyncH265:
case VideoEncoder.VceH264:
case VideoEncoder.VceH265:
case VideoEncoder.NvencH264:
case VideoEncoder.NvencH265:
case VideoEncoder.NvencH26510b:
case VideoEncoder.MFH264:
case VideoEncoder.MFH265:
this.QualityMin = 0;
this.QualityMax = (int)(51 / userSettingService.GetUserSetting<double>(UserSettingConstants.X264Step));
break;
Expand Down Expand Up @@ -978,7 +969,7 @@ private void SetRF(double? quality)
{
VideoQualityLimits limits = HandBrakeEncoderHelpers.GetVideoQualityLimits(EnumHelper<VideoEncoder>.GetShortName(this.SelectedVideoEncoder));
double cqStep = 1;
if (limits.Granularity != 1)
if (limits != null && limits.Granularity != 1)
{
cqStep = this.userSettingService.GetUserSetting<double>(UserSettingConstants.X264Step);
}
Expand Down Expand Up @@ -1018,6 +1009,7 @@ private void SetRF(double? quality)
case VideoEncoder.VceH265:
case VideoEncoder.NvencH264:
case VideoEncoder.NvencH265:
case VideoEncoder.NvencH26510b:
case VideoEncoder.MFH264:
case VideoEncoder.MFH265:
double multiplier = 1.0 / cqStep;
Expand Down Expand Up @@ -1177,7 +1169,7 @@ private int GetDefaultEncoderPreset(VideoEncoder selectedEncoder)
int defaultPreset = (int)Math.Round((decimal)(this.VideoPresetMaxValue / 2), 0);

// Override for NVEnc
if (selectedEncoder == VideoEncoder.NvencH264 || selectedEncoder == VideoEncoder.NvencH265)
if (selectedEncoder == VideoEncoder.NvencH264 || selectedEncoder == VideoEncoder.NvencH265 || selectedEncoder == VideoEncoder.NvencH26510b)
{
defaultPreset = this.VideoPresets.IndexOf(this.VideoPresets.FirstOrDefault(s => s.ShortName == "medium"));
}
Expand Down

0 comments on commit 405ae91

Please sign in to comment.