Skip to content

Commit 39eb4d4

Browse files
committed
Added support for QSV load balancing.
Added number of QSV cores to Options UI. Implemented QSV hyperencode.
1 parent dab8449 commit 39eb4d4

File tree

15 files changed

+122
-8
lines changed

15 files changed

+122
-8
lines changed

VidCoder/Resources/OptionsRes.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VidCoder/Resources/OptionsRes.resx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,4 +470,9 @@ Polling: Periodically checks the contents of the folders. Uses significant CPU a
470470
<value>Supported codecs: {0}</value>
471471
<comment>Format string for codec lists. {0} is replaced with comma-separated list of codecs.</comment>
472472
</data>
473+
<data name="QsvEncoderCount" xml:space="preserve">
474+
<value>QSV Encoder Cores: {0}</value>
475+
<comment>Indicator for how many QSV cores are available on the system.
476+
{0} is the number of cores, for example "2"</comment>
477+
</data>
473478
</root>

VidCoder/Services/HandBrakeProxy/LocalEncodeProxy.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using VidCoderCommon.Utilities;
1414
using HandBrake.Interop.Interop.Interfaces.EventArgs;
1515
using System.Text.Json;
16+
using Microsoft.AnyContainer;
1617

1718
namespace VidCoder;
1819

@@ -27,6 +28,8 @@ public class LocalEncodeProxy : IEncodeProxy
2728
private ManualResetEventSlim encodeStartEvent;
2829
private ManualResetEventSlim encodeEndEvent;
2930

31+
private QsvLoadBalancingService qsvLoadBalancingService = StaticResolver.Resolve<QsvLoadBalancingService>();
32+
3033
private bool encoding;
3134

3235
public event EventHandler EncodeStarted;
@@ -58,6 +61,7 @@ public Task StartEncodeAsync(
5861
encodeTitle,
5962
EncodingRes.DefaultChapterName,
6063
VideoCodecUtilities.CreateJobConfiguration(),
64+
this.qsvLoadBalancingService.GetQsvGpu(job),
6165
true,
6266
preview ? previewNumber : -1,
6367
previewSeconds,

VidCoder/Services/HandBrakeProxy/RemoteEncodeProxy.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using HandBrake.Interop.Interop.Interfaces.EventArgs;
11+
using Microsoft.AnyContainer;
1112
using PipeMethodCalls;
1213
using VidCoder.Model;
1314
using VidCoder.Resources;
@@ -34,6 +35,8 @@ public class RemoteEncodeProxy : RemoteProxyBase<IHandBrakeEncodeWorker, IHandBr
3435
private SemaphoreSlim encodeStartEvent;
3536
private SemaphoreSlim encodeEndEvent;
3637

38+
private QsvLoadBalancingService qsvLoadBalancingService = StaticResolver.Resolve<QsvLoadBalancingService>();
39+
3740
public async Task StartEncodeAsync(
3841
VCJob job,
3942
IAppLogger logger,
@@ -53,7 +56,8 @@ await this.RunOperationAsync(worker =>
5356
preview ? previewNumber : -1,
5457
previewSeconds,
5558
EncodingRes.DefaultChapterName,
56-
VideoCodecUtilities.CreateJobConfiguration())
59+
VideoCodecUtilities.CreateJobConfiguration(),
60+
qsvLoadBalancingService.GetQsvGpu(job))
5761
);
5862
}
5963

VidCoder/Services/PreviewImageService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ private void ProcessPreviewImageWork(object state)
485485
imageJob.Title,
486486
EncodingRes.DefaultChapterName,
487487
VideoCodecUtilities.CreateJobConfiguration(),
488+
qsvGpu: -1,
488489
isEncode: false);
489490

490491
// Make a HandBrake call to get the image
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using HandBrake.Interop.Interop;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using VidCoderCommon.Model;
8+
9+
namespace VidCoder.Services;
10+
11+
public class QsvLoadBalancingService
12+
{
13+
private List<int> qsvGpus = new List<int>();
14+
private int currentGpuIndex = -1;
15+
16+
public QsvLoadBalancingService()
17+
{
18+
this.qsvGpus = HandBrakeEncoderHelpers.GetQsvAdaptorList();
19+
}
20+
21+
public int GetQsvGpu(VCJob job)
22+
{
23+
if (!job.EncodingProfile.VideoEncoder.StartsWith("qsv_", StringComparison.Ordinal))
24+
{
25+
return -1;
26+
}
27+
28+
if (!Config.UseWorkerProcess)
29+
{
30+
return -1;
31+
}
32+
33+
if (Config.MaxSimultaneousEncodes == 1)
34+
{
35+
return -1;
36+
}
37+
38+
this.currentGpuIndex++;
39+
40+
return this.qsvGpus[this.currentGpuIndex % this.qsvGpus.Count];
41+
}
42+
}

VidCoder/Utilities/Ioc.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public static void SetUp()
6464
container.RegisterSingleton<StatusService>();
6565
container.RegisterSingleton<PreviewUpdateService>();
6666
container.RegisterSingleton<PreviewImageService>();
67+
container.RegisterSingleton<QsvLoadBalancingService>();
6768
container.RegisterSingleton<ClipboardService>();
6869
container.RegisterSingleton<TrayService>();
6970
container.RegisterSingleton<AppLoggerFactory>();

VidCoder/View/OptionsDialog.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@
475475

476476
<StackPanel Orientation="Vertical" Visibility="{Binding IsQuickSyncAvailable, Converter={StaticResource VisibilityConverter}}">
477477
<controls:AvailabilityIndicator />
478-
<TextBlock Text="{Binding QsvEncoders}" />
478+
<TextBlock Margin="0 2 0 0" Text="{Binding QsvEncoders}" />
479+
<TextBlock Margin="0 2 0 0" Text="{Binding QsvEncoderCount}" />
479480

480481
<CheckBox
481482
Margin="0 6 0 0"

VidCoder/ViewModel/OptionsDialogViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ public OptionsDialogViewModel(IUpdater updateService)
183183

184184
this.PlayerChoices = Players.All;
185185

186+
int qsvCount = HandBrakeEncoderHelpers.GetQsvAdaptorList().Count();
187+
this.QsvEncoderCount = string.Format(OptionsRes.QsvEncoderCount, qsvCount);
188+
186189
int tabIndex = Config.OptionsDialogLastTab;
187190
if (tabIndex >= this.Tabs.Count)
188191
{
@@ -722,6 +725,8 @@ private static string GetEncodersByPrefix(List<HBVideoEncoder> encoders, string
722725

723726
public string MFEncoders => GetEncodersByPrefix(HandBrakeEncoderHelpers.VideoEncoders, "mf_");
724727

728+
public string QsvEncoderCount { get; }
729+
725730
public bool EnableQuickSyncDecoding
726731
{
727732
get => Config.EnableQuickSyncDecoding;

VidCoder/ViewModel/QueueTitlesWindowViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ private void OnSelectedTitlesCollectionChanged(object sender, System.Collections
9191
title,
9292
EncodingRes.DefaultChapterName,
9393
VideoCodecUtilities.CreateJobConfiguration(),
94+
qsvGpu: -1,
9495
isEncode: false);
9596

9697
this.PreviewImage = BitmapUtilities.ConvertToBitmapImage(BitmapUtilities.ConvertByteArrayToBitmap(this.main.ScanInstance.GetPreview(jsonEncodeObject, 2)));

0 commit comments

Comments
 (0)