Added support for cached DxDiag output
This commit is contained in:
parent
507e17ec14
commit
d6010162fc
|
@ -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,52 +260,78 @@ 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");
|
|
||||||
_videoFilePath = $"{_ffmpegFolderPath}\\{songName}_{date}.mkv";
|
|
||||||
var ffmpegArguments = $"-framerate {_framerate} " +
|
|
||||||
$"-filter_complex \"ddagrab=framerate={_framerate},hwdownload,format=bgra\" " +
|
|
||||||
$"{_encoder} -crf {_crf} -video_size {_resolution} -draw_mouse 0 -movflags +faststart -y \"{_videoFilePath}\"";
|
|
||||||
_ffmpegProcess = new Process
|
|
||||||
{
|
{
|
||||||
StartInfo = new ProcessStartInfo
|
var date = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
|
||||||
|
_videoFilePath = $"{_ffmpegFolderPath}\\{songName}_{date}.mkv";
|
||||||
|
var ffmpegArguments = $"-framerate {_framerate} " +
|
||||||
|
$"-filter_complex \"ddagrab=framerate={_framerate},hwdownload,format=bgra\" " +
|
||||||
|
$"{_encoder} -crf {_crf} -video_size {_resolution} -draw_mouse 0 -movflags +faststart -y \"{_videoFilePath}\"";
|
||||||
|
_ffmpegProcess = new Process
|
||||||
{
|
{
|
||||||
FileName = "ffmpeg",
|
StartInfo = new ProcessStartInfo
|
||||||
Arguments = ffmpegArguments,
|
{
|
||||||
UseShellExecute = false,
|
FileName = "ffmpeg",
|
||||||
RedirectStandardError = true,
|
Arguments = ffmpegArguments,
|
||||||
CreateNoWindow = true
|
UseShellExecute = false,
|
||||||
}
|
RedirectStandardError = true,
|
||||||
};
|
CreateNoWindow = true
|
||||||
_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,35 +347,36 @@ class Program
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetHardwareEncoder()
|
||||||
|
{
|
||||||
|
var graphicsCard = GetGraphicsCard();
|
||||||
|
Console.WriteLine($"Using {graphicsCard} for hardware video acceleration");
|
||||||
|
var encoder = "-c:v libx264";
|
||||||
|
|
||||||
private static string GetHardwareEncoder()
|
if (graphicsCard.Contains("NVIDIA"))
|
||||||
{
|
{
|
||||||
var graphicsCard = GetGraphicsCard();
|
encoder = "-c:v h264_nvenc";
|
||||||
Console.WriteLine($"Using {graphicsCard} for hardware video acceleration");
|
Console.WriteLine("Using NVIDIA hardware encoding (h264_nvenc).");
|
||||||
var encoder = "-c:v libx264";
|
}
|
||||||
|
else if (graphicsCard.Contains("AMD"))
|
||||||
|
{
|
||||||
|
encoder = "-c:v h264_amf";
|
||||||
|
Console.WriteLine("Using AMD hardware encoding (h264_amf).");
|
||||||
|
}
|
||||||
|
else if (graphicsCard.Contains("INTEL"))
|
||||||
|
{
|
||||||
|
encoder = "-c:v h264_qsv";
|
||||||
|
Console.WriteLine("Using Intel hardware encoding (h264_qsv).");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
if (graphicsCard.Contains("NVIDIA"))
|
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");
|
||||||
encoder = "-c:v h264_nvenc";
|
}
|
||||||
Console.WriteLine("Using NVIDIA hardware encoding (h264_nvenc).");
|
|
||||||
}
|
|
||||||
else if (graphicsCard.Contains("AMD"))
|
|
||||||
{
|
|
||||||
encoder = "-c:v h264_amf";
|
|
||||||
Console.WriteLine("Using AMD hardware encoding (h264_amf).");
|
|
||||||
}
|
|
||||||
else if (graphicsCard.Contains("INTEL"))
|
|
||||||
{
|
|
||||||
encoder = "-c:v h264_qsv";
|
|
||||||
Console.WriteLine("Using Intel hardware encoding (h264_qsv).");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("No recognized hardware encoder found, using CPU (libx264).");
|
|
||||||
}
|
|
||||||
|
|
||||||
return encoder;
|
return encoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void StopRecording(string songName)
|
private static void StopRecording(string songName)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue