From 51433528a187ef68b724b5443061263a70446149 Mon Sep 17 00:00:00 2001 From: Evan Jarrett Date: Sat, 3 Aug 2024 11:56:56 -0500 Subject: [PATCH 1/5] Allow QSV to use the renderNodePath instead of defaulting to the first available device --- MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs index 2c3d44bf83..3f3f80f0c6 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs @@ -891,13 +891,13 @@ namespace MediaBrowser.Controller.MediaEncoding renderNodePath); } - private string GetQsvDeviceArgs(string alias) + private string GetQsvDeviceArgs(string renderNodePath, string alias) { var arg = " -init_hw_device qsv=" + (alias ?? QsvAlias); if (OperatingSystem.IsLinux()) { // derive qsv from vaapi device - return GetVaapiDeviceArgs(null, "iHD", "i915", null, VaapiAlias) + arg + "@" + VaapiAlias; + return GetVaapiDeviceArgs(renderNodePath, "iHD", "i915", null, VaapiAlias) + arg + "@" + VaapiAlias; } if (OperatingSystem.IsWindows()) @@ -1061,7 +1061,7 @@ namespace MediaBrowser.Controller.MediaEncoding return string.Empty; } - args.Append(GetQsvDeviceArgs(QsvAlias)); + args.Append(GetQsvDeviceArgs(options.VaapiDevice, QsvAlias)); var filterDevArgs = GetFilterHwDeviceArgs(QsvAlias); // child device used by qsv. if (_mediaEncoder.SupportsHwaccel("vaapi") || _mediaEncoder.SupportsHwaccel("d3d11va")) From 0d8669fbe8a8b9845bcebbb98486adf6f733f016 Mon Sep 17 00:00:00 2001 From: Evan Jarrett Date: Sat, 3 Aug 2024 15:05:13 -0500 Subject: [PATCH 2/5] Add a new EncodingOption for QsvDevice --- MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs | 2 +- MediaBrowser.Model/Configuration/EncodingOptions.cs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs index 3f3f80f0c6..e18a23e18e 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs @@ -1061,7 +1061,7 @@ namespace MediaBrowser.Controller.MediaEncoding return string.Empty; } - args.Append(GetQsvDeviceArgs(options.VaapiDevice, QsvAlias)); + args.Append(GetQsvDeviceArgs(options.QsvDevice, QsvAlias)); var filterDevArgs = GetFilterHwDeviceArgs(QsvAlias); // child device used by qsv. if (_mediaEncoder.SupportsHwaccel("vaapi") || _mediaEncoder.SupportsHwaccel("d3d11va")) diff --git a/MediaBrowser.Model/Configuration/EncodingOptions.cs b/MediaBrowser.Model/Configuration/EncodingOptions.cs index 9a192f584d..2b3f57c33b 100644 --- a/MediaBrowser.Model/Configuration/EncodingOptions.cs +++ b/MediaBrowser.Model/Configuration/EncodingOptions.cs @@ -26,6 +26,7 @@ public class EncodingOptions // This is a DRM device that is almost guaranteed to be there on every intel platform, // plus it's the default one in ffmpeg if you don't specify anything VaapiDevice = "/dev/dri/renderD128"; + QsvDevice = ""; EnableTonemapping = false; EnableVppTonemapping = false; EnableVideoToolboxTonemapping = false; @@ -136,6 +137,11 @@ public class EncodingOptions /// public string VaapiDevice { get; set; } + /// + /// Gets or sets the QSV device. + /// + public string QsvDevice { get; set; } + /// /// Gets or sets a value indicating whether tonemapping is enabled. /// From 8941c059f6dfc6e2e49f64b0da00c71e950bf5cd Mon Sep 17 00:00:00 2001 From: Evan Jarrett Date: Sat, 3 Aug 2024 18:19:36 -0500 Subject: [PATCH 3/5] use string.Empty --- MediaBrowser.Model/Configuration/EncodingOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.Model/Configuration/EncodingOptions.cs b/MediaBrowser.Model/Configuration/EncodingOptions.cs index 2b3f57c33b..4c5213d4e2 100644 --- a/MediaBrowser.Model/Configuration/EncodingOptions.cs +++ b/MediaBrowser.Model/Configuration/EncodingOptions.cs @@ -26,7 +26,7 @@ public class EncodingOptions // This is a DRM device that is almost guaranteed to be there on every intel platform, // plus it's the default one in ffmpeg if you don't specify anything VaapiDevice = "/dev/dri/renderD128"; - QsvDevice = ""; + QsvDevice = string.Empty; EnableTonemapping = false; EnableVppTonemapping = false; EnableVideoToolboxTonemapping = false; From e1f72b1f27b9a315fbe49462b050ac45fc899825 Mon Sep 17 00:00:00 2001 From: Evan Jarrett Date: Fri, 16 Aug 2024 14:48:50 -0700 Subject: [PATCH 4/5] Add ability to specify gpu index on windows --- MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs index e18a23e18e..41199563c6 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs @@ -902,6 +902,12 @@ namespace MediaBrowser.Controller.MediaEncoding if (OperatingSystem.IsWindows()) { + // on Windows, the deviceIndex is an int + if (int.TryParse(renderNodePath, NumberStyles.Any, CultureInfo.InvariantCulture, out int deviceIndex)) + { + return GetD3d11vaDeviceArgs(deviceIndex, string.Empty, D3d11vaAlias) + arg + "@" + D3d11vaAlias; + } + // derive qsv from d3d11va device return GetD3d11vaDeviceArgs(0, "0x8086", D3d11vaAlias) + arg + "@" + D3d11vaAlias; } From 6eec6c9957fcbf10ac80c4b66ceed06ef4fbe0ce Mon Sep 17 00:00:00 2001 From: Evan Jarrett Date: Wed, 21 Aug 2024 09:37:52 -0500 Subject: [PATCH 5/5] fix number parser --- MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs index 41199563c6..7a1067dcc4 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs @@ -903,7 +903,7 @@ namespace MediaBrowser.Controller.MediaEncoding if (OperatingSystem.IsWindows()) { // on Windows, the deviceIndex is an int - if (int.TryParse(renderNodePath, NumberStyles.Any, CultureInfo.InvariantCulture, out int deviceIndex)) + if (int.TryParse(renderNodePath, NumberStyles.Integer, CultureInfo.InvariantCulture, out int deviceIndex)) { return GetD3d11vaDeviceArgs(deviceIndex, string.Empty, D3d11vaAlias) + arg + "@" + D3d11vaAlias; }