Splash GUI for HW encoder detection

This commit is contained in:
N00MKRAD
2024-10-16 11:09:44 +02:00
parent a5ac086364
commit e0a228ce48
5 changed files with 86 additions and 37 deletions

View File

@@ -493,6 +493,7 @@
<Compile Include="Media\GetFrameCountCached.cs" />
<Compile Include="Media\GetMediaResolutionCached.cs" />
<Compile Include="Media\GetVideoInfo.cs" />
<Compile Include="Media\HwEncCheck.cs" />
<Compile Include="MiscUtils\Benchmarker.cs" />
<Compile Include="MiscUtils\FrameRename.cs" />
<Compile Include="MiscUtils\ModelDownloadFormUtils.cs" />

View File

@@ -16,6 +16,7 @@ using Flowframes.MiscUtils;
using System.Threading.Tasks;
using System.Linq;
using System.Runtime.InteropServices;
using Flowframes.Media;
#pragma warning disable IDE1006
@@ -118,7 +119,7 @@ namespace Flowframes.Forms.Main
{
comboxOutputEncoder.Items.Clear();
Config.Set(Config.Key.PerformedHwEncCheck, false.ToString());
await StartupChecks.DetectHwEncoders();
await HwEncCheck.DetectHwEncoders();
UpdateOutputUi();
}
@@ -179,8 +180,7 @@ namespace Flowframes.Forms.Main
Task.Run(() => Servers.Init());
await Python.CheckCompression();
await StartupChecks.SymlinksCheck();
await StartupChecks.DetectHwEncoders();
await HwEncCheck.DetectHwEncoders();
}
catch (Exception e)
{

View File

@@ -1,16 +1,19 @@
using System.Windows.Forms;
using System.Drawing;
using System.Windows.Forms;
namespace Flowframes.Forms
{
public partial class SplashForm : Form
{
public static SplashForm Inst;
public enum TextSize { Small, Medium, Large }
private static readonly string[] fontPresets = { "Yu Gothic UI, 14pt", "Yu Gothic UI, 18pt", "Yu Gothic UI, 21.75pt" };
public SplashForm(string status = "")
public SplashForm(string status = "", bool topMost = true, TextSize textSize = TextSize.Large)
{
Inst = this;
InitializeComponent();
SetStatus(status);
TopMost = topMost;
statusLabel.Font = (Font)new FontConverter().ConvertFromInvariantString(fontPresets[(int)textSize]);
}
private void SplashForm_Load(object sender, System.EventArgs e)

View File

@@ -0,0 +1,75 @@
using Flowframes.Forms;
using Flowframes.IO;
using Flowframes.MiscUtils;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Enc = Flowframes.Data.Enums.Encoding.Encoder;
namespace Flowframes.Media
{
internal class HwEncCheck
{
public static async Task DetectHwEncoders(bool hideMainForm = true, bool onlyShowAvail = true, int waitMs = 0)
{
if (Config.GetBool(Config.Key.PerformedHwEncCheck))
return;
Logger.Log($"Detecting hardare encoding support...");
SplashForm statusForm = new SplashForm("Checking hardware encoders...", textSize: SplashForm.TextSize.Medium);
statusForm.Show();
var previousMainFormOpacity = Program.mainForm.Opacity;
if (hideMainForm)
{
Program.mainForm.Opacity = 0;
}
try
{
var encoders = new[] { Enc.Nvenc264, Enc.Nvenc265, Enc.NvencAv1, Enc.Qsv264, Enc.Qsv265, Enc.Amf264, Enc.Amf265 };
var encoderNames = encoders.Select(x => OutputUtils.GetEncoderInfoVideo(x).Name);
var compatEncoders = new List<string>();
foreach (string e in encoderNames)
{
bool compat = await FfmpegCommands.IsEncoderCompatible(e);
if (compat)
{
compatEncoders.Add(e);
Logger.Log($"HW Encoder supported: {e}", true);
}
if(!compat && onlyShowAvail)
continue;
statusForm.SetStatus($"Checking hardware encoders...\n{(compat ? "Available" : "Not available")}: {e.Replace("_", " ").Upper()}");
}
var compEncsPretty = compatEncoders.Select(e => e.Replace("_", " ").Upper());
if(waitMs > 0)
{
string availNvidia = string.Join(", ", compEncsPretty.Where(e => e.Contains("NVENC")).Select(e => e.Replace("NVENC", "").Trim())) + "\n";
string availAmd = string.Join(", ", compEncsPretty.Where(e => e.Contains("AMF")).Select(e => e.Replace("AMF", "").Trim())) + "\n";
string availIntel = string.Join(", ", compEncsPretty.Where(e => e.Contains("QSV")).Select(e => e.Replace("QSV", "").Trim())) + "\n";
if (availNvidia.IsEmpty()) availNvidia = "None";
if (availAmd.IsEmpty()) availAmd = "None";
if (availIntel.IsEmpty()) availIntel = "None";
statusForm.SetStatus($"Nvidia NVENC: {availNvidia}AMD AMF: {availAmd}Intel QuickSync: {availIntel}".Trim());
await Task.Delay(waitMs);
}
Logger.Log($"Available hardware encoders: {string.Join(", ", compEncsPretty)}");
Config.Set(Config.Key.SupportedHwEncoders, string.Join(",", compatEncoders));
Config.Set(Config.Key.PerformedHwEncCheck, true.ToString());
}
catch { }
statusForm.Close();
Program.mainForm.Opacity = previousMainFormOpacity;
}
}
}

View File

@@ -1,14 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Flowframes.IO;
using Flowframes.MiscUtils;
using Flowframes.Ui;
using Enc = Flowframes.Data.Enums.Encoding.Encoder;
namespace Flowframes.Os
{
@@ -125,31 +121,5 @@ namespace Flowframes.Os
IoUtils.TryDeleteIfExists(devmodeBatchPath);
}
}
public static async Task DetectHwEncoders ()
{
if (Config.GetBool(Config.Key.PerformedHwEncCheck))
return;
Logger.Log($"Detecting hardare encoding support...");
var encoders = new[] { Enc.Nvenc264, Enc.Nvenc265, Enc.NvencAv1, Enc.Qsv264, Enc.Qsv265, Enc.Amf264, Enc.Amf265 };
var encoderNames = encoders.Select(x => OutputUtils.GetEncoderInfoVideo(x).Name);
var compatEncoders = new List<string>();
foreach(string e in encoderNames)
{
bool compat = await FfmpegCommands.IsEncoderCompatible(e);
if (compat)
{
compatEncoders.Add(e);
Logger.Log($"HW Encoder supported: {e}", true);
}
}
Logger.Log($"Available hardware encoders: {string.Join(", ", compatEncoders.Select(e => e.Replace("_", " ").Upper()))}");
Config.Set(Config.Key.SupportedHwEncoders, string.Join(",", compatEncoders));
Config.Set(Config.Key.PerformedHwEncCheck, true.ToString());
}
}
}