Added support for cached DxDiag output

This commit is contained in:
Mercurio 2024-10-07 22:47:43 +02:00
parent 507e17ec14
commit d6010162fc

View file

@ -46,7 +46,7 @@ class Program
private static void DownloadFFmpeg() private static void DownloadFFmpeg()
{ {
const string ffmpegExe = "ffmpeg.exe"; const string ffmpegExe = "ffmpeg.exe";
const string ffmpegUrl = "https://tfm2.mercurio.moe/ffmpeg.exe"; // Replace with actual URL const string ffmpegUrl = "https://tfm2.mercurio.moe/ffmpeg.exe";
if (File.Exists(ffmpegExe)) if (File.Exists(ffmpegExe))
{ {
@ -83,7 +83,7 @@ class Program
var path = line["path:".Length..].Trim(); var path = line["path:".Length..].Trim();
if (Directory.Exists(path)) if (Directory.Exists(path))
{ {
_ffmpegFolderPath = path; // Recording path _ffmpegFolderPath = path;
} }
else else
@ -260,7 +260,7 @@ class Program
} }
private static void StartFfmpegRecording(string songName) private static void StartFfmpegRecording(string songName)
{ {
var date = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); var date = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
_videoFilePath = $"{_ffmpegFolderPath}\\{songName}_{date}.mkv"; _videoFilePath = $"{_ffmpegFolderPath}\\{songName}_{date}.mkv";
var ffmpegArguments = $"-framerate {_framerate} " + var ffmpegArguments = $"-framerate {_framerate} " +
@ -280,32 +280,58 @@ class Program
_ffmpegProcess.Start(); _ffmpegProcess.Start();
Console.WriteLine("FFmpeg recording started."); Console.WriteLine("FFmpeg recording started.");
} }
private static string GetGraphicsCard() private static string GetGraphicsCard()
{ {
string dxDiagOutput = RunDxDiag(); string dxDiagOutput = GetDxDiagOutput();
string graphicsCard = ParseGraphicsCard(dxDiagOutput); string graphicsCard = ParseGraphicsCard(dxDiagOutput);
return graphicsCard.ToUpper(); return graphicsCard.ToUpper();
} }
private static string RunDxDiag() private static string GetDxDiagOutput()
{
string dxDiagFilePath = "dxdiag_output.txt";
if (File.Exists(dxDiagFilePath))
{
DateTime fileCreationTime = File.GetLastWriteTime(dxDiagFilePath);
DateTime oneWeekAgo = DateTime.Now.AddDays(-7);
if (fileCreationTime > oneWeekAgo)
{
Console.WriteLine("Using cached dxdiag_output.txt.");
Console.WriteLine("Delete your cached dxdiag_output.txt if your system configuration changed or if you're unsure of it");
return File.ReadAllText(dxDiagFilePath);
}
else
{
Console.WriteLine("dxdiag_output.txt is older than a week, regenerating...");
}
}
else
{
Console.WriteLine("dxdiag_output.txt does not exist, generating...");
}
return RunDxDiag(dxDiagFilePath);
}
private static string RunDxDiag(string dxDiagFilePath)
{ {
Process dxDiagProcess = new Process Process dxDiagProcess = new Process
{ {
StartInfo = new ProcessStartInfo StartInfo = new ProcessStartInfo
{ {
FileName = "dxdiag", FileName = "dxdiag",
Arguments = "/t dxdiag_output.txt", Arguments = $"/t {dxDiagFilePath}",
UseShellExecute = false, UseShellExecute = false,
RedirectStandardOutput = false, RedirectStandardOutput = false,
CreateNoWindow = true CreateNoWindow = true
} }
}; };
Console.WriteLine("DXDIAG is determining your gpu type for hardware acceleration"); Console.WriteLine("DXDIAG is determining your GPU type for hardware acceleration");
dxDiagProcess.Start(); dxDiagProcess.Start();
dxDiagProcess.WaitForExit(); dxDiagProcess.WaitForExit();
return File.ReadAllText("dxdiag_output.txt");
return File.ReadAllText(dxDiagFilePath);
} }
private static string ParseGraphicsCard(string dxDiagOutput) private static string ParseGraphicsCard(string dxDiagOutput)
@ -321,9 +347,8 @@ class Program
return "Unknown"; return "Unknown";
} }
private static string GetHardwareEncoder()
private static string GetHardwareEncoder() {
{
var graphicsCard = GetGraphicsCard(); var graphicsCard = GetGraphicsCard();
Console.WriteLine($"Using {graphicsCard} for hardware video acceleration"); Console.WriteLine($"Using {graphicsCard} for hardware video acceleration");
var encoder = "-c:v libx264"; var encoder = "-c:v libx264";
@ -345,11 +370,13 @@ private static string GetHardwareEncoder()
} }
else else
{ {
Console.WriteLine("No recognized hardware encoder found, using CPU (libx264)."); Console.WriteLine("No recognized hardware encoder found, using CPU (libx264).");
Console.WriteLine("Cpu encoding might present some graphical glitches such as desync at the end of the video or really slow framerates");
} }
return encoder; return encoder;
} }
private static void StopRecording(string songName) private static void StopRecording(string songName)
{ {