diff options
author | Scott <[email protected]> | 2018-06-29 19:48:26 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2018-06-29 19:48:26 +0100 |
commit | dbf898635dc12608b78c33916137465ce08937bf (patch) | |
tree | 2449891c1f1275e43673b9aa276b8e8905374b55 /win/CS | |
parent | ac390b630498163ff37bea491202c0872bb679ec (diff) |
Add NVEnc encoder. (Round 3) (#1437)
Adding the Nvidia NVEnc H.264 and H.265 encoders.
Based on Initial work by sgothel
--enable-nvenc is the new compile time configure option to enable for builds.
Diffstat (limited to 'win/CS')
5 files changed, 96 insertions, 7 deletions
diff --git a/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs b/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs index 65b81c509..8e36dc6c6 100644 --- a/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs +++ b/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs @@ -415,6 +415,12 @@ namespace HandBrake.Interop.Interop.HbLib [DllImport("hb", EntryPoint = "hb_vce_h265_available", CallingConvention = CallingConvention.Cdecl)] public static extern int hb_vce_h265_available(); + [DllImport("hb", EntryPoint = "hb_nvenc_h264_available", CallingConvention = CallingConvention.Cdecl)] + public static extern int hb_nvenc_h264_available(); + + [DllImport("hb", EntryPoint = "hb_nvenc_h265_available", CallingConvention = CallingConvention.Cdecl)] + public static extern int hb_nvenc_h265_available(); + // hb_image_t* hb_get_preview2(hb_handle_t* h, int title_idx, int picture, hb_geometry_settings_t* geo, int deinterlace); [DllImport("hb", EntryPoint = "hb_get_preview2", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr hb_get_preview2(IntPtr hbHandle, int title_idx, int preview_idx, ref hb_geometry_settings_s geo, int deinterlace); diff --git a/win/CS/HandBrake.Interop/Interop/Model/Encoding/VideoEncoder.cs b/win/CS/HandBrake.Interop/Interop/Model/Encoding/VideoEncoder.cs index a5aded796..e8a2ed485 100644 --- a/win/CS/HandBrake.Interop/Interop/Model/Encoding/VideoEncoder.cs +++ b/win/CS/HandBrake.Interop/Interop/Model/Encoding/VideoEncoder.cs @@ -30,8 +30,12 @@ namespace HandBrake.Interop.Interop.Model.Encoding [DisplayName("H.264 (AMD VCE)")] [ShortName("vce_h264")] - VceH264, + VceH264, + [DisplayName("H.264 (Nvidia NVEnc)")] + [ShortName("nvenc_h264")] + NvencH264, + [DisplayName("MPEG-4")] [ShortName("mpeg4")] FFMpeg, @@ -68,6 +72,10 @@ namespace HandBrake.Interop.Interop.Model.Encoding [ShortName("vce_h265")] VceH265, + [DisplayName("H.265 (Nvidia NVEnc)")] + [ShortName("nvenc_h265")] + NvencH265, + [DisplayName("VP8")] [ShortName("VP8")] VP8, diff --git a/win/CS/HandBrake.Interop/Utilities/SystemInfo.cs b/win/CS/HandBrake.Interop/Utilities/SystemInfo.cs index a364c50ac..454132b53 100644 --- a/win/CS/HandBrake.Interop/Utilities/SystemInfo.cs +++ b/win/CS/HandBrake.Interop/Utilities/SystemInfo.cs @@ -18,6 +18,9 @@ namespace HandBrake.Interop.Utilities /// </summary> public class SystemInfo { + private static bool? isNvencH264Available; // Local cache to prevent log spam. + private static bool? isNvencH265Available; + /// <summary> /// Gets a value indicating whether is qsv available. /// </summary> @@ -122,5 +125,52 @@ namespace HandBrake.Interop.Utilities } } } + + public static bool IsNVEncH264Available + { + get + { + try + { + if (isNvencH264Available == null) + { + isNvencH264Available = HBFunctions.hb_nvenc_h264_available() != 0; + } + + return isNvencH264Available.Value; + } + catch (Exception) + { + // Silent failure. Typically this means the dll hasn't been built with --enable-qsv + return false; + } + } + } + + public static bool IsNVEncH265Available + { + get + { + try + { + if (!IsNVEncH264Available) + { + return false; + } + + if (isNvencH265Available == null) + { + isNvencH265Available = HBFunctions.hb_nvenc_h265_available() != 0; + } + + return isNvencH265Available.Value; + } + catch (Exception) + { + // Silent failure. Typically this means the dll hasn't been built with --enable-qsv + return false; + } + } + } } } diff --git a/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs b/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs index 42ccf1c10..40131ddb3 100644 --- a/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs @@ -101,6 +101,16 @@ namespace HandBrakeWPF.Converters.Video encoders.Remove(VideoEncoder.VceH265);
}
+ if (!SystemInfo.IsNVEncH264Available)
+ {
+ encoders.Remove(VideoEncoder.NvencH264);
+ }
+
+ if (!SystemInfo.IsNVEncH265Available)
+ {
+ encoders.Remove(VideoEncoder.NvencH265);
+ }
+
return EnumHelper<VideoEncoder>.GetEnumDisplayValuesSubset(encoders);
}
diff --git a/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs index 4bd5b777d..74ac53a85 100644 --- a/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/VideoViewModel.cs @@ -349,6 +349,8 @@ namespace HandBrakeWPF.ViewModels case VideoEncoder.QuickSyncH265:
case VideoEncoder.VceH264:
case VideoEncoder.VceH265:
+ case VideoEncoder.NvencH264:
+ case VideoEncoder.NvencH265:
rfValue = 51.0 - value;
rfValue = Math.Round(rfValue, 0);
this.Task.Quality = rfValue;
@@ -977,7 +979,8 @@ namespace HandBrakeWPF.ViewModels if (preset.Task.VideoEncoder == VideoEncoder.X264 || preset.Task.VideoEncoder == VideoEncoder.X264_10
|| preset.Task.VideoEncoder == VideoEncoder.X265 || preset.Task.VideoEncoder == VideoEncoder.X265_10 || preset.Task.VideoEncoder == VideoEncoder.X265_12
|| preset.Task.VideoEncoder == VideoEncoder.QuickSync || preset.Task.VideoEncoder == VideoEncoder.QuickSyncH265 || preset.Task.VideoEncoder == VideoEncoder.QuickSyncH26510b
- || preset.Task.VideoEncoder == VideoEncoder.VceH264 || preset.Task.VideoEncoder == VideoEncoder.VceH265)
+ || preset.Task.VideoEncoder == VideoEncoder.VceH264 || preset.Task.VideoEncoder == VideoEncoder.VceH265
+ || preset.Task.VideoEncoder == VideoEncoder.NvencH264 || preset.Task.VideoEncoder == VideoEncoder.NvencH265)
{
this.VideoLevel = preset.Task.VideoLevel != null ? preset.Task.VideoLevel.Clone() : this.VideoLevels.FirstOrDefault();
this.VideoProfile = preset.Task.VideoProfile != null ? preset.Task.VideoProfile.Clone() : this.VideoProfiles.FirstOrDefault();
@@ -1090,7 +1093,8 @@ namespace HandBrakeWPF.ViewModels || this.Task.VideoEncoder == VideoEncoder.X265 || this.Task.VideoEncoder == VideoEncoder.X265_10
|| 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.VceH264 || this.Task.VideoEncoder == VideoEncoder.VceH265
+ || this.Task.VideoEncoder == VideoEncoder.NvencH264 || this.Task.VideoEncoder == VideoEncoder.NvencH265)
{
if (!Equals(preset.Task.VideoPreset, this.Task.VideoPreset))
{
@@ -1183,6 +1187,8 @@ namespace HandBrakeWPF.ViewModels case VideoEncoder.QuickSyncH265:
case VideoEncoder.VceH264:
case VideoEncoder.VceH265:
+ case VideoEncoder.NvencH264:
+ case VideoEncoder.NvencH265:
this.QualityMin = 0;
this.QualityMax = 51;
break;
@@ -1317,9 +1323,12 @@ namespace HandBrakeWPF.ViewModels case VideoEncoder.QuickSyncH26510b:
case VideoEncoder.VceH264:
case VideoEncoder.VceH265:
+ case VideoEncoder.NvencH264:
+ case VideoEncoder.NvencH265:
if (this.SelectedVideoEncoder == VideoEncoder.QuickSync || this.SelectedVideoEncoder == VideoEncoder.QuickSyncH265 || this.SelectedVideoEncoder == VideoEncoder.QuickSyncH26510b
- || this.SelectedVideoEncoder == VideoEncoder.VceH264 || this.SelectedVideoEncoder == VideoEncoder.VceH265)
+ || this.SelectedVideoEncoder == VideoEncoder.VceH264 || this.SelectedVideoEncoder == VideoEncoder.VceH265
+ || this.SelectedVideoEncoder == VideoEncoder.NvencH264 || this.SelectedVideoEncoder == VideoEncoder.NvencH265)
{
cqStep = 1;
}
@@ -1441,12 +1450,15 @@ namespace HandBrakeWPF.ViewModels // Update control display
this.UseAdvancedTab = selectedEncoder != VideoEncoder.QuickSync && selectedEncoder != VideoEncoder.QuickSyncH265 && selectedEncoder != VideoEncoder.QuickSyncH26510b
- && selectedEncoder != VideoEncoder.VceH264 && selectedEncoder != VideoEncoder.VceH265 && this.UseAdvancedTab;
+ && selectedEncoder != VideoEncoder.VceH264 && selectedEncoder != VideoEncoder.VceH265
+ && selectedEncoder != VideoEncoder.NvencH264 && selectedEncoder != VideoEncoder.NvencH265
+ && this.UseAdvancedTab;
this.DisplayOptimiseOptions = this.SelectedVideoEncoder == VideoEncoder.X264 || this.SelectedVideoEncoder == VideoEncoder.X264_10 ||
this.SelectedVideoEncoder == VideoEncoder.X265 || this.SelectedVideoEncoder == VideoEncoder.X265_10 || this.SelectedVideoEncoder == VideoEncoder.X265_12 ||
this.SelectedVideoEncoder == VideoEncoder.QuickSync || this.SelectedVideoEncoder == VideoEncoder.QuickSyncH265 || this.SelectedVideoEncoder == VideoEncoder.QuickSyncH26510b ||
this.SelectedVideoEncoder == VideoEncoder.VceH264 || this.SelectedVideoEncoder == VideoEncoder.VceH265 ||
+ this.SelectedVideoEncoder == VideoEncoder.NvencH264 || this.SelectedVideoEncoder == VideoEncoder.NvencH265 ||
this.SelectedVideoEncoder == VideoEncoder.VP8 || this.SelectedVideoEncoder == VideoEncoder.VP9;
this.DisplayNonQSVControls = this.SelectedVideoEncoder != VideoEncoder.QuickSync && this.SelectedVideoEncoder != VideoEncoder.QuickSyncH265 && this.SelectedVideoEncoder != VideoEncoder.QuickSyncH26510b;
@@ -1459,7 +1471,8 @@ namespace HandBrakeWPF.ViewModels this.DisplayLevelControl = this.SelectedVideoEncoder == VideoEncoder.X264 || this.SelectedVideoEncoder == VideoEncoder.X264_10 ||
this.SelectedVideoEncoder == VideoEncoder.QuickSync || this.SelectedVideoEncoder == VideoEncoder.QuickSyncH265 || this.SelectedVideoEncoder == VideoEncoder.QuickSyncH26510b ||
- this.SelectedVideoEncoder == VideoEncoder.VceH264 || this.SelectedVideoEncoder == VideoEncoder.VceH265;
+ this.SelectedVideoEncoder == VideoEncoder.VceH264 || this.SelectedVideoEncoder == VideoEncoder.VceH265 ||
+ this.SelectedVideoEncoder == VideoEncoder.NvencH264 || this.SelectedVideoEncoder == VideoEncoder.NvencH265;
this.DisplayProfileControl = this.SelectedVideoEncoder == VideoEncoder.X264
|| this.SelectedVideoEncoder == VideoEncoder.X264_10
@@ -1470,7 +1483,9 @@ namespace HandBrakeWPF.ViewModels || this.SelectedVideoEncoder == VideoEncoder.QuickSyncH265
|| this.SelectedVideoEncoder == VideoEncoder.QuickSyncH26510b
|| this.SelectedVideoEncoder == VideoEncoder.VceH264
- || this.SelectedVideoEncoder == VideoEncoder.VceH265;
+ || this.SelectedVideoEncoder == VideoEncoder.VceH265
+ || this.SelectedVideoEncoder == VideoEncoder.NvencH264
+ || this.SelectedVideoEncoder == VideoEncoder.NvencH265;
// Refresh Display
this.NotifyOfPropertyChange(() => this.Rfqp);
|