Revert ffmpeg clip combination, fix application audio recording call for charts with spaces and special characters in them

This commit is contained in:
Mercurio 2025-01-01 16:46:35 +01:00
parent 1b8420f1ab
commit b5327f1574

View file

@ -206,11 +206,11 @@ class Program
try try
{ {
await clientWebSocket.ConnectAsync(tickerUri, CancellationToken.None); await clientWebSocket.ConnectAsync(tickerUri, CancellationToken.None);
Console.WriteLine("Connected to TickerHook WebSocket."); Console.WriteLine("[TickerHook] Connected to WebSocket.");
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"Error connecting to TickerHook WebSocket: {ex.Message}"); Console.WriteLine($"[TickerHook] [ERROR] Unable to connect to WebSocket: {ex.Message}");
return false; return false;
} }
@ -224,13 +224,13 @@ class Program
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"Error receiving message: {ex.Message}"); Console.WriteLine($"[TickerHook] [ERROR] Unable to receive message: {ex.Message}");
reconnecting = true; reconnecting = true;
break; break;
} }
var message = Encoding.UTF8.GetString(buffer, 0, result.Count).Trim().ToUpper(); var message = Encoding.UTF8.GetString(buffer, 0, result.Count).Trim().ToUpper();
Console.WriteLine($"Received message: {message}"); Console.WriteLine($"[TickerHook] Received message: {message}");
if (message == lastMessage && !message.Contains("SELECT FROM")) if (message == lastMessage && !message.Contains("SELECT FROM"))
{ {
@ -301,11 +301,11 @@ class Program
_waveSource.Dispose(); _waveSource.Dispose();
}; };
_waveSource.StartRecording(); _waveSource.StartRecording();
Console.WriteLine("WASAPI Audio recording started."); Console.WriteLine("[WASAPI] Audio recording started.");
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"Error starting audio recording: {ex.Message}"); Console.WriteLine($"[WASAPI] [ERROR] Unable to start audio recording:{ex.Message}");
} }
} }
@ -316,20 +316,9 @@ class Program
var date = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); var date = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
_audioFilePath = $"{_ffmpegFolderPath}\\{songName}_{date}.wav"; _audioFilePath = $"{_ffmpegFolderPath}\\{songName}_{date}.wav";
var directory = Path.GetDirectoryName(_audioFilePath);
if (directory == null)
{
throw new InvalidOperationException("Invalid audio file path.");
}
Directory.CreateDirectory(directory);
var procid = GetFirstProcessIdByName(_gameProcessName); var procid = GetFirstProcessIdByName(_gameProcessName);
if (procid == -1)
{
throw new InvalidOperationException("Target process is not running.");
}
var args = $"{procid} includetree {_audioFilePath}"; var args = $"{procid} includetree \"{_audioFilePath}\"";
_recorderprocess = new Process _recorderprocess = new Process
{ {
StartInfo = new ProcessStartInfo StartInfo = new ProcessStartInfo
@ -338,19 +327,36 @@ class Program
Arguments = args, Arguments = args,
UseShellExecute = false, UseShellExecute = false,
RedirectStandardError = true, RedirectStandardError = true,
RedirectStandardOutput = true,
CreateNoWindow = true CreateNoWindow = true
} }
}; };
_recorderprocess.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
Console.WriteLine($"[applb]: {e.Data}");
}
};
_recorderprocess.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
Console.WriteLine($"[applb] [ERROR]: {e.Data}");
}
};
_recorderprocess.Start(); _recorderprocess.Start();
_recorderprocess.BeginOutputReadLine();
_recorderprocess.BeginErrorReadLine();
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"Error starting audio recording: {ex.Message}"); Console.WriteLine($"[applb] [ERROR] Unable to start audio recording: {ex.Message}");
} }
} }
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");
@ -371,7 +377,7 @@ class Program
}; };
_ffmpegProcess.Start(); _ffmpegProcess.Start();
Console.WriteLine("FFmpeg recording started."); Console.WriteLine("[FFmpeg] recording started.");
} }
private static string GetGraphicsCard() private static string GetGraphicsCard()
@ -390,18 +396,18 @@ class Program
DateTime oneWeekAgo = DateTime.Now.AddDays(-7); DateTime oneWeekAgo = DateTime.Now.AddDays(-7);
if (fileCreationTime > oneWeekAgo) if (fileCreationTime > oneWeekAgo)
{ {
Console.WriteLine("Using cached dxdiag_output.txt."); Console.WriteLine("[DxDiagHelper] 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"); Console.WriteLine("[DxDiagHelper] Delete your cached dxdiag_output.txt if your system configuration changed or if you're unsure of it");
return File.ReadAllText(dxDiagFilePath); return File.ReadAllText(dxDiagFilePath);
} }
else else
{ {
Console.WriteLine("dxdiag_output.txt is older than a week, regenerating..."); Console.WriteLine("[DxDiagHelper] dxdiag_output.txt is older than a week, regenerating...");
} }
} }
else else
{ {
Console.WriteLine("dxdiag_output.txt does not exist, generating..."); Console.WriteLine("[DxDiagHelper] dxdiag_output.txt does not exist, generating...");
} }
return RunDxDiag(dxDiagFilePath); return RunDxDiag(dxDiagFilePath);
} }
@ -419,7 +425,7 @@ class Program
CreateNoWindow = true CreateNoWindow = true
} }
}; };
Console.WriteLine("DXDIAG is determining your GPU type for hardware acceleration"); Console.WriteLine("[DxDiagHelper] Gathering GPU information for Hardware Accelerated Video");
dxDiagProcess.Start(); dxDiagProcess.Start();
dxDiagProcess.WaitForExit(); dxDiagProcess.WaitForExit();
@ -442,29 +448,29 @@ class Program
private static string GetHardwareEncoder() private static string GetHardwareEncoder()
{ {
var graphicsCard = GetGraphicsCard(); var graphicsCard = GetGraphicsCard();
Console.WriteLine($"Using {graphicsCard} for hardware video acceleration"); Console.WriteLine($"[DxDiagHelper] Using {graphicsCard} for hardware video acceleration");
var encoder = "-c:v libx264"; var encoder = "-c:v libx264";
if (graphicsCard.Contains("NVIDIA")) if (graphicsCard.Contains("NVIDIA"))
{ {
encoder = "-c:v h264_nvenc"; encoder = "-c:v h264_nvenc";
Console.WriteLine("Using NVIDIA hardware encoding (h264_nvenc)."); Console.WriteLine("[DxDiagHelper] Using NVIDIA hardware encoding (h264_nvenc).");
} }
else if (graphicsCard.Contains("AMD")) else if (graphicsCard.Contains("AMD"))
{ {
encoder = "-c:v h264_amf"; encoder = "-c:v h264_amf";
Console.WriteLine("Using AMD hardware encoding (h264_amf)."); Console.WriteLine("[DxDiagHelper] Using AMD hardware encoding (h264_amf).");
} }
else if (graphicsCard.Contains("INTEL")) else if (graphicsCard.Contains("INTEL"))
{ {
encoder = "-c:v h264_qsv"; encoder = "-c:v h264_qsv";
Console.WriteLine("Using Intel hardware encoding (h264_qsv)."); Console.WriteLine("[DxDiagHelper] Using Intel hardware encoding (h264_qsv).");
} }
else else
{ {
Console.WriteLine("No recognized hardware encoder found, using CPU (libx264)."); Console.WriteLine("[DxDiagHelper] [WARN] 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"); Console.WriteLine("[DxDiagHelper] [WARN] Cpu encoding might present some graphical glitches such as desync at the end of the video or really slow framerates");
} }
return encoder; return encoder;
@ -508,7 +514,7 @@ class Program
private static void StopAudioRecording() private static void StopAudioRecording()
{ {
_waveSource?.StopRecording(); _waveSource?.StopRecording();
Console.WriteLine("WASAPI Audio recording stopped."); Console.WriteLine("[WASAPI] Audio recording stopped.");
} }
private static void StopFfmpegRecording() private static void StopFfmpegRecording()
{ {
@ -517,14 +523,14 @@ class Program
_ffmpegProcess.Kill(); _ffmpegProcess.Kill();
_ffmpegProcess.WaitForExit(); _ffmpegProcess.WaitForExit();
_ffmpegProcess = null!; _ffmpegProcess = null!;
Console.WriteLine("FFmpeg recording stopped."); Console.WriteLine("[FFmpeg] recording stopped.");
} }
} }
private static void CombineAudioAndVideo(string videoFilePath, string audioFilePath, string songName) private static void CombineAudioAndVideo(string videoFilePath, string audioFilePath, string songName)
{ {
var combinedOutputFilePath = $"{_ffmpegFolderPath}\\{songName}_combined_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.mp4"; var combinedOutputFilePath = $"{_ffmpegFolderPath}\\{songName}_combined_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.mp4";
var ffmpegArgs = var ffmpegArgs =
$"-y -i \"{videoFilePath}\" -i \"{audioFilePath}\" {_encoder} -preset fast -crf 23 -r {_framerate} -c:a aac -strict experimental -shortest \"{combinedOutputFilePath}\""; $"-y -i \"{videoFilePath}\" -i \"{audioFilePath}\" -c:v copy -c:a aac -strict experimental -shortest \"{combinedOutputFilePath}\"";
var processInfo = new ProcessStartInfo var processInfo = new ProcessStartInfo
{ {
@ -539,7 +545,7 @@ class Program
using var process = Process.Start(processInfo); using var process = Process.Start(processInfo);
if (process == null) if (process == null)
{ {
Console.WriteLine("FFmpeg failed to start."); Console.WriteLine("[FFmpeg] [FATAL] Unable to start.");
return; return;
} }
@ -550,8 +556,8 @@ class Program
Console.WriteLine("FFmpeg Error: " + error); Console.WriteLine("FFmpeg Error: " + error);
Console.WriteLine(File.Exists(combinedOutputFilePath) Console.WriteLine(File.Exists(combinedOutputFilePath)
? "Audio and video have been successfully combined." ? "[FFmpeg] Audio and video have been successfully combined."
: "Failed to combine audio and video. Check the logs for errors."); : "[FFmpeg] [FATAL] Failed to combine audio and video. Check the logs for errors.");
File.Delete(videoFilePath); File.Delete(videoFilePath);
File.Delete(audioFilePath); File.Delete(audioFilePath);
} }