From b5327f157414adfdf0eab0e84b1be0ca8497f7c3 Mon Sep 17 00:00:00 2001 From: Mercurio <47455213+NotLugozzi@users.noreply.github.com> Date: Wed, 1 Jan 2025 16:46:35 +0100 Subject: [PATCH] Revert ffmpeg clip combination, fix application audio recording call for charts with spaces and special characters in them --- 2dxAutoClip/iidxAutoClip.cs | 82 ++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/2dxAutoClip/iidxAutoClip.cs b/2dxAutoClip/iidxAutoClip.cs index 7126877..e2fcfa1 100644 --- a/2dxAutoClip/iidxAutoClip.cs +++ b/2dxAutoClip/iidxAutoClip.cs @@ -206,11 +206,11 @@ class Program try { await clientWebSocket.ConnectAsync(tickerUri, CancellationToken.None); - Console.WriteLine("Connected to TickerHook WebSocket."); + Console.WriteLine("[TickerHook] Connected to WebSocket."); } 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; } @@ -224,13 +224,13 @@ class Program } catch (Exception ex) { - Console.WriteLine($"Error receiving message: {ex.Message}"); + Console.WriteLine($"[TickerHook] [ERROR] Unable to receive message: {ex.Message}"); reconnecting = true; break; } 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")) { @@ -301,11 +301,11 @@ class Program _waveSource.Dispose(); }; _waveSource.StartRecording(); - Console.WriteLine("WASAPI Audio recording started."); + Console.WriteLine("[WASAPI] Audio recording started."); } 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"); _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); - if (procid == -1) - { - throw new InvalidOperationException("Target process is not running."); - } - var args = $"{procid} includetree {_audioFilePath}"; + var args = $"{procid} includetree \"{_audioFilePath}\""; _recorderprocess = new Process { StartInfo = new ProcessStartInfo @@ -338,19 +327,36 @@ class Program Arguments = args, UseShellExecute = false, RedirectStandardError = true, + RedirectStandardOutput = 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.BeginOutputReadLine(); + _recorderprocess.BeginErrorReadLine(); } 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) { var date = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); @@ -371,7 +377,7 @@ class Program }; _ffmpegProcess.Start(); - Console.WriteLine("FFmpeg recording started."); + Console.WriteLine("[FFmpeg] recording started."); } private static string GetGraphicsCard() @@ -390,18 +396,18 @@ class Program 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"); + Console.WriteLine("[DxDiagHelper] Using cached dxdiag_output.txt."); + 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); } 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 { - Console.WriteLine("dxdiag_output.txt does not exist, generating..."); + Console.WriteLine("[DxDiagHelper] dxdiag_output.txt does not exist, generating..."); } return RunDxDiag(dxDiagFilePath); } @@ -419,7 +425,7 @@ class Program 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.WaitForExit(); @@ -442,29 +448,29 @@ class Program private static string GetHardwareEncoder() { 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"; if (graphicsCard.Contains("NVIDIA")) { 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")) { 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")) { encoder = "-c:v h264_qsv"; - Console.WriteLine("Using Intel hardware encoding (h264_qsv)."); + Console.WriteLine("[DxDiagHelper] Using Intel hardware encoding (h264_qsv)."); } else { - 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"); + Console.WriteLine("[DxDiagHelper] [WARN] No recognized hardware encoder found, using CPU (libx264)."); + 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; @@ -508,7 +514,7 @@ class Program private static void StopAudioRecording() { _waveSource?.StopRecording(); - Console.WriteLine("WASAPI Audio recording stopped."); + Console.WriteLine("[WASAPI] Audio recording stopped."); } private static void StopFfmpegRecording() { @@ -517,14 +523,14 @@ class Program _ffmpegProcess.Kill(); _ffmpegProcess.WaitForExit(); _ffmpegProcess = null!; - Console.WriteLine("FFmpeg recording stopped."); + Console.WriteLine("[FFmpeg] recording stopped."); } } 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 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 { @@ -539,7 +545,7 @@ class Program using var process = Process.Start(processInfo); if (process == null) { - Console.WriteLine("FFmpeg failed to start."); + Console.WriteLine("[FFmpeg] [FATAL] Unable to start."); return; } @@ -550,8 +556,8 @@ class Program Console.WriteLine("FFmpeg Error: " + error); Console.WriteLine(File.Exists(combinedOutputFilePath) - ? "Audio and video have been successfully combined." - : "Failed to combine audio and video. Check the logs for errors."); + ? "[FFmpeg] Audio and video have been successfully combined." + : "[FFmpeg] [FATAL] Failed to combine audio and video. Check the logs for errors."); File.Delete(videoFilePath); File.Delete(audioFilePath); }